• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AppServiceConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AppServiceConnection的典型用法代码示例。如果您正苦于以下问题:C# AppServiceConnection类的具体用法?C# AppServiceConnection怎么用?C# AppServiceConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AppServiceConnection类属于命名空间,在下文中一共展示了AppServiceConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WebSocketServer

 public WebSocketServer(AppServiceConnection connection)
 {
     _appServiceConnection = connection;
     _appServiceConnection.RequestReceived += OnRequestReceived;
     
     _portMapping = new IdHelper(5);
 }
开发者ID:Quantzo,项目名称:IotRouter,代码行数:7,代码来源:WebSocketServer.cs


示例2: InitializeAppSvc

        private async void InitializeAppSvc()
        {
            string WebServerStatus = "PoolWebServer failed to start. AppServiceConnectionStatus was not successful.";

            // Initialize the AppServiceConnection
            appServiceConnection = new AppServiceConnection();
            appServiceConnection.PackageFamilyName = "PoolWebServer_hz258y3tkez3a";
            appServiceConnection.AppServiceName = "App2AppComService";

            // 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)
                {
                    WebServerStatus = "PoolWebServer failed to start.";
                    throw new Exception("Failed to send message");
                }
                appServiceConnection.RequestReceived += OnMessageReceived;
                WebServerStatus = "PoolWebServer started.";
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                txtWebServerStatus.Text = WebServerStatus;
            });
        }
开发者ID:mmackes,项目名称:Windows-10-IoT-PoolController,代码行数:30,代码来源:MainPage.xaml.cs


示例3: AppServiceConnection_RequestReceived

        private async void AppServiceConnection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var message = args.Request.Message;
            string command = message["Command"] as string;

            switch (command)
            {
                case "CalcSum":
                    {
                        var messageDeferral = args.GetDeferral();

                        int value1 = (int)message["Value1"];
                        int value2 = (int)message["Value2"];

                        //Set a result to return to the caller 
                        int result = value1 + value2;
                        var returnMessage = new ValueSet();
                        returnMessage.Add("Result", result);
                        var responseStatus = await args.Request.SendResponseAsync(returnMessage);

                        messageDeferral.Complete();
                        break;
                    }

                case "Quit":
                    {
                        //Service was asked to quit. Give us service deferral 
                        //so platform can terminate the background task 
                        _serviceDeferral.Complete();
                        break;
                    }
            }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:33,代码来源:AppServiceTask.cs


示例4: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Loading.IsActive = true;
            AppServiceConnection connection = new AppServiceConnection();
            connection.PackageFamilyName = Package.Current.Id.FamilyName;
            connection.AppServiceName = "FeedParser";

            var status = await connection.OpenAsync();

            if (status == AppServiceConnectionStatus.Success)
            {
                ValueSet data = new ValueSet();
                data.Add("FeedUrl", "http://blog.qmatteoq.com/feed/");

                var response = await connection.SendMessageAsync(data);
                if (response.Status == AppServiceResponseStatus.Success)
                {
                    string items = response.Message["FeedItems"].ToString();
                    var result = JsonConvert.DeserializeObject<List<FeedItem>>(items);
                    News.ItemsSource = result;
                }
            }

            Loading.IsActive = false;
        }
开发者ID:qmatteoq,项目名称:dotNetSpainConference2016,代码行数:25,代码来源:MainPage.xaml.cs


