const int sleep_after_completion = 1; // seconds private async Task ConsumeService() { while (true) { Windows.ApplicationModel.AppService.AppServiceConnection newConnection = new Windows.ApplicationModel.AppService.AppServiceConnection(); #if false newConnection.AppServiceName = "com.microsoft.numbercruncher2"; newConnection.PackageFamilyName = "AppServiceProviderBackgroundApp4-uwp_55b230cc6y9ay"; #else newConnection.AppServiceName = "com.microsoft.numbercruncher"; newConnection.PackageFamilyName = "Microsoft.AppServicesProvider.NumberCruncher_9nthh9tntkkay"; #endif var status = await newConnection.OpenAsync(); if (status != Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success) { System.Diagnostics.Debug.WriteLine(string.Format("Error {0}", status)); return; } await Task.Delay(sleep_after_connection *1000); var inputs = new Windows.Foundation.Collections.ValueSet(); int min = 0; int max = 100; Random random = new Random(); int val1 = random.Next(min, max); int val2 = random.Next(min, max); System.Diagnostics.Debug.Write(string.Format("{0} + {1} = ", val1, val2)); inputs.Add("value1", val1); inputs.Add("value2", val2); var response = await newConnection.SendMessageAsync(inputs); if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { var resultText = response.Message["sum"]; System.Diagnostics.Debug.WriteLine(string.Format("{0}", resultText)); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { textBlock.Text = string.Format("[{3}]: {0} + {1} = {2}", val1, val2, resultText, DateTime.Now.ToString("HH:mm:ss")); }); } else { System.Diagnostics.Debug.WriteLine(string.Format("Error {0}", response.Status)); } await Task.Delay(sleep_after_completion * 1000); } }
public async Task <Windows.Foundation.Collections.ValueSet> MakeUWPCommandCall(string commandCall, string serviceName, List <KeyValuePair <string, object> > dataToPass) { using (var connection = new Windows.ApplicationModel.AppService.AppServiceConnection()) { connection.AppServiceName = serviceName; connection.PackageFamilyName = HostPackageFamilyName; var status = await connection.OpenAsync(); if (status != Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success) { throw new NotImplementedException("Failed app service connection"); } else { var request = new Windows.Foundation.Collections.ValueSet(); request.Add("Command", commandCall); if (dataToPass != null && dataToPass.Count > 0) { foreach (var data in dataToPass) { //message.Add(new KeyValuePair<string, object>("AppExtensionDisplayName", AppExtension.AppInfo.DisplayInfo.DisplayName)); request.Add(new KeyValuePair <string, object>(data.Key, data.Value)); } } Windows.ApplicationModel.AppService.AppServiceResponse response = await connection.SendMessageAsync(request); if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { var message = response.Message as Windows.Foundation.Collections.ValueSet; if (message != null && message.Count > 0) { } return((message != null && message.Count > 0) ? message : null); } } } return(null); }
private async void Connection_RequestReceived(Windows.ApplicationModel.AppService.AppServiceConnection sender, Windows.ApplicationModel.AppService.AppServiceRequestReceivedEventArgs args) { ValueSet message = args.Request.Message; if (message.ContainsKey("InterCommunication")) { Common.InterCommunication interCommunication = JsonSerializer.Deserialize <Common.InterCommunication>(message["InterCommunication"] as string); switch (interCommunication.InterCommunicationType) { case Common.InterCommunicationType.ReportISOConversionProgress: { await coreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { switch (interCommunication.ISOConversionProgress.Phase) { case ProcessPhase.ReadingMetadata: { ReadingMetadataGlyph.Glyph = "\uF167"; break; } case ProcessPhase.PreparingFiles: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uF167"; break; } case ProcessPhase.CreatingWindowsInstaller: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uEC61"; CreatingWindowsInstallerGlyph.Glyph = "\uF167"; break; } case ProcessPhase.ApplyingImage: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uEC61"; CreatingWindowsInstallerGlyph.Glyph = "\uEC61"; ApplyingImageGlyph.Glyph = "\uF167"; break; } case ProcessPhase.IntegratingWinRE: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uEC61"; CreatingWindowsInstallerGlyph.Glyph = "\uEC61"; ApplyingImageGlyph.Glyph = "\uEC61"; IntegratingWinREGlyph.Glyph = "\uF167"; break; } case ProcessPhase.CapturingImage: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uEC61"; CreatingWindowsInstallerGlyph.Glyph = "\uEC61"; ApplyingImageGlyph.Glyph = "\uEC61"; IntegratingWinREGlyph.Glyph = "\uEC61"; CapturingImageGlyph.Glyph = "\uF167"; break; } case ProcessPhase.CreatingISO: { ReadingMetadataGlyph.Glyph = "\uEC61"; PreparingFilesGlyph.Glyph = "\uEC61"; CreatingWindowsInstallerGlyph.Glyph = "\uEC61"; ApplyingImageGlyph.Glyph = "\uEC61"; IntegratingWinREGlyph.Glyph = "\uEC61"; CapturingImageGlyph.Glyph = "\uEC61"; CreatingISOGlyph.Glyph = "\uF167"; break; } case ProcessPhase.Error: { switch (lastPhase) { case ProcessPhase.ReadingMetadata: { ReadingMetadataGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.PreparingFiles: { PreparingFilesGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.CreatingWindowsInstaller: { CreatingWindowsInstallerGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.ApplyingImage: { ApplyingImageGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.IntegratingWinRE: { IntegratingWinREGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.CapturingImage: { CapturingImageGlyph.Glyph = "\uEB90"; break; } case ProcessPhase.CreatingISO: { CreatingISOGlyph.Glyph = "\uEB90"; break; } } break; } } if (interCommunication.ISOConversionProgress.Phase == ProcessPhase.Done) { // Move to finish page when done, for now, welcome page Frame.Navigate(typeof(WelcomePage)); return; } lastPhase = interCommunication.ISOConversionProgress.Phase; ProgressBar.Value = interCommunication.ISOConversionProgress.ProgressInPercentage; ProgressBar.IsIndeterminate = interCommunication.ISOConversionProgress.IsIndeterminate; StatusText.Text = interCommunication.ISOConversionProgress.SubOperation; }); break; } } } }
public async Task<Windows.Foundation.Collections.ValueSet> MakeUWPCommandCall(string commandCall, string serviceName, List<KeyValuePair<string, object>> dataToPass) { using (var connection = new Windows.ApplicationModel.AppService.AppServiceConnection()) { connection.AppServiceName = serviceName; connection.PackageFamilyName = HostPackageFamilyName; var status = await connection.OpenAsync(); if (status != Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success) { throw new NotImplementedException("Failed app service connection"); } else { var request = new Windows.Foundation.Collections.ValueSet(); request.Add("Command", commandCall); if (dataToPass != null && dataToPass.Count > 0) { foreach (var data in dataToPass) { //message.Add(new KeyValuePair<string, object>("AppExtensionDisplayName", AppExtension.AppInfo.DisplayInfo.DisplayName)); request.Add(new KeyValuePair<string, object>(data.Key, data.Value)); } } Windows.ApplicationModel.AppService.AppServiceResponse response = await connection.SendMessageAsync(request); if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success) { var message = response.Message as Windows.Foundation.Collections.ValueSet; if (message != null && message.Count > 0) { } return (message != null && message.Count > 0) ? message : null; } } } return null; }