public static BaseStatus GetStatus(TollGeolocationStatus status) { BaseStatus statusObject = null; if (_pool.TryGetValue(status, out statusObject)) { return(statusObject); } return(null); }
public async Task CheckAreWeStillOnTheRoadAsync() { if (waypointChecker.TollPoint != null) { Debug.WriteLine(waypointChecker.TollPoint.Name); BaseStatus statusObject = StatusesFactory.GetStatus(TollStatus); _textToSpeech.IsEnabled = true; switch (_storedSettingsService.CurrentRoadStatus) { case TollGeolocationStatus.NearTollRoadEntrance: case TollGeolocationStatus.NotOnTollRoad: break; case TollGeolocationStatus.NearTollRoadExit: case TollGeolocationStatus.OnTollRoad: if (await statusObject.SpeechToTextService.AskQuestionAsync($"Are you still going from {waypointChecker.TollPoint.Name} tollroad?")) { waypointChecker.SetEntrance(waypointChecker.TollPoint); if (waypointChecker.TollPoint.WaypointAction == WaypointAction.Bridge) { waypointChecker.SetExit(waypointChecker.TollPoint); waypointChecker.SetTollPointsInRadius(null); waypointChecker.ClearData(); TollStatus = Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus == TollGeolocationStatus.OnTollRoad ? Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus : TollGeolocationStatus.NotOnTollRoad; } else { TollStatus = TollGeolocationStatus.OnTollRoad; } } else { TollStatus = TollGeolocationStatus.NotOnTollRoad; Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus = TollStatus; } break; } } }
protected Task <TollGeoStatusResult> CheckNearestPoint(TollGeolocationStatus tollGeoStatus, List <TollPointWithDistance> tollPoints = null) { var location = GeoWatcher.Location; var nearestWaypoints = GeoDataService.FindNearestTollPoints(location); if (nearestWaypoints?.Count == 0) { #if REALEASE GeoWatcher.StopUpdatingHighAccuracyLocation(); #endif Log.LogMessage($"No waypoint founded for location {GeoWatcher.Location}"); SetTollStatusWithDistance(location, Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus == TollGeolocationStatus.OnTollRoad ? Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus : TollGeolocationStatus.NotOnTollRoad); shouldContinueCheckStatus = false; return(Task.FromResult(new TollGeoStatusResult() { TollPointWithDistance = null, Location = location, TollGeolocationStatus = tollGeolocationStatus, IsNeedToDoubleCheck = shouldContinueCheckStatus })); } WaypointChecker.SetTollPointsInRadius(nearestWaypoints); WaypointChecker.SetIgnoredChoiceTollPoint(null); var tollPointInRadius = WaypointChecker.TollPointsInRadius[firstElement]; foreach (var item in WaypointChecker.TollPointsInRadius) { Log.LogMessage($"FOUNDED WAYPOINT : {item.Name}, DISTANCE {item.Distance}"); } #if REALEASE GeoWatcher.StartUpdatingHighAccuracyLocation(); #endif switch (tollPointInRadius.WaypointAction) { case WaypointAction.Entrance: if (tollGeoStatus == TollGeolocationStatus.OnTollRoad) { tollGeolocationStatus = TollGeolocationStatus.OnTollRoad; shouldContinueCheckStatus = false; } else if (Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus == TollGeolocationStatus.NotOnTollRoad || Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus == TollGeolocationStatus.SearchingNearestTollPoint) { SetTollStatusWithDistance(location, TollGeolocationStatus.NearTollRoadEntrance); } break; case WaypointAction.Bridge: SetTollStatusWithDistance(location, TollGeolocationStatus.NearTollRoadEntrance); break; case WaypointAction.Exit: if (Mvx.Resolve <IStoredSettingsService>().CurrentRoadStatus == TollGeolocationStatus.OnTollRoad) { SetTollStatusWithDistance(location, TollGeolocationStatus.NearTollRoadExit); } else { tollGeolocationStatus = tollGeoStatus; shouldContinueCheckStatus = false; } break; } return(Task.FromResult(new TollGeoStatusResult() { TollPointWithDistance = tollPointInRadius, Location = location, TollGeolocationStatus = tollGeolocationStatus, IsNeedToDoubleCheck = shouldContinueCheckStatus })); }
private void SetTollStatusWithDistance(GeoLocation location, TollGeolocationStatus tollStatus) { WaypointChecker.DetectWeAreInsideSomeTollPoint(location); tollGeolocationStatus = tollStatus; shouldContinueCheckStatus = true; }
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(); } }