示例5: EnsureConnectionToService

        private async System.Threading.Tasks.Task EnsureConnectionToService()
        {
            if (this.connection == null)
            {
                connection = new AppServiceConnection();

                // See the appx manifest of the AppServicesDemp app for this value
                connection.AppServiceName = "microsoftDX-appservicesdemo";
                // Use the Windows.ApplicationModel.Package.Current.Id.FamilyName API in the 
                // provider app to get this value
                connection.PackageFamilyName = "82a987d5-4e4f-4cb4-bb4d-700ede1534ba_nsf9e2fmhb1sj";

                AppServiceConnectionStatus connectionStatus = await connection.OpenAsync();
                if (connectionStatus == AppServiceConnectionStatus.Success)
                {
                    connection.ServiceClosed += OnServiceClosed;
                    //connection.RequestReceived += OnRequestReceived;
                }
                else
                {
                    //Drive the user to store to install the app that provides 
                    //the app service 
                }
            }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:25,代码来源:MainPage.xaml.cs


示例6: MakeUWPCommandCall

        public async Task<ValueSet> MakeUWPCommandCall(string commandCall, string serviceName) {
            if (AppExtension == null) return null;
            using (var connection = new AppServiceConnection())
            {
                connection.AppServiceName = serviceName;
                connection.PackageFamilyName = AppExtension.Package.Id.FamilyName;
                var status = await connection.OpenAsync();
                if (status != AppServiceConnectionStatus.Success)
                {
                    Debug.WriteLine("Failed app service connection");
                }
                else
                {
                    var request = new ValueSet();
                    request.Add("Command", commandCall);
                    AppServiceResponse response = await connection.SendMessageAsync(request);
                    if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success)
                    {
                        var message = response.Message as ValueSet;
                        if (message != null && message.Count > 0) {
                            message.Add(new KeyValuePair<string, object>("AppExtensionDisplayName", AppExtension.AppInfo.DisplayInfo.DisplayName));
                        }
                        return (message!=null && message.Count>0)? message: null;
                    }
                }

            }
            return null;
        }
开发者ID:liquidboy,项目名称:X,代码行数:29,代码来源:ExtensionLite.cs


示例7: Connection_RequestReceived

		private async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
		{
			var lDeferral = args.GetDeferral();
			try
			{
				var message = args.Request.Message;
				if(message.ContainsKey("MessageType") && message.ContainsKey("Message"))
				{
					var type = message["MessageType"] as String;
					var mes = message["Message"] as String;
					if(type != null && mes != null)
					{
						using(var lh = new LoggingHelper())
						{
							var result = lh.LogEntry(type, mes);
							var vs = new ValueSet();
							vs["result"] = result;
							await args.Request.SendResponseAsync(vs);
						}
					}
				}
			}
			catch { }
			lDeferral.Complete();	
		}
开发者ID:holtsoftware,项目名称:House,代码行数:25,代码来源:LoggingAppService.cs


示例8: LaunchAppService

        private async Task LaunchAppService(string cmd)
        {
            var connection = new AppServiceConnection
            {
                AppServiceName = "uwpdeepdive-appservice",
                PackageFamilyName = "11fc3805-6c54-417b-916c-a4f6e89876b2_2eqywga5gg4gm"
            };
            var appServiceConnectionStatus = await connection.OpenAsync();
            if (appServiceConnectionStatus != AppServiceConnectionStatus.Success)
            {
                _resultsTextBox.Text = appServiceConnectionStatus.ToString();
                return;
            }

            var msg = new ValueSet {["cmd"] = cmd};
            var appServiceResponse = await connection.SendMessageAsync(msg);
            if (appServiceResponse.Status != AppServiceResponseStatus.Success)
            {
                _resultsTextBox.Text = appServiceResponse.Status.ToString();
                return;
            }
            var time = appServiceResponse.Message[cmd] as string;
            _resultsTextBox.Text = time ?? "";

            //note - communication is two-way! can send/receive as needed
            //connection.RequestReceived += delegate(
            //    AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) { /* ... */ };
        }
开发者ID:andyhammar,项目名称:win10apps-deepdive,代码行数:28,代码来源:BuddyMainPage.xaml.cs


