Beispiel #1
0
        /// <summary>
        /// Updates the callbacks when the app is activated. This services any callbacks that should have already been
        /// serviced or will be serviced in the near future. This also reissues all silent notifications, which would
        /// have been canceled when the app went into the background.
        /// </summary>
        /// <returns>Async task.</returns>
        public async Task UpdateCallbacksOnActivationAsync()
        {
            foreach (string callbackId in CallbackIds)
            {
                ScheduledCallback callback = TryGetCallback(callbackId);

                if (callback == null)
                {
                    continue;
                }

                // service any callback that should have already been serviced or will soon be serviced
                if (callback.NextExecution.Value < DateTime.Now + CALLBACK_NOTIFICATION_HORIZON_THRESHOLD)
                {
                    iOSNotifier notifier = SensusContext.Current.Notifier as iOSNotifier;
                    notifier.CancelNotification(callback.Id);
                    await RaiseCallbackAsync(callback, callback.InvocationId);
                }
                // all silent notifications (e.g., those for health tests) were cancelled when the app entered background. reissue them now.
                // if the notification has already been issued, it will simply be replaced with itself (no change).
                else if (callback.Silent)
                {
                    await ReissueSilentNotificationAsync(callback.Id);
                }
                else
                {
                    SensusServiceHelper.Get().Logger.Log("Non-silent callback notification " + callback.Id + " has upcoming trigger time of " + callback.NextExecution, LoggingLevel.Normal, GetType());
                }
            }
        }
        /// <summary>
        /// Updates the callbacks when the app is activated. This services any callbacks that should have already been
        /// serviced or will be serviced in the near future. This also reissues all silent notifications, which would
        /// have been canceled when the app went into the background.
        /// </summary>
        /// <returns>Async task.</returns>
        public async Task UpdateCallbacksOnActivationAsync()
        {
            IEnumerable <ScheduledCallback> callbacks = CallbackIds
                                                        .Select(x => TryGetCallback(x))
                                                        .Where(x => x != null)
                                                        .OrderBy(x => x.Priority);

            foreach (ScheduledCallback callback in callbacks)
            {
                //ScheduledCallback callback = TryGetCallback(callbackId);

                if (callback == null)
                {
                    continue;
                }

                // service any callback that should have already been serviced or will soon be serviced
                if (callback.NextExecution.Value < DateTime.Now + CALLBACK_NOTIFICATION_HORIZON_THRESHOLD)
                {
                    iOSNotifier notifier = SensusContext.Current.Notifier as iOSNotifier;
                    notifier.CancelNotification(callback.Id);
                    await RaiseCallbackAsync(callback, callback.InvocationId);
                }
                else
                {
                    SensusServiceHelper.Get().Logger.Log("Non-silent callback notification " + callback.Id + " has upcoming trigger time of " + callback.NextExecution, LoggingLevel.Normal, GetType());
                }
            }
        }