private async Task <AppServiceConnection> MakeConnection() { var listing = await AppServiceCatalog.FindAppServiceProvidersAsync(AppServiceName); if (listing.Count == 0) { throw new Exception("Unable to find app service '" + AppServiceName + "'"); } var packageName = listing[0].PackageFamilyName; var connection = new AppServiceConnection { AppServiceName = AppServiceName, PackageFamilyName = packageName }; var status = await connection.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { throw new Exception("Could not connect to MessageRelay, status: " + status); } return(connection); }
private async void InitAppSvc() { var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("AppComService"); var packageName = ""; // there may be cases where other applications could expose the same App Service Name, in our case // we only have the one if (listing.Count == 1) { packageName = listing[0].PackageFamilyName; } // Initialize the AppServiceConnection appServiceConnection = new AppServiceConnection(); appServiceConnection.PackageFamilyName = packageName; appServiceConnection.AppServiceName = "AppComService"; // Send a initialize request var res = await appServiceConnection.OpenAsync(); if (res == AppServiceConnectionStatus.Success) { var message = new ValueSet(); message.Add("Command", "Initialize"); var response = await appServiceConnection.SendMessageAsync(message); if (response.Status != AppServiceResponseStatus.Success) { throw new Exception("Failed to send message"); } appServiceConnection.RequestReceived += OnMessageReceived; } }
public async Task InitAsync() { var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("com.softwarelogistics.gcodemachine"); if (listing != null && listing.Any()) { var packageName = listing[0].PackageFamilyName; Debug.WriteLine("Found Package - Opening: " + packageName); _appServiceConnection = new AppServiceConnection(); _appServiceConnection.PackageFamilyName = packageName; _appServiceConnection.AppServiceName = "com.softwarelogistics.gcodemachine"; var status = await _appServiceConnection.OpenAsync(); if (status == AppServiceConnectionStatus.Success) { Debug.WriteLine("Success Opening"); _appServiceConnection.RequestReceived += _appServiceConnection_RequestReceived; } else { Debug.WriteLine("Failed Opening " + status.ToString()); } _appService = new AppService(_appServiceConnection); } else { Debug.Write("Could not connect to background service."); } if (LightningProvider.IsLightningEnabled) { var gpioController = (await GpioController.GetControllersAsync(LightningGpioProvider.GetGpioProvider()))[0]; foreach (var axis in _axes) { axis.Init(gpioController, _appService); } _topLight.Init(gpioController); _bottomLight.Init(gpioController); _vacuum.Init(gpioController); _motorPower.Init(gpioController); _motorPower.Disable(); } else { Debug.WriteLine("Ligtning IS NOT Enabled, please enable through Device Portal"); } StartWorkLoop(); }
private async Task <CrossCuttingRT.Dto.SensorsDataDto> PollData() { CrossCuttingRT.Dto.SensorsDataDto result = null; using (var dataService = new AppServiceConnection()) { var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("DataCollectorInterface"); var packageName = ""; // there may be cases where other applications could expose the same App Service Name, in our case // we only have the one if (listing.Count == 1) { packageName = listing[0].PackageFamilyName; } dataService.AppServiceName = "DataCollectorInterface"; dataService.PackageFamilyName = packageName; var status = await dataService.OpenAsync(); if (status == AppServiceConnectionStatus.Success) { var msg = new ValueSet(); msg.Add("Request", "SensorData"); AppServiceResponse request = await dataService.SendMessageAsync(msg); if (request.Status == AppServiceResponseStatus.Success) { CrossCuttingRT.Dto.SensorsDataDto data = new CrossCuttingRT.Dto.SensorsDataDto(); data.Temperature = request.Message["Temperature"] as double?; data.LightLevel = request.Message["LightLevel"] as double?; result = data; } else { System.Diagnostics.Debug.WriteLine("Request Response Status: " + status.ToString()); } } } return(result); }
/* This procedure will look for WebService application and then initiate and connect it. The * connection itself will be stored in the ApplicationServiceConnection variable which will be * used for communication with the Web Service. This will ensure to get the messages passed * by the Web client (browser) and at the same time send a feedback to the WebService * which will be picked by the Web client. * **/ private async void SetupAppServerService() { var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("com.brahas.WebService"); var packageName = (listing.Count == 1) ? listing[0].PackageFamilyName : string.Empty; asc = new AppServiceConnection(); asc.AppServiceName = "com.brahas.WebService"; asc.PackageFamilyName = packageName; var status = await asc.OpenAsync(); //The service will be started and then open a connection to it if (status != AppServiceConnectionStatus.Success) { tbStatus.Text = "Could not connect: " + status.ToString(); tbStatus.Foreground = new SolidColorBrush(Colors.DarkRed); tbStatus.FontWeight = FontWeights.Bold; } else { asc.RequestReceived += Asc_RequestReceived; } }
private async void SetupAppService() { try { // find the installed application(s) that expose the app service PerimeterBreachService var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("AlertService"); var packageName = ""; // there may be cases where other applications could expose the same App Service Name, in our case // we only have the one if (listing.Count == 1) { packageName = listing[0].PackageFamilyName; } _mediaPlayerService = new AppServiceConnection(); _mediaPlayerService.AppServiceName = "AlertService"; _mediaPlayerService.PackageFamilyName = packageName; _mediaPlayerService.ServiceClosed += OnMediaPlayerServiceClosed; //open app service connection var status = await _mediaPlayerService.OpenAsync(); if (status != AppServiceConnectionStatus.Success) { //something went wrong Debug.WriteLine("Could not open media player service.!!!"); } else { _mediaPlayerService.RequestReceived += OnMediaPlayerServiceRequestReceived; } } catch (Exception ex) { Debug.WriteLine("Exception while application is doing SetupAppService - {0}", ex); } }
private async void RunAppServiceTask(object sender, RoutedEventArgs e) { IReadOnlyList <AppInfo> readOnlyList = (await AppServiceCatalog.FindAppServiceProvidersAsync("AppServiceServer_kj4sv7dv9awfe")).ToList(); foreach (AppInfo _ in readOnlyList) { } var appServiceConnection = new AppServiceConnection { AppServiceName = "AppServiceServerBackgroundTaskName", PackageFamilyName = "AppServiceServer_kj4sv7dv9awfe" }; AppServiceConnectionStatus status = await appServiceConnection.OpenAsync(); if (status == AppServiceConnectionStatus.Success) { AppServiceResponse appServiceResponse = await appServiceConnection.SendMessageAsync(new ValueSet { { "a", null }, { "b", null } }); ValueSet responseValueSet = appServiceResponse.Message; if (responseValueSet == null) { RunAppServiceTextBlock.Text = "response is null"; return; } string response = responseValueSet.ContainsKey("count") ? responseValueSet["count"].ToString() : "missing response key"; RunAppServiceTextBlock.Text = response; return; } RunAppServiceTextBlock.Text = "Failed to connect"; }
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; }