示例9: EnsureConnectionToSynonymsService

        private async System.Threading.Tasks.Task EnsureConnectionToSynonymsService()
        {
            if (this.synonymsServiceConnection == null)
            {
                synonymsServiceConnection = new AppServiceConnection();

                // See the appx manifest of the AppServicesDemp app for this value
                synonymsServiceConnection.AppServiceName = "MicrosoftDX-SynonymsService";
                // Use the Windows.ApplicationModel.Package.Current.Id.FamilyName API in the 
                // provider app to get this value
                synonymsServiceConnection.PackageFamilyName = "82a987d5-4e4f-4cb4-bb4d-700ede1534ba_nsf9e2fmhb1sj";

                AppServiceConnectionStatus connectionStatus = await synonymsServiceConnection.OpenAsync();
                if (connectionStatus == AppServiceConnectionStatus.Success)
                {
                    synonymsServiceConnection.ServiceClosed += (s, serviceClosedEventArgs) =>
                    {
                        if (ServiceClosed != null)
                        {
                            ServiceClosed(this, serviceClosedEventArgs);
                        }
                    };
                }
                else
                {
                    //Drive the user to store to install the app that provides 
                    //the app service 
                    throw new NotImplementedException("Service not installed on this device");
                }
            }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:31,代码来源:SynonymsServiceClient.cs


示例10: RestServer

 public RestServer(int serverPort, string serviceConnection)
 {
     listener = new StreamSocketListener();
     port = serverPort;
     appServiceConnection = new AppServiceConnection() { AppServiceName = serviceConnection };
     listener.ConnectionReceived += (s, e) => ProcessRequestAsync(e.Socket);
 }
开发者ID:LeighCurran,项目名称:IoTExamples,代码行数:7,代码来源:RestServer.cs


示例11: OnRequestReceived

        async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            //Get a deferral so we can use an awaitable API to respond to the message
            var messageDeferral = args.GetDeferral();

            try
            {
                var input = args.Request.Message;
                int minValue = (int)input["minvalue"];
                int maxValue = (int)input["maxvalue"];

                //Create the response
                var result = new ValueSet();
                result.Add("result", randomNumberGenerator.Next(minValue, maxValue));

                //Send the response
                await args.Request.SendResponseAsync(result);

            }
            finally
            {
                //Complete the message deferral so the platform knows we're done responding
                messageDeferral.Complete();
            }
        }
开发者ID:mweilb,项目名称:SampleCode,代码行数:25,代码来源:RandomNumberGeneratorTask.cs


示例12: AzureIoTHubConnection

        public AzureIoTHubConnection(AppServiceConnection connection)
        {
            _appServiceConnection = connection;
            deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString);
            _appServiceConnection.RequestReceived += OnRequestReceived;

        }
开发者ID:Quantzo,项目名称:IotRouter,代码行数:7,代码来源:AzureIoTHubConnection.cs


示例13: Connection_RequestReceived

		private async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
		{
			var reqDeferral = args.GetDeferral();
			var message = args.Request.Message;
            var result = new ValueSet();
			if (args.Request.Message.ContainsKey("service"))
			{
				var serviceName = message["service"] as string;
				if (serviceName.Equals("add", StringComparison.OrdinalIgnoreCase))
				{
					if (message.ContainsKey("a") && message.ContainsKey("b"))
					{
						result.Add("result", Add((int)message["a"], (int)message["b"]));
					}
				}
				else if (serviceName.Equals("sub", StringComparison.OrdinalIgnoreCase))
				{
					if (message.ContainsKey("a") && message.ContainsKey("b"))
					{
						result.Add("result", Sub((int)message["a"], (int)message["b"]));
					}
				}
                else
                {
                    result.Add("result", 0);
                }
			}
			await args.Request.SendResponseAsync(result);
			reqDeferral.Complete();
		}
开发者ID:oudoulj,项目名称:win10demo,代码行数:30,代码来源:CalculatorService.cs


