コード例 #1
0
        public ActionResult <PlannedTour> Get([FromBody] PlanTourParameters planTourParameters)
        {
            this.logger.LogDebug($"Planning tour with {planTourParameters.WaypointIdList.Count} waypoints...");

            var watch = new Stopwatch();

            watch.Start();

            try
            {
                var result = this.engine.PlanTour(planTourParameters);
                return(result);
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Exception while planning tour");

                return(this.BadRequest(ex.Message));
            }
            finally
            {
                watch.Stop();

                this.logger.LogDebug($"Planning tour took {watch.ElapsedMilliseconds} ms.");
            }
        }
コード例 #2
0
        public void TestPlanTour_TwoPoints()
        {
            // set up
            var engine = new PlanTourEngine();

            engine.LoadGraph(GetPlanTourKmlStream());

            // run
            var planTourParameters = new PlanTourParameters
            {
                WaypointIdList = new List <string>
                {
                    "wheretofly-path-bahnhof-neuhaus",
                    "wheretofly-path-rauhkopf",
                }
            };

            var tour = engine.PlanTour(planTourParameters);

            // check
            Assert.IsTrue(tour.Description.Any(), "description must contain text");
            Assert.IsTrue(tour.TotalDuration.TotalMinutes > 0, "total duration must contain value");
            Assert.IsTrue(tour.TourEntriesList.Any(), "tour entries list must be filled");
            Assert.IsTrue(tour.MapPointList.Any(), "map point list must be filled");
        }
コード例 #3
0
        /// <summary>
        /// Plans a tour with given waypoints
        /// </summary>
        /// <param name="planTourParameters">tour planning parameters</param>
        /// <returns>planned tour</returns>
        public PlannedTour PlanTour(PlanTourParameters planTourParameters)
        {
            this.CheckTourPlanningArguments(planTourParameters);

            var vertexList = (from waypointId in planTourParameters.WaypointIdList
                              select this.FindWaypointInfo(waypointId)).ToList();

            var tour            = new PlannedTour();
            var descriptionText = new StringBuilder();
            var totalDuration   = TimeSpan.Zero;

            for (int index = 1; index < vertexList.Count; index++)
            {
                var source = vertexList[index - 1];
                var target = vertexList[index];

                this.PlanSingleTourStep(source, target, tour, descriptionText, ref totalDuration);

                if (index + 1 == vertexList.Count)
                {
                    descriptionText.Append($"Ende-Wegpunkt: {target.Description}\n");
                }
            }

            tour.Description   = descriptionText.ToString();
            tour.TotalDuration = totalDuration;

            return(tour);
        }
