/// <summary> /// Send request to query the registry /// </summary> private async void btnClick_ReadKey(object sender, RoutedEventArgs e) { request.Clear(); request.Add("KEY", tbKey.Text); AppServiceResponse response = await App.Connection.SendMessageAsync(request); // display the response key/value pairs tbResult.Text = ""; foreach (string key in response.Message.Keys) { tbResult.Text += key + " = " + response.Message[key] + "\r\n"; } }
private async void Button_Click(object sender, RoutedEventArgs e) { // Add the connection. if (this.inventoryService == null) { this.inventoryService = new AppServiceConnection(); // Here, we use the app service name defined in the app service // provider's Package.appxmanifest file in the <Extension> section. this.inventoryService.AppServiceName = "com.microsoft.inventory"; // Use Windows.ApplicationModel.Package.Current.Id.FamilyName // within the app service provider to get this value. this.inventoryService.PackageFamilyName = "f8439e8e-d9d3-4843-b3ad-a7fce65b6d49_8vkwcx8tjcnay"; var status = await this.inventoryService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { textBox.Text = "Failed to connect"; this.inventoryService = null; return; } } // Call the service. int idx = int.Parse(textBox.Text); var message = new ValueSet(); message.Add("Command", "Item"); message.Add("ID", idx); AppServiceResponse response = await this.inventoryService.SendMessageAsync(message); string result = ""; if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result = response.Message["Result"] as string; } } message.Clear(); message.Add("Command", "Price"); message.Add("ID", idx); response = await this.inventoryService.SendMessageAsync(message); if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result += " : Price = " + response.Message["Result"] as string; } } textBox.Text = result; }
private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { //async operation needs a deferral var msgDeferral = args.GetDeferral(); //picking up the data ValueSet var input = args.Request.Message; var result = new ValueSet(); //parsing the ValueSet var response = (string)input["question"]; try { //as long as the app service connection is established we are using the same instance even if data changes. //to avoid crashes, clear the result before getting the new one result.Clear(); if (!string.IsNullOrEmpty(response)) { var responderResponse = AppServiceResponder.Responder.Instance.GetResponse(response); result.Add("Status", "OK"); result.Add("response", responderResponse); } await args.Request.SendResponseAsync(result); } //using finally because we need to tell the OS we have finished, no matter of the result finally { msgDeferral?.Complete(); } }
private async void Button_Click(object sender, RoutedEventArgs e) { // Add the connection. if (this.inventoryService == null) { this.inventoryService = new AppServiceConnection(); // Here, we use the app service name defined in the app service provider's Package.appxmanifest file in the <Extension> section. this.inventoryService.AppServiceName = "com.microsoft.inventory"; // Use Windows.ApplicationModel.Package.Current.Id.FamilyName within the app service provider to get this value. this.inventoryService.PackageFamilyName = "e2cc7592-32d1-43a6-80a3-10a0f89a13d4_4ear8jrhgg8sp"; //this.inventoryService.PackageFamilyName = "1.0.0.0_x86__4ear8jrhgg8sp"; //this.inventoryService.PackageFamilyName = "6aeb6501-6116-40e3-8855-910d573121da_1.0.0.0_x86__4ear8jrhgg8sp"; var status = await this.inventoryService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { textBox.Text = "Failed to connect"; return; } } // Call the service. int idx = int.Parse(textBox.Text); var message = new ValueSet(); message.Add("Command", "Item"); message.Add("ID", idx); AppServiceResponse response = await this.inventoryService.SendMessageAsync(message); string result = ""; if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result = response.Message["Result"] as string; } } message.Clear(); message.Add("Command", "Price"); message.Add("ID", idx); response = await this.inventoryService.SendMessageAsync(message); if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result += " : Price = " + response.Message["Result"] as string; } } textBox.Text = result; }
/// <summary> /// Receives message from UWP app and sends a response back /// </summary> private static void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { string key = args.Request.Message.First().Key; string value = args.Request.Message.First().Value.ToString(); ValueSet valueSet = new ValueSet(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(string.Format("Received message '{0}' with value '{1}'", key, value)); switch (value) { case "claimScale": // send back: scaleReady valueSet.Add("response", "scaleReady"); args.Request.SendResponseAsync(valueSet).Completed += delegate { }; Console.WriteLine(string.Format("Sending response: '{0}'", "scaleReady")); Console.WriteLine(); valueSet.Clear(); //Finds scales in the service enumeration and return the one we use for demo that has table in the name //Call the classic OPOS code // "table" parameter was specific to the device we used in video demo, please adapt to you target device selectedDeviceInfo = Find("scale", "table"); //Run Open, Claim, Enable device for usage claimedDevice = Scale_ClaimOpenEnable(selectedDeviceInfo); return; case "getWeight": //send back: weight String auxWeight = getWeight(); valueSet.Add("response", auxWeight); args.Request.SendResponseAsync(valueSet).Completed += delegate { }; Console.WriteLine(string.Format("Sending response: '{0}'", auxWeight)); Console.WriteLine(); valueSet.Clear(); return; case "endProcess": valueSet.Add("response", "processEnded"); args.Request.SendResponseAsync(valueSet).Completed += delegate { }; keepRuuning = false; valueSet.Clear(); return; } }
/// <summary> /// Open connection to UWP app service /// </summary> private async void InitializeAppServiceConnection() { response.Clear(); connection = new AppServiceConnection(); connection.AppServiceName = "SampleInteropService"; connection.PackageFamilyName = Package.Current.Id.FamilyName; connection.RequestReceived += Connection_RequestReceived; connection.ServiceClosed += Connection_ServiceClosed; AppServiceConnectionStatus status = await connection.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { // something went wrong ... MessageBox.Show(status.ToString()); this.IsEnabled = false; } }
private async void button_Click(object sender, RoutedEventArgs e) { // Add the connection. if (this.inventoryService == null) { this.inventoryService = new AppServiceConnection(); this.inventoryService.AppServiceName = "com.microsoft.inventory"; this.inventoryService.PackageFamilyName = "bb1a8478-8005-46869923-e525ceaa26fc_4sz2ag3dcq60a"; var status = await this.inventoryService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { button.Content = "Failed To Connect"; return; } } // Call the service. var idx = int.Parse(textBox.Text); var message = new ValueSet(); message.Add("Command", "Item"); message.Add("ID", idx); AppServiceResponse response = await this.inventoryService.SendMessageAsync(message); string result = ""; if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result = response.Message["Result"] as string; } } message.Clear(); message.Add("Command", "Price"); message.Add("ID", idx); response = await this.inventoryService.SendMessageAsync(message); if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["message"] as string == "OK") { result += " : Price = " + "$" + response.Message["Result"] as string; } } textBlock.Text = result; }
/// <summary> /// Initiates the second screen experience on the client if the system is showing a slideshow /// </summary> /// <param name="system"></param> /// <returns>Message from system with what adventure and current slide number</returns> public async Task <ValueSet> ConnectToSystem(AdventureRemoteSystem system) { ValueSet message = new ValueSet(); message.Add("query", ConnectedServiceQuery.StartHostingSession.ToString()); var response = await system.SendMessage(message); if (response != null && response.ContainsKey("success") && (bool)response["success"]) { var status = (ConnectedServiceStatus)Enum.Parse(typeof(ConnectedServiceStatus), (String)response["status"]); if (status != ConnectedServiceStatus.HostingNotConnected && status != ConnectedServiceStatus.HostingConnected) { return(null); } message.Clear(); if (_remoteSystem != system) { if (_remoteSystem != null) { _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived; _remoteSystem = null; } _remoteSystem = system; _remoteSystem.MessageReceived += _remoteSystem_MessageReceived; } response = await SendMessageFromClientAsync(message, SlideshowMessageTypeEnum.Status); if (response == null) { _remoteSystem = null; _remoteSystem.MessageReceived -= _remoteSystem_MessageReceived; return(null); } return(response); } return(null); }
private async Task StartAppService() { if (this.appService == null) { this.appService = new AppServiceConnection(); // Here, we use the app service name defined in the app service // provider's Package.appxmanifest file in the <Extension> section. this.appService.AppServiceName = "InProcessAppService"; // Use Windows.ApplicationModel.Package.Current.Id.FamilyName // within the app service provider to get this value. this.appService.PackageFamilyName = "30812FreistLi.HoloDomino_33rssfepyhexc"; var status = await this.appService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { Debug.WriteLine("Failed to create"); return; } } var message = new ValueSet(); message.Add("Request", "StartAnimator"); AppServiceResponse response = await this.appService.SendMessageAsync(message); string result = ""; if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Response"] as string == "OK") { result = response.Message["StatusCode"] as string; } } message.Clear(); }
private async void button_Click(object sender, RoutedEventArgs e) { string result = ""; // Add the connection. if (this.inventoryService == null) { this.inventoryService = new AppServiceConnection(); var appServiceName = "com.microsoft.inventory"; //var appServiceName = "InProcessAppSvc"; // Here, we use the app service name defined in the app service provider's Package.appxmanifest file in the <Extension> section. this.inventoryService.AppServiceName = appServiceName; var listing = await AppServiceCatalog.FindAppServiceProvidersAsync(appServiceName); var packageName = listing[0].PackageFamilyName; // Use Windows.ApplicationModel.Package.Current.Id.FamilyName within the app service provider to get this value. //this.inventoryService.PackageFamilyName = "032e90bc-4fc8-4f7d-a738-084235381814_zrn1d0te84tw0"; this.inventoryService.PackageFamilyName = packageName; var status = await this.inventoryService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { textBox.Text = "Failed to connect"; return; } result = GetStatusDetail(status); } // Call the service. int idx = int.Parse(textBox.Text); var message = new ValueSet(); message.Add("Command", "manual_download_promotions"); message.Add("ID", idx); AppServiceResponse response = await this.inventoryService.SendMessageAsync(message); if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result += response.Message["Result"] as string; StorageFolder sharedDownloadsFolder = ApplicationData.Current.GetPublisherCacheFolder("Downloads"); StorageFile sampleFile = await sharedDownloadsFolder.GetFileAsync("IntelMarketingMaterial.json"); String fileContent = await FileIO.ReadTextAsync(sampleFile); textBox1.Text = fileContent; } } idx = int.Parse(textBox.Text); message = new ValueSet(); message.Add("Command", "automatic_download_promotions"); message.Add("ID", idx); response = await this.inventoryService.SendMessageAsync(message); result = ""; if (response.Status == AppServiceResponseStatus.Success) { // Get the data that the service sent to us. if (response.Message["Status"] as string == "OK") { result += response.Message["Result"] as string; StorageFolder sharedDownloadsFolder = ApplicationData.Current.GetPublisherCacheFolder("Downloads"); StorageFile sampleFile = await sharedDownloadsFolder.GetFileAsync("IntelMarketingMaterial.json"); String fileContent = await FileIO.ReadTextAsync(sampleFile); textBox1.Text = fileContent; } } message.Clear(); textBox.Text = result; }
/// <summary> /// Get the Startup program names from the RegistryReadAppService and put them in ObservableCollection /// bound to the ListBox in the UI. /// </summary> private async void GetStartupProgramNames() { ValueSet valueSet = new ValueSet(); valueSet.Clear(); valueSet.Add("verb", "getStartupProgramNames"); try { AppServiceResponse response = await App.Connection.SendMessageAsync(valueSet); if (response.Status == AppServiceResponseStatus.Success) { ValueSet test = response.Message; // Get the data that the service sent to us. if (response.Message["verb"] as string == "RegistryReadResult") { // Update UI-bound collections and controls on the UI thread await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { StartupProgramNames.Clear(); string[] newNames = (string[])response.Message["StartupProgramNames"]; StartupProgramNames = new ObservableCollection <string>(newNames); // scroll to bottom of the list StartupProgramsListView.SelectedIndex = startupProgramNames.Count - 1; StartupProgramsListView.ScrollIntoView(StartupProgramsListView.SelectedItem); // Adjust the label of the RegistryButton. The action of // removing it actually takes place in ElevatedRegistryWrite.exe // which decides on its own indepenently which action to take // based on whether "notepad" is in the Registry's list. if (StartupProgramNames.Contains("notepad")) { RegistryButton.Content = "Remove Notepad"; } else { RegistryButton.Content = "Add Notepad"; } }); } else if (response.Message["verb"] as string == "RegistryReadError") { string exceptionMessage = response.Message["exceptionMessage"] as string; MainPage.Current?.NotifyUser(string.Format("RegistryReadError, Exception: {0}", exceptionMessage), NotifyType.ErrorMessage); } else { MainPage.Current?.NotifyUser("RegistryReadError, unknown type.", NotifyType.ErrorMessage); } } else { MainPage.Current?.NotifyUser(string.Format("GetStartupProgramNames error AppServiceResponse: {0}", response?.Status.ToString()), NotifyType.ErrorMessage); } } catch (Exception ex) { MainPage.Current?.NotifyUser(string.Format("GetStartupProgramNames Exception. Message {0}", ex.Message.ToString()), NotifyType.ErrorMessage); } }
public virtual void Clear() { Sum = 0; ValueSet.Clear(); }
public void Clear() { ValueSet.Clear(this); }