Пример #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);
            }
        }