示例#1
0
 public bool IsSatisfiedBy(Itinerary itinerary)
 {
     return(itinerary.FirstLoadLocation.Equals(Origin)
            &&
            itinerary.LastUnloadLocation.Equals(Destination)
            &&
            itinerary.FinalArrivalDate <= ArrivalDeadline);
 }
示例#2
0
        public void AssignToItinerary(Itinerary itinerary)
        {
            Itinerary = itinerary ?? throw new ArgumentNullException(nameof(itinerary));

            Delivery = new Delivery(RouteSpec, Itinerary, LastHandlingEvent);

            this.Events.Add(new AssignedToItinerary(TrackingId, Itinerary));
            this.Events.Add(new DeliveryStateChanged(TrackingId, Delivery));
        }
示例#3
0
        // rehydration ctor
        public Cargo(TrackingId trackingId, RouteSpecification routeSpec, Itinerary itinerary, Delivery delivery, HandlingEvent lastHandlingEvent)
        {
            TrackingId        = trackingId;
            RouteSpec         = routeSpec;
            Itinerary         = itinerary;
            LastHandlingEvent = lastHandlingEvent;

            Delivery = new Delivery(RouteSpec, Itinerary, LastHandlingEvent);
        }
示例#4
0
 private void _calcIsMishandled(Itinerary itinerary, HandlingEvent @event)
 {
     if (@event == null || itinerary == null)
     {
         IsMishandled = false;
     }
     else
     {
         IsMishandled = itinerary.IsExpected(@event);
     }
 }
示例#5
0
 private void _calcRoutingStatus(RouteSpecification routeSpec, Itinerary itinerary)
 {
     if (itinerary == null)
     {
         RoutingStatus = RoutingStatus.NotRouted;
     }
     else if (routeSpec.IsSatisfiedBy(itinerary))
     {
         RoutingStatus = RoutingStatus.Routed;
     }
     else
     {
         RoutingStatus = RoutingStatus.MisRouted;
     }
 }
示例#6
0
        public Delivery(
            RouteSpecification routeSpec,
            Itinerary itinerary,
            HandlingEvent lastHandlingEvent
            )
        {
            RouteSpec         = routeSpec ?? throw new ArgumentNullException(nameof(routeSpec));
            Itinerary         = itinerary;
            LastHandlingEvent = lastHandlingEvent;

            _calcTransportStatus(lastHandlingEvent);
            _calcLastKnownLocation(lastHandlingEvent);
            _calcCurrentVoyage(lastHandlingEvent);
            _calcNextExpectedHandlingActivity(routeSpec, itinerary, lastHandlingEvent);
            _calcIsUnloadedAtDestination(routeSpec, lastHandlingEvent);
            _calcRoutingStatus(routeSpec, itinerary);
            _calcIsMishandled(itinerary, lastHandlingEvent);
        }
示例#7
0
        private void _calcNextExpectedHandlingActivity(RouteSpecification routeSpec, Itinerary itinerary, HandlingEvent @event)
        {
            // can't derive next handling activity if there is no itinerary
            if (itinerary == null)
            {
                NextExpectedHandlingActivity = null;
                return;
            }

            // can't derive the next handling activity if the cargo is misrouted
            _calcRoutingStatus(routeSpec, itinerary);
            if (RoutingStatus == RoutingStatus.MisRouted)
            {
                NextExpectedHandlingActivity = null;
                return;
            }

            // no handling event so far; next one should be receive at itinerary's first leg unload location
            if (@event == null)
            {
                NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Receive, itinerary.FirstLoadLocation, null);
                return;
            }

            switch (@event.Type)
            {
            // last handling event = received => next handling activity = load at itinerary's first leg unload location and voyage
            case HandlingType.Receive:

                NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Load, itinerary.FirstLoadLocation, itinerary.FirstYoyage);

                return;

            // last handling event = load => next handling activity = unload at itinerary's next leg unload location
            case HandlingType.Load:
                var leg = itinerary.Of(@event.Location);

                NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Unload, leg.UnloadLocation, leg.Voyage);

                return;

            // last handling event = unload => next handling activity =
            // a. load at itinerary's next leg load location and voyage, if that leg is not the final one
            // b. customs at itinerarys's final unload location
            case HandlingType.Unload:

                if (@event.Location.Equals(itinerary.LastUnloadLocation))
                {
                    NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Customs, itinerary.LastUnloadLocation, null);
                    return;
                }

                var nextLeg = itinerary.NextOf(@event.Location);
                NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Load, nextLeg.LoadLocation, nextLeg.Voyage);
                return;

            // last handling event = customs => next handling activity = claim
            case HandlingType.Customs:
                NextExpectedHandlingActivity = new HandlingActivity(HandlingType.Claim, itinerary.LastUnloadLocation, null);
                return;

            // last handling event = claim => next handling activity = none
            case HandlingType.Claim:
            default:
                NextExpectedHandlingActivity = null;
                return;
            }
        }