Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions WPFExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public partial class MainWindow : Window

private Finsemble FSBL;

private bool finsembleRequestedClose = false;

private void SpawnComponent_Click(object sender, RoutedEventArgs e)
{
string componentName = ComponentSelect.SelectedValue.ToString();
Expand Down Expand Up @@ -64,6 +66,7 @@ public MainWindow(string[] args)
FSBL.Connect();
}


private void Finsemble_Connected(object sender, EventArgs e)
{
Application.Current.Dispatcher.Invoke(delegate //main thread
Expand Down Expand Up @@ -191,6 +194,39 @@ private void Finsemble_Connected(object sender, EventArgs e)
});
*/

//listen for window close requests from FInsemble so we can differentiate user and system close requests
/*string closeTopic = "WindowService-Event-" + FSBL.windowName + "-close-requested";
FSBL.RouterClient.AddListener(closeTopic, (s, args) =>
{
finsembleRequestedCloseAt = DateTime.UtcNow;
});*/

//wait for the window to come up
FSBL.RouterClient.AddListener("WindowService-Event-" + FSBL.windowName + "-ready", (t, arguments) =>
{
//Register an event listener to pause Finsemble during workspace switch/shutdown/restart events until this listener responds
var guid = DateTime.UtcNow + " " + FSBL.windowName;
FSBL.RouterClient.Query("WindowService-Request-addEventListener", new JObject
{
["windowIdentifier"] = FSBL.WindowClient.windowIdentifier,
["eventName"] = "close-requested",
["guid"] = guid
}, (s, args) => {

});

//When a close-requested event fires, log the timestamp abd then publish on the interrupt channel to let FInsemble know it can continue
string closeTopic = "WindowService-Event-" + FSBL.windowName + "-close-requested";
FSBL.RouterClient.AddListener(closeTopic, (s, args) =>
{
finsembleRequestedClose = true;
FSBL.RouterClient.Publish("Finsemble.Event.Interrupt." + guid, new JObject
{
["delayed"] = false
});
});
});

}

/// <summary>
Expand All @@ -200,13 +236,27 @@ private void Finsemble_Connected(object sender, EventArgs e)
/// <param name="e"></param>
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
/*if (MessageBox.Show("Close Application?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
// Cancel Closing
e.Cancel = true;
return;
}*/
}
//consider yielding here to let the message arrive?
if (finsembleRequestedClose)
{
finsembleRequestedClose = false;
if (MessageBox.Show("Finsemble is requesting that this app close, proceed?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
// Cancel Closing
e.Cancel = true;
return;
}
}
else
{
if (MessageBox.Show("Close Application?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
// Cancel Closing
e.Cancel = true;
return;
}
}
}

private void LinkToGroup_Click(object sender, RoutedEventArgs e)
{
Expand Down