示例#1
0
        public void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance)
        {
            if (taskInstance == null)
            {
                Diag.DebugPrint("PushNotifyTask: taskInstance was null");
                return;
            }

            Diag.DebugPrint("PushNotifyTask " + taskInstance.Task.Name + " Starting...");

            // Use the ControlChannelTriggerEventDetails object to derive the context for this background task.
            // The context happens to be the channelId that apps can use to differentiate between
            // various instances of the channel..
            var channelEventArgs = taskInstance.TriggerDetails as IControlChannelTriggerEventDetails;

            ControlChannelTrigger channel = channelEventArgs.ControlChannelTrigger;

            if (channel == null)
            {
                Diag.DebugPrint("Channel object may have been deleted.");
                return;
            }

            string channelId = channel.ControlChannelTriggerId;

            if (((IDictionary <string, object>)CoreApplication.Properties).ContainsKey(channelId))
            {
                try
                {
                    string messageReceived = "PushNotification Received";
                    var    appContext      = ((IDictionary <string, object>)CoreApplication.Properties)[channelId] as AppContext;

                    // Process any messages that have been enqueued by the receive completion handler.
                    bool result = AppContext.messageQueue.TryDequeue(out messageReceived);
                    if (result)
                    {
                        Diag.DebugPrint("Message: " + messageReceived);
                        InvokeSimpleToast(messageReceived);
                    }
                    else
                    {
                        Diag.DebugPrint("There was no message for this push notification: ");
                    }
                }
                catch (Exception exp)
                {
                    Diag.DebugPrint("PushNotifyTask failed with: " + exp.Message);
                }
            }
            else
            {
                Diag.DebugPrint("Cannot find AppContext key " + channelId);
            }

            Diag.DebugPrint("PushNotifyTask " + taskInstance.Task.Name + " finished.");
        }
示例#2
0
        protected override async void OnRun(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            //Config.Initialize();

            //if (Web.IsLanAvailable() && !AppFields.UpdateAvailable)
            //{
            //    var checkResult = await UpdateMonitor.CheckUpdate();
            //    if (checkResult == UpdateMonitor.Result.Found)
            //    {
            //        sendUpdateToastNotification();
            //    }
            //}

            //var tiles = await SecondaryTile.FindAllAsync();
            //if (tiles.Any())
            //{
            //    using (var TB = new TransitBaseComponent(
            //        root: App.Services.FileSystem.GetAppStorageRoot(),
            //        preLoad: false,
            //        bigTableLimit: Config.Current.BigTableLimit,
            //        checkSameRoutes: Config.Current.CheckSameRoutes,
            //        latitudeDegreeDistance: Config.Current.LatitudeDegreeDistance,
            //        longitudeDegreeDistance: Config.Current.LongitudeDegreeDistance
            //        ))
            //    {
            //        foreach (var tile in tiles)
            //        {
            //            var arg = tile.Arguments.Split('-');
            //            Route route = TB.Logic.GetRouteByID(int.Parse(arg[0]));
            //            StopGroup stop = TB.Logic.GetStopGroupByID(int.Parse(arg[1]));
            //            await AppTileUpdater.UpdateTile(route, stop, tile: tile, doFlush: true);
            //            TB.Flush();
            //        }
            //    }
            //}

            deferral.Complete();
        }