Esempio n. 1
0
        public override Task <TollGeolocationStatus> CheckStatus()
        {
            Log.LogMessage(string.Format($"TRY TO FIND TOLLPOINT ENTRANCES FROM {SettingsService.WaypointLargeRadius * 1000} m"));

            var location  = GeoWatcher.Location;
            var waypoints = GeoDataService.FindNearestEntranceTollPoints(location);

            WaypointChecker.SetTollPointsInRadius(waypoints);
            WaypointChecker.SetIgnoredChoiceTollPoint(null);

            if (waypoints.Count == 0)
            {
                GeoWatcher.StopUpdatingHighAccuracyLocation();
                Log.LogMessage($"No waypoint founded for location {GeoWatcher.Location}");
                return(Task.FromResult(TollGeolocationStatus.NotOnTollRoad));
            }
            else
            {
                foreach (var item in WaypointChecker.TollPointsInRadius)
                {
                    Log.LogMessage($"FOUNDED WAYPOINT : {item.Name}, DISTANCE {item.Distance}");
                }

                GeoWatcher.StartUpdatingHighAccuracyLocation();

                return(Task.FromResult(TollGeolocationStatus.NearTollRoadEntrance));
            }
        }
        public async override Task <TollGeolocationStatus> CheckStatus()
        {
            var location  = GeoWatcher.Location;
            var waypoints = GeoDataService.FindNearestEntranceTollPoints(location);

            WaypointChecker.SetTollPointsInRadius(waypoints);

            if (waypoints.Count == 0)
            {
                return(TollGeolocationStatus.NotOnTollRoad);
            }

            var insideTollPoint = WaypointChecker.DetectWeAreInsideSomeTollPoint(location);

            if (insideTollPoint != null)
            {
                double radius = insideTollPoint.Radius != 0 ? insideTollPoint.Radius / 1000 : SettingsService.WaypointSmallRadius * 1000;
                Log.LogMessage($"We are inside tollpoint {radius} radius");

                WaypointChecker.SetIgnoredChoiceTollPoint(insideTollPoint);

                if (WaypointChecker.TollPointsInRadius.Count == 1)
                {
                    GeoWatcher.StopUpdatingHighAccuracyLocation();
                }

                if (await SpeechToTextService.AskQuestion($"Are you entering {insideTollPoint.Name} tollroad?"))
                {
                    WaypointChecker.SetEntrance(insideTollPoint);

                    if (insideTollPoint.WaypointAction == WaypointAction.Bridge)
                    {
                        WaypointChecker.SetExit(insideTollPoint);

                        WaypointChecker.SetTollPointsInRadius(null);
                        await NotifyService.Notify("Bill was created");

                        WaypointChecker.ClearData();
                        return(TollGeolocationStatus.NotOnTollRoad);
                    }
                    else
                    {
                        return(TollGeolocationStatus.OnTollRoad);
                    }
                }
                else
                {
                    return(TollGeolocationStatus.NotOnTollRoad);
                }
            }
            else
            {
                return(TollGeolocationStatus.NearTollRoadEntrance);
            }
        }
Esempio n. 3
0
        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
            }));
        }
Esempio n. 4
0
        public override bool CheckBatteryDrain()
        {
            var distance = DistanceChecker.GetMostClosestTollPoint(GeoWatcher.Location, GeoDataService.GetAllEntranceTollPoints()).FirstOrDefault()?.Distance ?? 0;

            return(BatteryDrainService.CheckGpsTrackingSleepTime(distance));
        }
        public override async Task <TollGeolocationStatus> CheckStatus()
        {
            var location  = GeoWatcher.Location;
            var waypoints = GeoDataService.FindNearestExitTollPoints(location);

            WaypointChecker.SetTollPointsInRadius(waypoints);

            if (waypoints.Count == 0)
            {
                return(TollGeolocationStatus.OnTollRoad);
            }

            var insideTollPoint = WaypointChecker.DetectWeAreInsideSomeTollPoint(location);

            if (insideTollPoint != null)
            {
                double radius = insideTollPoint.Radius != 0 ? insideTollPoint.Radius / 1000 : SettingsService.WaypointSmallRadius * 1000;
                Log.LogMessage($"We are inside tollpoint {radius} radius");

                WaypointChecker.SetIgnoredChoiceTollPoint(insideTollPoint);

                if (WaypointChecker.TollPointsInRadius.Count == 1)
                {
                    GeoWatcher.StopUpdatingHighAccuracyLocation();
                }

                if (await SpeechToTextService.AskQuestion($"Are you exiting from {insideTollPoint.Name} tollroad?"))
                {
                    WaypointChecker.SetExit(insideTollPoint);
                    WaypointChecker.SetTollPointsInRadius(null);
                    WaypointChecker.SetIgnoredChoiceTollPoint(null);

                    if (WaypointChecker.Exit != null)
                    {
                        await NotifyService.Notify("Bill was created");

                        var duration = WaypointChecker.TripDuration;

                        if (duration.Hours > 0)
                        {
                            await NotifyService.Notify($"Trip duration is {duration.Hours} hours {duration.Minutes} minutes {duration.Seconds} seconds");
                        }
                        else
                        {
                            await NotifyService.Notify($"Trip duration is {duration.Minutes} minutes {duration.Seconds} seconds");
                        }

                        WaypointChecker.ClearData();
                    }
                    else
                    {
                        await NotifyService.Notify("Bill was not created. You didn't enter any exit");
                    }

                    return(TollGeolocationStatus.NotOnTollRoad);
                }
                else
                {
                    return(TollGeolocationStatus.OnTollRoad);
                }
            }
            else
            {
                return(TollGeolocationStatus.NearTollRoadExit);
            }
        }