示例14: OnRequestReceived

        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var message = args.Request.Message;
            string command = message["Command"] as string;

            switch (command)
            {
                case "Initialize":
                    var messageDeferral = args.GetDeferral();
                    //Set a result to return to the caller
                    var returnMessage = new ValueSet();
                    HttpServer server = new HttpServer(8000, appServiceConnection);
                    IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync(
                        (workItem) =>
                        {
                            server.StartServer();
                        });
                    returnMessage.Add("Status", "Success");
                    var responseStatus = await args.Request.SendResponseAsync(returnMessage);
                    messageDeferral.Complete();
                    break;
                case "Quit":
                    //Service was asked to quit. Give us service deferral
                    //so platform can terminate the background task
                    serviceDeferral.Complete();
                    break;
            }
        }
开发者ID:nudaca,项目名称:simplehttpserver.uwp,代码行数:28,代码来源:BackgroundTask.cs


示例15: OnMessageReceived

 private async void OnMessageReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
 {
     var message = args.Request.Message;
     string newState = message["State"] as string;
     switch (newState)
     {
         case "On":
             {
                 await Dispatcher.RunAsync(
                       CoreDispatcherPriority.High,
                      () =>
                      {
                          TurnOnLED();
                      }); 
                 break;
             }
         case "Off":
             {
                 await Dispatcher.RunAsync(
                 CoreDispatcherPriority.High,
                 () =>
                 {
                     TurnOffLED();
                  });
                 break;
             }
         case "Unspecified":
         default:
             {
                 // Do nothing 
                 break;
             }
     }
 }
开发者ID:chris-perry,项目名称:DigitalControl,代码行数:34,代码来源:MainPage.xaml.cs


示例16: Run

        //TemperatureSensors tempSensors;

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            //if (!_started)
            //{
            //    tempSensors = new TemperatureSensors();
            //    tempSensors.InitSensors();
            //    _started = true;
            //}
            
            // Associate a cancellation handler with the background task. 
            taskInstance.Canceled += TaskInstance_Canceled;

            // Get the deferral object from the task instance
            serviceDeferral = taskInstance.GetDeferral();

            var appService = taskInstance.TriggerDetails as AppServiceTriggerDetails;
            if (appService != null && appService.Name == "App2AppComService")
            {
                appServiceConnection = appService.AppServiceConnection;
                appServiceConnection.RequestReceived += AppServiceConnection_RequestReceived; ;
            }

            // just run init, maybe don't need the above...
            Initialize();
        }
开发者ID:admin4cc,项目名称:sprinklerServer,代码行数:27,代码来源:StartupTask.cs


示例17: CallService_Click

		private async void CallService_Click(object sender, RoutedEventArgs e)
		{
			var connection = new AppServiceConnection();
			connection.PackageFamilyName = "0df93276-6bbb-46fa-96b7-ec223e226505_cb1hhkscw5m06"; // Windows.ApplicationModel.Package.Current.Id.FamilyName;
			connection.AppServiceName = "CalculatorService";
			var status = await connection.OpenAsync();
			if (status != AppServiceConnectionStatus.Success)
			{
				var dialog = new MessageDialog("Sorry, I can't connect to the service right now :S");
				await dialog.ShowAsync();
				return;
			}
			var message = new ValueSet();
			message.Add("service", OperatorCombo.Items[OperatorCombo.SelectedIndex]);
			message.Add("a", Convert.ToInt32(ValueABox.Text));
			message.Add("b", Convert.ToInt32(ValueBBox.Text));
			AppServiceResponse response = await connection.SendMessageAsync(message);
			if (response.Status == AppServiceResponseStatus.Success)
			{
				if (response.Message.ContainsKey("result"))
				{
					ResultBlock.Text = response.Message["result"] as string;
				}
			}
			else
			{
				var dialog = new MessageDialog(string.Format("Opps, I just get an error :S ({0})", response.Status));
				await dialog.ShowAsync();
			}
		}
开发者ID:ericzile,项目名称:win10demo,代码行数:30,代码来源:LauncherView.xaml.cs


