Пример #1
0
 /// <summary>
 /// Creates a new delivery snapshot to reflect changes in routing, i.e. when the route
 /// specification or the itinerary has changed but no additional handling of the
 /// cargo has been performed.
 /// </summary>
 /// <param name="routeSpecification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>New delivery status description.</returns>
 public Delivery UpdateOnRouting(RouteSpecification routeSpecification, Itinerary itinerary)
 {
     if (routeSpecification == null)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     return(new Delivery(m_lastEvent, itinerary, routeSpecification));
 }
Пример #2
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return(RoutingStatus.NotRouted);
     }
     return(specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted);
 }
Пример #3
0
        /// <summary>
        /// Specifies a new route for this cargo.
        /// </summary>
        /// <param name="routeSpecification">Route specification.</param>
        public void SpecifyNewRoute(RouteSpecification routeSpecification)
        {
            if (routeSpecification == null)
            {
                throw new ArgumentNullException("routeSpecification");
            }

            RouteSpecification = routeSpecification;
            Delivery           = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
        }
Пример #4
0
        /// <summary>
        /// Specifies a new route for this cargo.
        /// </summary>
        /// <param name="routeSpecification">Route specification.</param>
        public void SpecifyNewRoute(RouteSpecification routeSpecification)
        {
            if (routeSpecification == null)
            {
                throw new ArgumentNullException("routeSpecification");
            }

            RouteSpecification = routeSpecification;
            Delivery           = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
        }
Пример #5
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary,
                         RouteSpecification specification)
        {
            m_calculatedAt = DateTime.Now;
            m_lastEvent    = lastHandlingEvent;

            m_misdirected       = CalculateMisdirectionStatus(itinerary);
            m_routingStatus     = CalculateRoutingStatus(itinerary, specification);
            m_transportStatus   = CalculateTransportStatus();
            m_lastKnownLocation = CalculateLastKnownLocation();
            m_eta = CalculateEta(itinerary);
            m_nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary);
            m_isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
Пример #6
0
        /// <summary>
        /// Creates new <see cref="Cargo"/> object with provided tracking id and route specification.
        /// </summary>
        /// <param name="trackingId">Tracking id of this cargo.</param>
        /// <param name="routeSpecification">Route specification.</param>
        public Cargo(TrackingId trackingId, RouteSpecification routeSpecification)
        {
            if (trackingId == null)
            {
                throw new ArgumentNullException("trackingId");
            }

            if (routeSpecification == null)
            {
                throw new ArgumentNullException("routeSpecification");
            }

            TrackingId         = trackingId;
            RouteSpecification = routeSpecification;
            Delivery           = Delivery.DerivedFrom(RouteSpecification, Itinerary, null);
        }
Пример #7
0
        /// <summary>
        /// Creates new <see cref="Cargo"/> object with provided tracking id and route specification.
        /// </summary>
        /// <param name="trackingId">Tracking id of this cargo.</param>
        /// <param name="routeSpecification">Route specification.</param>
        public Cargo(TrackingId trackingId, RouteSpecification routeSpecification)
        {
            if (trackingId == null)
            {
                throw new ArgumentNullException("trackingId");
            }

            if (routeSpecification == null)
            {
                throw new ArgumentNullException("routeSpecification");
            }

            TrackingId         = trackingId;
            RouteSpecification = routeSpecification;
            Delivery           = Delivery.DerivedFrom(RouteSpecification, Itinerary, null);
        }
        public static Cargo CreateNew(String from, String to)
        {
            if (String.IsNullOrEmpty(from) || from.Length < 5)
            {
                throw new ArgumentException("from");
            }

            if (String.IsNullOrEmpty(to) || to.Length < 5)
            {
                throw new ArgumentException("to");
            }

            var origin      = new Location(new UnLocode(from.ToUpper().Substring(0,5)), from);
            var destination = new Location(new UnLocode(to.ToUpper().Substring(0, 5)), to);
            var trackingId  = NextTrackingId();
            var route       = new RouteSpecification(origin, destination, DateTime.Now);
            
            return new Cargo(trackingId, route);
        }
