in MiddlemanElectronSampleApp/AppServiceHost/AppServiceUWP/App.xaml.cs [149:186]
private async void ExcelOnAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
{
var messageDeferral = args.GetDeferral();
var request = args.Request;
var m = request.Message;
object command;
m.TryGetValue("Command", out command);
try
{
if (command as string == "Connect")
{
object role;
m.TryGetValue("Role", out role);
if ((role as string) == "DataStreamer")
{
_excelConnection = sender;
Debug.WriteLine($"Connecting Excel: {sender.GetHashCode()}");
}
var response = new ValueSet();
response.Add("Response", "OK");
await request.SendResponseAsync(response);
SendStatusAsync();
}
}
catch (Exception e)
{
Debug.WriteLine($"Exception while sending the response : {e.Message}");
}
finally
{
// Complete the deferral so that the platform knows that we're done responding to the app service call.
// Note for error handling: this must be called even if SendResponseAsync() throws an exception.
messageDeferral.Complete();
}
}