Esempio n. 1
0
        /// <summary>
        /// Find a route sequence to reach the destination block from the specified block.
        /// </summary>
        /// <param name="itinerary">Planned itinerary.</param>
        /// <returns>A value indicating if the itinerary can be completed (a valid route could be found).</returns>
        /// <remarks>The instance of <see cref="Itinerary"/> will be updated with all routes to follow to complete the itinerary.</remarks>
        public bool FindItinerary(Itinerary itinerary)
        {
            Logger.LogDebug(this, "[CLASS].FindItinerary([{0}])", itinerary);

            itinerary.PendingRoutes = this.FindItineraryRoutes(itinerary.FromBlock, itinerary.ToBlock);
            if (itinerary.PendingRoutes != null && itinerary.PendingRoutes.Count > 0)
            {
                itinerary.PendingRoutes.Reverse();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add a new <see cref="Itinerary"/> to be managed by traffic manager.
        /// </summary>
        /// <param name="itinerary">Planned itinerary.</param>
        /// <param name="automaticRun">A value indicating if the <paramref name="itinerary"/> will be activated automatically after adding the new itinerary.</param>
        /// <remarks>The instance of <see cref="Itinerary"/> will be updated with all routes to follow to complete the itinerary.</remarks>
        public void AddItinerary(Itinerary itinerary, bool automaticRun = true)
        {
            Logger.LogDebug(this, "[CLASS].AddItinerary([{0}])", itinerary);

            // Initialize the itinerary
            itinerary.SetItinerary(this.FindItineraryRoutes(itinerary.FromBlock, itinerary.ToBlock));

            // Add the itinerary to the traffic manager
            TrafficManager.ActiveItineraries.Add(itinerary);

            // Run the itinerary
            if (automaticRun)
            {
                itinerary.Run();
            }

            this.TrafficStatusChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 3
0
        /// <summary>
        /// Stop and remove the specified itinerary from the traffic manager.
        /// </summary>
        /// <param name="itinerary">Itinerary to remove.</param>
        public void RemoveItinerary(Itinerary itinerary)
        {
            Logger.LogDebug(this, "[CLASS].RemoveItinerary([{0}])", itinerary);

            if (TrafficManager.ActiveItineraries.Contains(itinerary))
            {
                // Deactivate all routes uded
                if (itinerary.Enabled)
                {
                    foreach (Route route in itinerary.PendingRoutes)
                    {
                        if (route.IsActive)
                        {
                            route.Deactivate();
                        }
                    }
                }

                // Remove the itinerary from the current itineraries queue
                TrafficManager.ActiveItineraries.Remove(itinerary);
                this.TrafficStatusChanged?.Invoke(this, new EventArgs());
            }
        }