Пример #1
0
        /// <summary>
        /// Start up the phone home service.
        /// </summary>
        internal static void Startup()
        {
            lock (_sync)
            {
                OnStartUp();

                _phoneHomeTimer = new Timer(ignore =>
                {
                    var type    = _sentStartUpMessage ? UsageType.Other : UsageType.Startup;
                    var msg     = CreateUsageMessage(type);
                    msg.AppData = new List <UsageApplicationData>();
                    msg.AppData.AddRange(UsageUtilities.GetApplicationData(type));
                    UsageUtilities.Register(msg, UsageTrackingThread.Background);

                    _sentStartUpMessage = true;
                },
                                            null,
                                            _startupCallDelay,
                                            _periodicCallInterval);
            }
        }
Пример #2
0
        private static void SendShutdownMessage()
        {
            const string keyProcessUptime = "PROCESSUPTIME";

            try
            {
                TimeSpan uptime = DateTime.Now - _startTimestamp;

                var msg = CreateUsageMessage(UsageType.Shutdown);
                msg.AppData = new List <UsageApplicationData>();
                msg.AppData.AddRange(UsageUtilities.GetApplicationData(UsageType.Shutdown));
                msg.AppData.Add(new UsageApplicationData {
                    Key = keyProcessUptime, Value = String.Format(CultureInfo.InvariantCulture, "{0}", uptime.TotalHours)
                });

                // Message must be sent using the current thread instead of threadpool when the app is being shut down
                UsageUtilities.Register(msg, UsageTrackingThread.Current);
            }
            catch (Exception ex)
            {
                // Requirement says log must be in debug
                Platform.Log(LogLevel.Debug, ex, "Error occurred when shutting down phone home service");
            }
        }