示例18: AppServiceConnection_RequestReceived

        private async void AppServiceConnection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var msgDef = args.GetDeferral();
            var msg = args.Request.Message;
            var returnData = new ValueSet();

            var command = msg["Command"] as string;

            switch (command) {
                case "UI":
                    returnData.Add("sketch-test", "X.Extension.ThirdParty.Backgrounds.UI.Test");
                    returnData.Add("sketch-home", "X.Extension.ThirdParty.Backgrounds.UI.Home");
                    break;
                case "RandomBackground":
                    Random rnd = new Random();
                    returnData.Add("filename", $"bkg0{rnd.Next(1, 5)}.jpg");
                    break;
                case "Spritesheet":
                    returnData.Add("spritesheet-img", "bkg-spritesheet.jpg");
                    returnData.Add("spritesheet-xml", "bkg-spritesheet.xml");
                    break;
            }
            
            await args.Request.SendResponseAsync(returnData);
            msgDef.Complete();
        }
开发者ID:liquidboy,项目名称:X,代码行数:26,代码来源:CallService.cs


示例19: GetEmployeeById

        private async void GetEmployeeById(object sender, RoutedEventArgs e)
        {

            appServiceConnection = new AppServiceConnection
            {
                AppServiceName = "EmployeeLookupService",
                PackageFamilyName = "3598a822-2b34-44cc-9a20-421137c7511f_4frctqp64dy5c"
            };

            var status = await appServiceConnection.OpenAsync();

            switch (status)
            {
                case AppServiceConnectionStatus.AppNotInstalled:
                    await LogError("The EmployeeLookup application is not installed. Please install it and try again.");
                    return;
                case AppServiceConnectionStatus.AppServiceUnavailable:
                    await LogError("The EmployeeLookup application does not have the available feature");
                    return;
                case AppServiceConnectionStatus.AppUnavailable:
                    await LogError("The package for the app service to which a connection was attempted is unavailable.");
                    return;
                case AppServiceConnectionStatus.Unknown:
                    await LogError("Unknown Error.");
                    return;
            }

            var items = this.EmployeeId.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            var message = new ValueSet();

            for (int i = 0; i < items.Length; i++)
            {
                message.Add(i.ToString(), items[i]);
            }

            var response = await appServiceConnection.SendMessageAsync(message);

            switch (response.Status)
            {
                case AppServiceResponseStatus.ResourceLimitsExceeded:
                    await LogError("Insufficient resources. The app service has been shut down.");
                    return;
                case AppServiceResponseStatus.Failure:
                    await LogError("Failed to receive response.");
                    return;
                case AppServiceResponseStatus.Unknown:
                    await LogError("Unknown error.");
                    return;
            }

            foreach (var item in response.Message)
            {
                this.Items.Add(new Employee
                {
                    Id = item.Key,
                    Name = item.Value.ToString()
                });
            }
        }
开发者ID:MaedaNoriyuki,项目名称:WinDevHOLs,代码行数:60,代码来源:MainPage.xaml.cs


示例20: InitializeService

        private async void InitializeService()
        {
            _appServiceConnection = new AppServiceConnection
            {
                PackageFamilyName = "ConnectionService-uwp_5gyrq6psz227t",
                AppServiceName = "App2AppComService"
            };

            // Send a initialize request 
            var res = await _appServiceConnection.OpenAsync();
            if (res == AppServiceConnectionStatus.Success)
            {
                var message = new ValueSet {{"Command", "Connect"}};

                var response = await _appServiceConnection.SendMessageAsync(message);
                if (response.Status == AppServiceResponseStatus.Success)
                {
                    InitializeSerialBridge();
                    //InitializeBluetoothBridge();
                    _appServiceConnection.RequestReceived += _serialBridge.OnCommandRecived;
                    //_appServiceConnection.RequestReceived += _bluetoothBridge.OnCommandRecived;
                    //_appServiceConnection.RequestReceived += _appServiceConnection_RequestReceived;
                    
                }
            }
        }
开发者ID:Quantzo,项目名称:IotRouter,代码行数:26,代码来源:StartupTask.cs



注:本文中的AppServiceConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AppSettings类代码示例发布时间:2022-05-24
下一篇:
C# AppKit类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap