Ejemplo n.º 1
0
 protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
 {
     base.OnBackgroundActivated(args);
     if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
     {
         if (details.CallerPackageFamilyName == Package.Current.Id.FamilyName)
         {
             try
             {
                 _appServiceDeferral         = args.TaskInstance.GetDeferral();
                 args.TaskInstance.Canceled += (s, e) =>
                 {
                     _appServiceDeferral?.Complete();
                     _appServiceDeferral = null;
                     Connection          = null;
                     AppServiceDisconnected?.Invoke(this, null);
                 };
                 Connection = details.AppServiceConnection;
                 AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
                 _logger.Info("辅助进程服务连接成功");
             }
             catch (Exception ex)
             {
                 _logger.Error("辅助进程服务连接失败");
                 _logger.Error(ex);
             }
         }
     }
     else
     {
         _logger.Error("辅助进程服务连接失败");
         _logger.Error(args.TaskInstance.TriggerDetails.GetType());
     }
 }
Ejemplo n.º 2
0
        //App Service
        // see https://blogs.msdn.microsoft.com/appconsult/2016/12/19/desktop-bridge-the-migrate-phase-invoking-a-win32-process-from-a-uwp-app/
        public static void OnAppServiceActivated(BackgroundActivatedEventArgs args)
        {
            IBackgroundTaskInstance  taskInstance = args.TaskInstance;
            AppServiceTriggerDetails details      = (AppServiceTriggerDetails)args.TaskInstance.TriggerDetails;

            appServiceDeferral     = taskInstance.GetDeferral();
            taskInstance.Canceled += OnAppServiceCanceled;
            appServiceConnection   = details.AppServiceConnection;

            AppServiceConnected?.Invoke(null, null);
        }
Ejemplo n.º 3
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);

            if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details && details.CallerPackageFamilyName == Package.Current.Id.FamilyName)
            {
                AppServiceDeferral          = args.TaskInstance.GetDeferral();
                args.TaskInstance.Canceled += OnTaskCanceled;
                Connection = details.AppServiceConnection;
                AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
            }
        }
Ejemplo n.º 4
0
 protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
 {
     // connection established from the fulltrust process
     base.OnBackgroundActivated(args);
     if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
     {
         AppServiceDeferral          = args.TaskInstance.GetDeferral();
         args.TaskInstance.Canceled += OnTaskCanceled;
         Connection = details.AppServiceConnection;
         Connection.RequestReceived += OnRequestReceived;
         AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
     }
 }
Ejemplo n.º 5
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails)
            {
                AppServiceDeferral          = args.TaskInstance.GetDeferral();
                args.TaskInstance.Canceled += OnTaskCanceled;

                if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
                {
                    Connection = details.AppServiceConnection;
                    AppServiceConnected?.Invoke(this, null);
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails)
            {
                // Hold deferral reference to make sure AppService connection is always alive
                appServiceDeferral          = args.TaskInstance.GetDeferral();
                args.TaskInstance.Canceled += OnTaskCanceled; // Associate a cancellation handler with the background task.

                if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
                {
                    connection = details.AppServiceConnection;

                    // Notify that connection between app and desktop server has been built
                    AppServiceConnected?.Invoke(this, null);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Invoked when the application is launched to handle background task.
        /// </summary>
        /// <param name="args">Details about the launch request.</param>
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);

            AppServiceTriggerDetails details = args.TaskInstance.TriggerDetails as AppServiceTriggerDetails;

            if (details != null)
            {
                // Hold deferral reference to make sure AppService connection is always alive
                appServiceDeferral = args.TaskInstance.GetDeferral();

                connection = details.AppServiceConnection;

                // Notify that connection between app and desktop server has been built
                AppServiceConnected?.Invoke(this, null);
            }
        }
Ejemplo n.º 8
0
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);

            if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
            {
                // only accept connections from callers in the same package
                if (details.CallerPackageFamilyName == Package.Current.Id.FamilyName)
                {
                    // connection established from the fulltrust process
                    AppServiceDeferral          = args.TaskInstance.GetDeferral();
                    args.TaskInstance.Canceled += OnTaskCanceled;

                    AppServiceConnection = details.AppServiceConnection;
                    AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
                }
            }
        }
Ejemplo n.º 9
0
        public static void OnNewAppService(BackgroundActivatedEventArgs args, AppServiceTriggerDetails details)
        {
            if (details.CallerPackageFamilyName == Package.Current.Id.FamilyName)
            {
                // keep the deferal alive for allowing communications between processes
                var appServiceDeferral = args.TaskInstance.GetDeferral();

                var cts = new CancellationTokenSource();

                //Complete deferal when background process is stopped
                cts.Token.Register(() => appServiceDeferral.Complete());
                args.TaskInstance.Canceled += delegate
                {
                    cts.Cancel();
                };

                AppServiceConnected?.Invoke(null, Tuple.Create(details, cts));
            }
        }