Пример #1
0
        public override bool TestHealth(ref string error, ref string warning, ref string misc)
        {
            bool restart = base.TestHealth(ref error, ref warning, ref misc);

            if (Running)
            {
#if __IOS__
                // on ios we do significant-change polling, which can override scheduled polls. don't check for polling delays if the scheduled polls are overridden.
                if (_significantChangePoll && _significantChangePollOverridesScheduledPolls)
                {
                    return(restart);
                }
#endif

                double msElapsedSincePreviousStore = (DateTimeOffset.UtcNow - MostRecentStoreTimestamp.GetValueOrDefault(DateTimeOffset.MinValue)).TotalMilliseconds;
                int    allowedLagMS = 5000;
                if (!_isPolling &&
                    _pollingSleepDurationMS <= int.MaxValue - allowedLagMS &&               // some probes (iOS HealthKit) have polling delays set to int.MaxValue. if we add to this (as we're about to do in the next check), we'll wrap around to 0 resulting in incorrect statuses. only do the check if we won't wrap around.
                    msElapsedSincePreviousStore > (_pollingSleepDurationMS + allowedLagMS)) // system timer callbacks aren't always fired exactly as scheduled, resulting in health tests that identify warning conditions for delayed polling. allow a small fudge factor to ignore these warnings.
                {
                    warning += "Probe \"" + GetType().FullName + "\" has not stored data in " + msElapsedSincePreviousStore + "ms (polling delay = " + _pollingSleepDurationMS + "ms)." + Environment.NewLine;
                }
            }

            return(restart);
        }
Пример #2
0
        public override bool TestHealth(ref List <Tuple <string, Dictionary <string, string> > > events)
        {
            bool restart = base.TestHealth(ref events);

            if (Running)
            {
#if __IOS__
                // on ios we do significant-change polling, which can override scheduled polls. don't check for polling delays if the scheduled polls are overridden.
                if (_significantChangePoll && _significantChangePollOverridesScheduledPolls)
                {
                    return(restart);
                }
#endif

                TimeSpan timeElapsedSincePreviousStore = DateTimeOffset.UtcNow - MostRecentStoreTimestamp.GetValueOrDefault(DateTimeOffset.MinValue);
                int      allowedLagMS = 5000;
                if (!_isPolling &&                                                                               // don't raise a warning if the probe is currently trying to poll
                    _pollingSleepDurationMS <= int.MaxValue - allowedLagMS &&                                    // some probes (iOS HealthKit for age) have polling delays set to int.MaxValue. if we add to this (as we're about to do in the next check), we'll wrap around to 0 resulting in incorrect statuses. only do the check if we won't wrap around.
                    timeElapsedSincePreviousStore.TotalMilliseconds > (_pollingSleepDurationMS + allowedLagMS))  // system timer callbacks aren't always fired exactly as scheduled, resulting in health tests that identify warning conditions for delayed polling. allow a small fudge factor to ignore these warnings.
                {
                    string eventName = TrackedEvent.Warning + ":" + GetType().Name;
                    Dictionary <string, string> properties = new Dictionary <string, string>
                    {
                        { "Polling Latency", (timeElapsedSincePreviousStore.TotalMilliseconds - _pollingSleepDurationMS).Round(1000).ToString() }
                    };

                    Analytics.TrackEvent(eventName, properties);

                    events.Add(new Tuple <string, Dictionary <string, string> >(eventName, properties));
                }

                if (!SensusContext.Current.CallbackScheduler.ContainsCallback(_pollCallback))
                {
                    string eventName = TrackedEvent.Error + ":" + GetType().Name;
                    Dictionary <string, string> properties = new Dictionary <string, string>
                    {
                        { "Missing Callback", _pollCallback.Id }
                    };

                    Analytics.TrackEvent(eventName, properties);

                    events.Add(new Tuple <string, Dictionary <string, string> >(eventName, properties));

                    restart = true;
                }
            }

            return(restart);
        }