Пример #9
0
        private HandlingActivity CalculateNextExpectedActivity(RouteSpecification routeSpecification, Itinerary itinerary)
        {
            if (!OnTrack)
            {
                return(null);
            }

            if (LastEvent == null)
            {
                return(new HandlingActivity(HandlingEventType.Receive, routeSpecification.Origin));
            }

            switch (LastEvent.EventType)
            {
            case HandlingEventType.Load:
                Leg lastLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == LastEvent.Location);
                return(lastLeg != null ? new HandlingActivity(HandlingEventType.Unload, lastLeg.UnloadLocation) : null);

            case HandlingEventType.Unload:
                IEnumerator <Leg> enumerator = itinerary.Legs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.UnloadLocation == LastEvent.Location)
                    {
                        Leg currentLeg = enumerator.Current;
                        return(enumerator.MoveNext()
                                ? new HandlingActivity(HandlingEventType.Load, enumerator.Current.LoadLocation)
                                : new HandlingActivity(HandlingEventType.Claim, currentLeg.UnloadLocation));
                    }
                }
                return(null);

            case HandlingEventType.Receive:
                Leg firstLeg = itinerary.Legs.First();
                return(new HandlingActivity(HandlingEventType.Load, firstLeg.LoadLocation));

            default:
                return(null);
            }
        }
Пример #10
0
 private Boolean CalculateUnloadedAtDestination(RouteSpecification specification)
 {
     return(LastEvent != null &&
            LastEvent.EventType == HandlingEventType.Unload &&
            specification.Destination == LastEvent.Location);
 }
Пример #11
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return RoutingStatus.NotRouted;
     }
     return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted;
 }
Пример #12
0
        private HandlingActivity CalculateNextExpectedActivity(RouteSpecification routeSpecification, Itinerary itinerary)
        {
            if (!OnTrack)
            {
                return null;
            }

            if (LastEvent == null)
            {
                return new HandlingActivity(HandlingEventType.Receive, routeSpecification.Origin);
            }

            switch (LastEvent.EventType)
            {
                case HandlingEventType.Load:
                    Leg lastLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == LastEvent.Location);
                    return lastLeg != null ? new HandlingActivity(HandlingEventType.Unload, lastLeg.UnloadLocation) : null;

                case HandlingEventType.Unload:
                    IEnumerator<Leg> enumerator = itinerary.Legs.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.UnloadLocation == LastEvent.Location)
                        {
                            Leg currentLeg = enumerator.Current;
                            return enumerator.MoveNext()
                                ? new HandlingActivity(HandlingEventType.Load, enumerator.Current.LoadLocation)
                                : new HandlingActivity(HandlingEventType.Claim, currentLeg.UnloadLocation);
                        }
                    }
                    return null;

                case HandlingEventType.Receive:
                    Leg firstLeg = itinerary.Legs.First();
                    return new HandlingActivity(HandlingEventType.Load, firstLeg.LoadLocation);

                default:
                    return null;
            }
        }
Пример #13
0
 private Boolean CalculateUnloadedAtDestination(RouteSpecification specification)
 {
     return LastEvent != null &&
              LastEvent.EventType == HandlingEventType.Unload &&
              specification.Destination == LastEvent.Location;
 }
Пример #14
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary,
            RouteSpecification specification)
        {
            m_calculatedAt = DateTime.Now;
            m_lastEvent = lastHandlingEvent;

            m_misdirected = CalculateMisdirectionStatus(itinerary);
            m_routingStatus = CalculateRoutingStatus(itinerary, specification);
            m_transportStatus = CalculateTransportStatus();
            m_lastKnownLocation = CalculateLastKnownLocation();
            m_eta = CalculateEta(itinerary);
            m_nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary);
            m_isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
Пример #15
0
 /// <summary>
 /// Creates a new delivery snapshot to reflect changes in routing, i.e. when the route 
 /// specification or the itinerary has changed but no additional handling of the 
 /// cargo has been performed.
 /// </summary>
 /// <param name="routeSpecification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>New delivery status description.</returns>
 public Delivery UpdateOnRouting(RouteSpecification routeSpecification, Itinerary itinerary)
 {
     if (routeSpecification == null)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     return new Delivery(m_lastEvent, itinerary, routeSpecification);
 }
Пример #16
0
 /// <summary>
 /// Creates a new delivery snapshot based on the complete handling history of a cargo, as well 
 /// as its route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(
     RouteSpecification specification,
     Itinerary itinerary,
     HandlingEvent lastHandlingEvent)
 {
     return new Delivery(lastHandlingEvent, itinerary, specification);
 }