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

            var location  = GeoWatcher.Location;
            var waypoints = GeoDataService.FindNearestExitTollPoints(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.OnTollRoad));
            }
            else
            {
                foreach (var item in WaypointChecker.TollPointsInRadius)
                {
                    Log.LogMessage($"FOUNDED WAYPOINT : {item.Name}, DISTANCE {item.Distance}");
                }

                GeoWatcher.StartUpdatingHighAccuracyLocation();

                return(Task.FromResult(TollGeolocationStatus.NearTollRoadExit));
            }
        }
        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);
            }
        }