Ejemplo n.º 1
0
        public static async Task InitAsync()
        {
            _service = AppServiceConnectionFactory.GetConnection();
            var serviceStatus = await _service.OpenAsync();

            // Should never fail, since app service is installed with the background app.
            Debug.Assert(serviceStatus == AppServiceConnectionStatus.Success, $"Opening service failed: {serviceStatus}.");

            _service.RequestReceived += (AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) => RequestReceived(sender, args);
            _service.ServiceClosed   += async(AppServiceConnection sender, AppServiceClosedEventArgs args) =>
            {
                _service = null;
                Debug.WriteLine($"Service closed: {args.Status}.");
                await InitAsync();
            };
            Debug.WriteLine("Connected to app service.");
        }
Ejemplo n.º 2
0
        public static async Task InitAsync()
        {
            _service = AppServiceConnectionFactory.GetConnection();
            _service.RequestReceived += (AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) =>
            {
                RequestReceived?.Invoke(sender, args);
            };
            _service.ServiceClosed += (AppServiceConnection sender, AppServiceClosedEventArgs args) => { Reconnect($"Service closed: {args.Status}."); };
            var status = await _service.OpenAsync();

            if (status != AppServiceConnectionStatus.Success)
            {
                Reconnect($"Connection to app service failed: {status}.");
                return;
            }
            Debug.WriteLine("Connected to app service.");
        }