Example #1
0
        protected async virtual Task CheckTrackStatus()
        {
            Log.LogMessage("Track status is cheking...");

            if (_locationProcessing)
            {
                Log.LogMessage("Ignore location in FACADE because location processing");
                return;
            }

            await _semaphor.WaitAsync();

            if (_locationProcessing)
            {
                return;
            }

            _locationProcessing = true;

            try
            {
                BaseStatus statusObject = StatusesFactory.GetStatus(TollStatus);

                //if (_activity.MotionType == MotionType.Still)
                //{
                //    Log.LogMessage("Ignore location in FACADE because we are still");
                //    return;
                //}
                //else
                //{
                //    if (statusObject.CheckBatteryDrain())
                //    {
                //        Log.LogMessage("Ignore location in FACADE because we are too away from nearest waypoint");
                //        return;
                //    }
                //}

                var statusBeforeCheck = TollStatus;
                Log.LogMessage($"Current status before check= {TollStatus}");

                TollStatus = await statusObject.CheckStatus();

                statusObject = StatusesFactory.GetStatus(TollStatus);

                Log.LogMessage($"Current status after check = {TollStatus}");
                if (statusBeforeCheck != TollStatus)
                {
                    Mvx.Resolve <INotificationSender>().SendLocalNotification($"Status: {TollStatus.ToString()}", $"Lat: {_geoWatcher.Location?.Latitude}, Long: {_geoWatcher.Location?.Longitude}");
                }
            }
            catch (Exception e)
            {
                Insights.Report(e);
                Log.LogMessage(e.Message + e.StackTrace);
            }
            finally
            {
                _locationProcessing = false;
                _semaphor.Release();
            }
        }