Exemplo n.º 1
0
        /// <summary>
        /// The build route settings.
        /// </summary>
        /// <param name="calc">
        /// The calc.
        /// </param>
        /// <param name="fleetToStore">
        /// The fleet to store.
        /// </param>
        /// <param name="storeToClient">
        /// The store to client.
        /// </param>
        /// <param name="distanceToClient">
        /// The distance to client.
        /// </param>
        /// <returns>
        /// The <see cref="RouteSettings"/>.
        /// </returns>
        public static RouteSettings BuildRouteSettings(
            DistanceCalculator calc,
            RouteDistance fleetToStore,
            RouteDistance storeToClient,
            double distanceToClient)
        {
            var result = new RouteSettings();

            result.ClientLocation = storeToClient.LocationToAddress;
            result.StoreLocation  = storeToClient.LocationFromAddress;
            result.DroneLocation  = fleetToStore.LocationFromAddress;

            result.DistanceToClient = distanceToClient;
            result.DroneFlyDistance = result.DistanceToClient + calc.Calculate(
                result.ClientLocation.Coordinates,
                result.DroneLocation.Coordinates);

            result.ClientWaitingTimeSec = (result.DistanceToClient * 1000) / 16.6667d;
            result.DroneFlyTimeSec      = (result.DroneFlyDistance * 1000) / 16.6667d;

            result.ClientWaitingTimeMin = result.ClientWaitingTimeSec / 60;
            result.DroneFlyTimeMin      = result.DroneFlyTimeSec / 60;

            return(result);
        }
 private void CreateDistancesRows(string[] distances, int id)
 {
     for (int i = 0; i < distances.Length; i++)
     {
         RouteDistance routeDistance = new RouteDistance();
         routeDistance.Distance  = distances[i];
         routeDistance.RouteId   = id;
         routeDistance.SortOrder = i;
         _context.Add(routeDistance);
     }
     _context.SaveChanges();
 }
        private string GetRouteInnerXml(IList <TagPositionLog> tracks)
        {
            StringBuilder sb = new StringBuilder();

            if (tracks.Count == 1)
            {
                sb.AppendLine("		<route endTime=\""+ tracks[0].WriteTime.ToString("yyyy/M/d H:mm:ss").Replace("-", "/") + "\">");
                sb.AppendFormat("			<point name=\"{0}\" x=\"{1}\" y=\"{2}\" />\r\n", "", tracks[0].X, tracks[0].Y);
                sb.AppendFormat("			<point name=\"{0}\" x=\"{1}\" y=\"{2}\" />\r\n", "", tracks[0].X, tracks[0].Y);
                sb.AppendLine("		</route>");
                return(sb.ToString());
            }

            using (AppDataContext db = new AppDataContext()) {
                for (int i = 0; i < tracks.Count - 1; i++)
                {
                    //2010-01-11: if there are two tracks, it should have one route. so comment out temporally
                    //if (tracks[i].X == tracks[i + 1].X && tracks[i].Y == tracks[i + 1].Y) {
                    //        continue;
                    //}

                    sb.AppendLine("		<route endTime=\""+ tracks[i + 1].WriteTime.ToString("yyyy/M/d H:mm:ss").Replace("-", "/") + "\">");

                    int location1 = Math.Min(tracks[i].CoordinatesId, tracks[i + 1].CoordinatesId);
                    int location2 = Math.Max(tracks[i].CoordinatesId, tracks[i + 1].CoordinatesId);

                    //MapRoute path = db.MapRoutes.SingleOrDefault(p => p.Endpoint1 == location1 && p.Endpoint2 == location2);
                    MapRoute path = RouteDistance.GetRoutePoints(location1, location2);
                    if (path == null)
                    {
                        sb.AppendFormat("			<point name=\"{0}\" x=\"{1}\" y=\"{2}\" />\r\n", "", tracks[i].X, tracks[i].Y);
                        sb.AppendFormat("			<point name=\"{0}\" x=\"{1}\" y=\"{2}\" />\r\n", "", tracks[i + 1].X, tracks[i + 1].Y);
                    }
                    else
                    {
                        string[] arr = path.CoordinatesArray.Split('|');
                        if (location1 == tracks[i + 1].CoordinatesId)
                        {
                            Array.Reverse(arr);
                        }
                        for (int j = 0; j < arr.Length; j++)
                        {
                            var xy = arr[j].Split(',');
                            sb.AppendFormat("			<point name=\"{0}\" x=\"{1}\" y=\"{2}\" />\r\n", "", xy[0], xy[1]);
                        }
                    }
                    sb.AppendLine("		</route>");
                }
                return(sb.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a logical route that maps to a physical route.
        /// </summary>
        /// <param name="logicalEP">The logical endpoint.</param>
        /// <param name="physicalRoute">The associated physical route.</param>
        internal LogicalRoute(MsgEP logicalEP, PhysicalRoute physicalRoute)
        {
            Assertion.Test(physicalRoute != null);

            if (logicalEP.IsPhysical)
            {
                throw new ArgumentException("Logical endpoint expected.", "logicalEP");
            }

            this.logicalEP     = logicalEP;
            this.physicalRoute = physicalRoute;
            this.targetGroup   = null;
            this.handlers      = null;
            this.marked        = false;
            this.distance      = RouteDistance.Unknown;
        }
Exemplo n.º 5
0
        private RouteDistance distance;                         // Physical distance from the current router
                                                                // (computed when a route is added to a LogicalRouteTable)

        /// <summary>
        /// Constructs a logical route that maps to an application
        /// message handler.
        /// </summary>
        /// <param name="logicalEP">The logical endpoint.</param>
        /// <param name="msgType">The fully qualified name of the message type handled.</param>
        /// <param name="handler">The message handler.</param>
        /// <remarks>
        /// This constructor creates and initializes the instance's Handlers
        /// hash table with the single entry specified by the msgType (the key)
        /// and handler (the value) parameters.
        /// </remarks>
        internal LogicalRoute(MsgEP logicalEP, string msgType, MsgHandler handler)
        {
            if (logicalEP.IsPhysical)
            {
                throw new ArgumentException("Logical endpoint expected.", "logicalEP");
            }

            this.logicalEP     = logicalEP;
            this.physicalRoute = null;
            this.targetGroup   = handler.Target;
            this.handlers      = new Dictionary <string, MsgHandler>();
            this.marked        = false;
            this.distance      = RouteDistance.Unknown;

            this.handlers.Add(msgType, handler);
        }
Exemplo n.º 6
0
 public Drive(RouteDistance distance)
 {
     Distance = distance;
 }
Exemplo n.º 7
0
        private static Lift BuildLift(KeyValuePair <object, Distance> passengerIdAndDistance)
        {
            var liftDistance = new RouteDistance(new RoutePoint(), new RoutePoint(passengerIdAndDistance.Value));

            return(new Lift(passengerIdAndDistance.Key, liftDistance));
        }
Exemplo n.º 8
0
 public Lift(object passengerId, RouteDistance liftDistance)
 {
     _passengerId = passengerId;
     _distance    = liftDistance;
 }