Exemplo n.º 1
0
        protected async virtual Task CheckTrackStatusAsync()
        {
            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}");

                var checkResult = await StatusesFactory.GetStatus(TollGeolocationStatus.SearchingNearestTollPoint)
                                  .CheckStatus(new TollGeoStatusResult()
                {
                    TollGeolocationStatus = statusBeforeCheck
                });                                                                                                                          //await statusObject.CheckStatus(statusBeforeCheck);

                TollStatus = checkResult.TollGeolocationStatus;

                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();
            }
        }