/// <summary>
        /// Returns the global instance of the PebbleConnector class
        /// </summary>
        /// <returns></returns>
        public static PaceHandler GetInstance()
        {
            if (_paceHandler == null)
            {
                _paceHandler = new PaceHandler();
            }

            return(_paceHandler);
        }
示例#2
0
        /// <summary>
        /// Pace handler
        /// </summary>
        /// <returns></returns>
        private async Task PaceHandler()
        {
            //initialise settings
            var localSettings   = ApplicationData.Current.LocalSettings;
            var roamingSettings = ApplicationData.Current.RoamingSettings;

            if (localSettings.Values.Keys.Contains(Constants.BackgroundPace) &&
                (bool)localSettings.Values[Constants.BackgroundPace])
            {
                if (!PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Pace))
                {
                    await PaceHandlerCleanup();
                }
                else
                {
                    if (_PaceHandler == null)
                    {
                        localSettings.Values[Constants.PaceSwitchPaused] = false;
                        localSettings.Values[Constants.PaceGPX]          = false;
                        if (localSettings.Values.Keys.Contains(Constants.Miles))
                        {
                            localSettings.Values[Constants.Miles] = localSettings.Values[Constants.Miles];
                        }
                        else
                        {
                            localSettings.Values[Constants.Miles] = !System.Globalization.RegionInfo.CurrentRegion.IsMetric;
                        }
                        localSettings.Values[Constants.BackgroundCommunicatieIsRunning] = true;

                        //initialise pace handler
                        _PaceHandler       = new Pebble_Time_Manager.Connector.PaceHandler();
                        _PaceHandler.Miles = (bool)localSettings.Values[Constants.Miles];
                        _PaceHandler.Start();
                        await _PaceHandler.UpdatePosition();
                    }

                    //Update pace
                    _PaceHandler.UpdatePosition();

                    if (!_PaceHandler.Paused)
                    {
                        //Send Pebble Message
                        await _PaceHandler.SendPebblePaceMessage();

                        localSettings.Values[Constants.PaceDistance] = string.Format("{0:f2}", _PaceHandler.Distance);
                        localSettings.Values[Constants.PaceDuration] = _PaceHandler.Duration.ToString(@"m\:ss");
                        localSettings.Values[Constants.PacePace]     = _PaceHandler.Pace.ToString(@"m\:ss");
                        if (_PaceHandler.Pace.TotalMinutes > 45)
                        {
                            localSettings.Values[Constants.PacePace] = "-";
                        }
                        if (_PaceHandler.Pace.TotalMilliseconds == 0)
                        {
                            localSettings.Values[Constants.PacePace] = "-";
                        }
                    }

                    localSettings.Values[Constants.PacePaused] = _PaceHandler.Paused;

                    //Check the switch pause/resume
                    if (localSettings.Values.Keys.Contains(Constants.PaceSwitchPaused))
                    {
                        bool SwitchPaused = (bool)localSettings.Values[Constants.PaceSwitchPaused];
                        localSettings.Values[Constants.PaceSwitchPaused] = false;
                        if (SwitchPaused)
                        {
                            if (_PaceHandler.Paused)
                            {
                                await _PaceHandler.Resume();
                            }
                            else
                            {
                                await _PaceHandler.Pause();
                            }
                        }
                    }
                }
            }
        }