/// <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));
 }
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return(RoutingStatus.NotRouted);
     }
     return(specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted);
 }
 private Boolean CalculateMisdirectionStatus(Itinerary itinerary)
 {
     if (LastEvent == null)
     {
         return(false);
     }
     return(!itinerary.IsExpected(LastEvent));
 }
 /// <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));
 }
Esempio n. 5
0
        /// <summary>
        /// Assigns cargo to a provided route.
        /// </summary>
        /// <param name="itinerary">New itinerary</param>
        public void AssignToRoute(Itinerary itinerary)
        {
            if (itinerary == null)
            {
                throw new ArgumentNullException("itinerary");
            }

            var @event = new CargoHasBeenAssignedToRouteEvent(this, Itinerary);

            Itinerary = itinerary;
            Delivery  = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);

            m_eventAggegator.Publish <CargoHasBeenAssignedToRouteEvent>(@event);
        }
        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);
        }
Esempio n. 7
0
 private Boolean CalculateMisdirectionStatus(Itinerary itinerary)
 {
     if (LastEvent == null)
     {
         return false;
     }
     return !itinerary.IsExpected(LastEvent);
 }
Esempio n. 8
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);
 }
Esempio n. 9
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);
 }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
 private Nullable <DateTime> CalculateEta(Itinerary itinerary)
 {
     return(OnTrack ? itinerary.FinalArrivalDate : null);
 }
Esempio n. 12
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);
        }
 /// <summary>
 /// Checks whether provided itinerary (a description of transporting steps) satisfies this
 /// specification.
 /// </summary>
 /// <param name="itinerary">An itinerary.</param>
 /// <returns>True, if cargo can be transported from <see cref="Origin"/> to <see cref="Destination"/>
 /// before <see cref="ArrivalDeadline"/> using provided itinerary.
 /// </returns>
 public Boolean IsSatisfiedBy(Itinerary itinerary)
 {
     return Origin == itinerary.InitialDepartureLocation &&
            Destination == itinerary.FinalArrivalLocation &&
            ArrivalDeadline > itinerary.FinalArrivalDate;
 }
 /// <summary>
 /// Checks whether provided itinerary (a description of transporting steps) satisfies this
 /// specification.
 /// </summary>
 /// <param name="itinerary">An itinerary.</param>
 /// <returns>True, if cargo can be transported from <see cref="Origin"/> to <see cref="Destination"/>
 /// before <see cref="ArrivalDeadline"/> using provided itinerary.
 /// </returns>
 public Boolean IsSatisfiedBy(Itinerary itinerary)
 {
     return(Origin == itinerary.InitialDepartureLocation &&
            Destination == itinerary.FinalArrivalLocation &&
            ArrivalDeadline > itinerary.FinalArrivalDate);
 }
Esempio n. 15
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return RoutingStatus.NotRouted;
     }
     return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted;
 }
Esempio n. 16
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;
            }
        }
Esempio n. 17
0
 private Nullable<DateTime> CalculateEta(Itinerary itinerary)
 {
     return OnTrack ? itinerary.FinalArrivalDate : null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CargoHasBeenAssignedToRouteEvent"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="oldItinerary">The old itinerary.</param>
 public CargoHasBeenAssignedToRouteEvent(Cargo source, Itinerary oldItinerary)
 {
     m_oldItinerary = oldItinerary;
 }
Esempio n. 19
0
        /// <summary>
        /// Assigns cargo to a provided route.
        /// </summary>
        /// <param name="itinerary">New itinerary</param>
        public void AssignToRoute(Itinerary itinerary)
        {
            if (itinerary == null)
            {
                throw new ArgumentNullException("itinerary");
            }

            var @event = new CargoHasBeenAssignedToRouteEvent(this, Itinerary);
            Itinerary  = itinerary;
            Delivery   = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);

            m_eventAggegator.Publish<CargoHasBeenAssignedToRouteEvent>(@event);
        }