コード例 #4
0
        /// <summary>
        /// Plans tour using network service and shows activity indicator while planning. When an
        /// error occured, a message is shown and no tour is returned.
        /// </summary>
        /// <param name="planTourParameters">parameters for planning tour</param>
        /// <returns>planned tour, or null on planning errors</returns>
        private async Task <Tour> PlanTourAsync(PlanTourParameters planTourParameters)
        {
            var networkService = DependencyService.Get <INetworkService>();

            try
            {
                this.IsPlanningActive = true;

                var plannedTour = await networkService.PlanTourAsync(planTourParameters, CancellationToken.None);

                return(plannedTour);
            }
            catch (Exception ex)
            {
                log.Error("error while planning tour", ex);

                this.IsPlanningActive = false;

                MessagingCenter.Send(
                    this,
                    "DisplayAlert",
                    "Error while planning tour!");
            }
            finally
            {
                this.IsPlanningActive = false;
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Creates a new popup page object
        /// </summary>
        /// <param name="planTourParameters">tour planning parameters</param>
        public PlanTourPopupPage(PlanTourParameters planTourParameters)
        {
            this.CloseWhenBackgroundIsClicked = true;

            this.InitializeComponent();

            this.BindingContext = new PlanTourPopupViewModel(planTourParameters, this.ClosePopupPage);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new view model object for "plan tour" view.
        /// </summary>
        public PlanTourViewModel()
        {
            this.isStartLocationRequiredVisible = false;
            this.isTourLocationRequiredVisible  = false;

            this.isPlanningActive   = false;
            this.PlanTourParameters = new PlanTourParameters();

            this.SetupBindings();
        }
コード例 #7
0
        /// <summary>
        /// Plans a tour with given parameters and returns planned tour; may throw exception when
        /// no tour could be planned with the given parameters. Using demo data, only returning
        /// tours with parameters that match a pre-planned tour.
        /// </summary>
        /// <param name="planTourParams">parameters to plan tour</param>
        /// <param name="token">token to cancel operation</param>
        /// <returns>planned tour</returns>
        public async Task <Tour> PlanTourAsync(PlanTourParameters planTourParams, CancellationToken token)
        {
            var prePlannedTourList = DemoData.DataProvider.FindPrePlannedTourList(planTourParams);

            if (prePlannedTourList != null)
            {
                return(await Task.FromResult(prePlannedTourList.Tour));
            }

            throw new System.Exception("Tour couldn't be calculated");
        }
コード例 #8
0
        public Tour Get([FromBody] PlanTourParameters planTourParams)
        {
            var prePlannedTourList = HikingPathFinder.DemoData.DataProvider.FindPrePlannedTourList(planTourParams);

            if (prePlannedTourList != null)
            {
                return(prePlannedTourList.Tour);
            }

            throw new System.Exception("Tour couldn't be calculated");
        }
コード例 #9
0
        /// <summary>
        /// Plans a tour with given parameters and returns planned tour; may throw exception when
        /// no tour could be planned with the given parameters.
        /// </summary>
        /// <param name="planTourParams">parameters to plan tour</param>
        /// <param name="cancellationToken">token to cancel operation</param>
        /// <returns>planned tour</returns>
        public async Task <Tour> PlanTourAsync(PlanTourParameters planTourParams, CancellationToken cancellationToken)
        {
            string parameter = JsonConvert.SerializeObject(planTourParams);

            Tour result = await this.SendRequestAsync <Tour>(
                "api/planTour",
                HttpMethod.Get,
                parameter,
                cancellationToken);

            return(result);
        }
コード例 #10
0
        public PlannedTour Get([FromBody] PlanTourParameters planTourParameters)
        {
            this.logger.LogDebug($"Planning tour with {planTourParameters.WaypointIdList.Count} waypoints...");

            var watch = new Stopwatch();

            watch.Start();

            var result = this.engine.PlanTour(planTourParameters);

            watch.Stop();

            this.logger.LogDebug($"Planning tour took {watch.ElapsedMilliseconds} ms.");

            return(result);
        }
コード例 #11
0
        public void TestPlanTour_GrandTour()
        {
            // set up
            var engine = new PlanTourEngine();

            engine.LoadGraph(GetPlanTourKmlStream());

            // run
            var planTourParameters = new PlanTourParameters
            {
                WaypointIdList = new List <string>
                {
                    "wheretofly-path-bahnhof-neuhaus",
                    "wheretofly-path-spitzingsattel",
                    "wheretofly-path-jagerkamp",
                    ////"wheretofly-path-benzingspitz",
                    "wheretofly-path-tanzeck",
                    "wheretofly-path-aiplspitz",
                    "wheretofly-path-rauhkopf",
                    "wheretofly-path-taubensteinhaus",
                    "wheretofly-path-hochmiesing",
                    "wheretofly-path-rotwand",
                    "wheretofly-path-rotwandhaus",
                    "wheretofly-path-lempersberg",
                    "wheretofly-path-taubenstein",
                    ////"wheretofly-path-albert-link-haus",
                    ////"wheretofly-path-stolzenberg",
                    ////"wheretofly-path-rotkopf",
                    ////"wheretofly-path-rosskopf",
                    ////"wheretofly-path-stuempfling",
                    ////"wheretofly-path-bodenschneid",
                    ////"wheretofly-path-brecherspitz",
                    "wheretofly-path-bahnhof-neuhaus",
                }
            };

            var tour = engine.PlanTour(planTourParameters);

            // check
            Assert.IsTrue(tour.Description.Any(), "description must contain text");
            Assert.IsTrue(tour.TotalDuration.TotalMinutes > 0, "total duration must contain value");
            Assert.IsTrue(tour.TourEntriesList.Any(), "tour entries list must be filled");
            Assert.IsTrue(tour.MapPointList.Any(), "map point list must be filled");
        }
コード例 #12
0
        public void TestPlanTour_OnePoint()
        {
            // set up
            var engine = new PlanTourEngine();

            engine.LoadGraph(GetPlanTourKmlStream());

            // run
            var planTourParameters = new PlanTourParameters
            {
                WaypointIdList = new List <string>
                {
                    "wheretofly-path-bahnhof-neuhaus",
                }
            };

            Assert.ThrowsException <InvalidOperationException>(
                () => engine.PlanTour(planTourParameters));
        }
コード例 #13
0
        /// <summary>
        /// Checks all tour planning arguments for validity
        /// </summary>
        /// <param name="planTourParameters">tour planning parameters</param>
        private void CheckTourPlanningArguments(PlanTourParameters planTourParameters)
        {
            if (planTourParameters == null)
            {
                throw new ArgumentNullException(nameof(planTourParameters));
            }

            if (planTourParameters.WaypointIdList.Count < 2)
            {
                throw new InvalidOperationException("there must be at least two waypoints for tour planning");
            }

            // check if one of the waypoints can't be found
            string invalidWaypointId = planTourParameters.WaypointIdList.FirstOrDefault(
                waypointId => this.FindWaypointInfo(waypointId) == null);

            if (invalidWaypointId != null)
            {
                throw new ArgumentException($"invalid waypoint id for tour planning: {invalidWaypointId}");
            }
        }
コード例 #14
0
        /// <summary>
        /// Finds pre-planned tour from given plan tour parameters
        /// </summary>
        /// <param name="planTourParams">plan tour params</param>
        /// <returns>pre-planned tour, or null when no tour was found</returns>
        public static PrePlannedTour FindPrePlannedTourList(PlanTourParameters planTourParams)
        {
            var prePlannedTourList = DemoData.DataProvider.GetPrePlannedTourList();

            foreach (var prePlannedTour in prePlannedTourList)
            {
                bool startLocationMatches =
                    planTourParams.StartLocation.Id == prePlannedTour.Tour.StartLocation.Id;

                bool endLocationAvailable =
                    planTourParams.EndLocation != null && prePlannedTour.Tour.EndLocation != null;

                bool endLocationMatches =
                    endLocationAvailable &&
                    planTourParams.EndLocation.Id == prePlannedTour.Tour.EndLocation.Id;

                if (startLocationMatches &&
                    (!endLocationAvailable || endLocationMatches))
                {
                    bool hasSameLocations = true;

                    foreach (var locationRef in planTourParams.TourLocationList)
                    {
                        if (prePlannedTour.Tour.LocationList.Find(x => x.Id == locationRef.Id) == null)
                        {
                            hasSameLocations = false;
                            break;
                        }
                    }

                    if (hasSameLocations)
                    {
                        return(prePlannedTour);
                    }
                }
            }

            return(null);
        }
コード例 #15
0
 /// <summary>
 /// Plans a tour with given tour planning parameters and returns the planned tour.
 /// </summary>
 /// <param name="planTourParameters">tour planning parameters</param>
 /// <returns>planned tour</returns>
 public async Task <PlannedTour> PlanTourAsync(PlanTourParameters planTourParameters)
 {
     return(await this.backendDataService.PlanTourAsync(planTourParameters));
 }
コード例 #16
0
 /// <summary>
 /// Plans a tour with given parameters and returns a planned tour, including description
 /// and a track.
 /// </summary>
 /// <param name="planTourParameters">tour planning parameters</param>
 /// <returns>planned tour</returns>
 public async Task <PlannedTour> PlanTourAsync(PlanTourParameters planTourParameters)
 {
     return(await this.backendWebApi.PlanTourAsync(planTourParameters));
 }
コード例 #17
0
 /// <summary>
 /// Creates a new user settings object with default values
 /// </summary>
 public UserSettings()
 {
     this.ShowMapIn3D = false;
     this.CurrentPlanTourParameters = new PlanTourParameters();
 }
コード例 #18
0
        /// <summary>
        /// Shows "Plan tour" popup page and lets the user edit the tour location list.
        /// </summary>
        /// <param name="planTourParameters">tour planning parameters</param>
        /// <returns>task to wait for</returns>
        public static async Task ShowAsync(PlanTourParameters planTourParameters)
        {
            var popupPage = new PlanTourPopupPage(planTourParameters);

            await popupPage.Navigation.PushPopupAsync(popupPage);
        }