当前位置: 首页>>代码示例>>C#>>正文


C# AppServiceConnection类代码示例

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


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


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