示例#1
0
      public void IsExpected_ReceiveEvent_FirstLegLocationMathesEventLocation_True()
      {
         Itinerary itinerary = new Itinerary(new[]{new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now  )});
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Receive, Krakow, DateTime.Now, DateTime.Now);

         Assert.IsTrue(itinerary.IsExpected(@event));
      }
示例#2
0
 /// <summary>
 /// Checks whether provided event is expected according to this itinerary specification.
 /// </summary>
 /// <param name="event">A handling event.</param>
 /// <returns>True, if it is expected. Otherwise - false. If itinerary is empty, returns false.</returns>
 public virtual bool IsExpected(HandlingEvent @event)
 {
    if (IsEmpty)
    {
       return false;
    }
    if (@event.EventType == HandlingEventType.Receive)
    {
       Leg firstLeg = _legs.First();
       return firstLeg.LoadLocation == @event.Location;
    }
    if (@event.EventType == HandlingEventType.Claim)
    {
       Leg lastLeg = _legs.Last();
       return lastLeg.UnloadLocation == @event.Location;
    }
    if (@event.EventType == HandlingEventType.Load)
    {
       return _legs.Any(x => x.LoadLocation == @event.Location);            
    }
    if (@event.EventType == HandlingEventType.Unload)
    {
       return _legs.Any(x => x.UnloadLocation == @event.Location);
    }
    //@event.EventType == HandlingEventType.Customs
    return true;
 }
示例#3
0
      public void IsExpected_ClaimEvent_Empty_False()
      {
         Itinerary itinerary = new Itinerary(new Leg[] { });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Krakow, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#4
0
      public void IsExpected_ReceiveEvent_FirstLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[] { new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now) });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Receive, Warszawa, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#5
0
      public void IsExpected_ClainEvent_LastLegLocationDoesntMatchEventLocation_False()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });
         HandlingEvent @event = new HandlingEvent(HandlingEventType.Claim, Warszawa, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#6
0
 /// <summary>
 /// Updates delivery progress information according to handling history.
 /// </summary>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 public virtual void DeriveDeliveryProgress(HandlingEvent lastHandlingEvent)
 {
     Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, lastHandlingEvent);
     if (Delivery.IsMisdirected)
     {
         DomainEvents.Raise(new CargoWasMisdirectedEvent(this));
     }
     else if (Delivery.IsUnloadedAtDestination)
     {
         DomainEvents.Raise(new CargoHasArrivedEvent(this));
     }
 }
示例#7
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent    = lastHandlingEvent;

            _isMisdirected           = CalculateMisdirectionStatus(itinerary);
            _routingStatus           = CalculateRoutingStatus(itinerary, specification);
            _transportStatus         = CalculateTransportStatus();
            _lastKnownLocation       = CalculateLastKnownLocation();
            _estimatedTimeOfArrival  = CalculateEta(itinerary);
            _nextExpectedActivity    = CalculateNextExpectedActivity(specification, itinerary);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification);
        }
示例#8
0
        private HandlingActivity CalculateNextExpectedActivity(HandlingEvent lastEvent, 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);
            }
        }
示例#9
0
        private static TransportStatus CalculateTransportStatus(HandlingEvent lastEvent)
        {
            if (lastEvent == null)
            {
                return(TransportStatus.NotReceived);
            }

            switch (lastEvent.EventType)
            {
            case HandlingEventType.Load:
                return(TransportStatus.OnboardCarrier);

            case HandlingEventType.Unload:
            case HandlingEventType.Receive:
            case HandlingEventType.Customs:
                return(TransportStatus.InPort);

            case HandlingEventType.Claim:
                return(TransportStatus.Claimed);

            default:
                return(TransportStatus.Unknown);
            }
        }
示例#10
0
      private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
      {
         CalculatedAt = DateTime.Now;
         LastEvent = lastHandlingEvent;

         IsMisdirected = CalculateMisdirectionStatus(itinerary, lastHandlingEvent);
         RoutingStatus = CalculateRoutingStatus(itinerary, specification);
         TransportStatus = CalculateTransportStatus(lastHandlingEvent);
         LastKnownLocation = CalculateLastKnownLocation(lastHandlingEvent);
         EstimatedTimeOfArrival = CalculateEta(itinerary);
         NextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary, lastHandlingEvent);
         IsUnloadedAtDestination = CalculateUnloadedAtDestination(specification, lastHandlingEvent);
      }
示例#11
0
 private static UnLocode CalculateLastKnownLocation(HandlingEvent lastHandlingEvent)
 {
    return lastHandlingEvent != null ? lastHandlingEvent.Location : null;
 }
示例#12
0
      private static TransportStatus CalculateTransportStatus(HandlingEvent lastHandlingEvent)
      {
         if (lastHandlingEvent == null)
         {
            return TransportStatus.NotReceived;
         }

         switch (lastHandlingEvent.EventType)
         {
            case HandlingEventType.Load:
               return TransportStatus.OnboardCarrier;
            case HandlingEventType.Unload:
            case HandlingEventType.Receive:
            case HandlingEventType.Customs:
               return TransportStatus.InPort;
            case HandlingEventType.Claim:
               return TransportStatus.Claimed;
            default:
               return TransportStatus.Unknown;
         }
      }
示例#13
0
 private static bool CalculateUnloadedAtDestination(HandlingEvent lastEvent, RouteSpecification specification)
 {
     return(lastEvent != null &&
            lastEvent.EventType == HandlingEventType.Unload &&
            specification.Destination == lastEvent.Location);
 }
示例#14
0
 private static Location.Location CalculateLastKnownLocation(HandlingEvent lastEvent)
 {
     return(lastEvent != null ? lastEvent.Location : null);
 }
示例#15
0
      private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
      {
         _calculatedAt = DateTime.Now;
         _lastEvent = lastHandlingEvent;

         _misdirected = CalculateMisdirectionStatus(itinerary, lastHandlingEvent);
         _routingStatus = CalculateRoutingStatus(itinerary, specification);
         _transportStatus = CalculateTransportStatus(lastHandlingEvent);
         _lastKnownLocation = CalculateLastKnownLocation(lastHandlingEvent);
         _eta = CalculateEta(itinerary);
         _nextExpectedActivity = CalculateNextExpectedActivity(specification, itinerary, lastHandlingEvent);
         _isUnloadedAtDestination = CalculateUnloadedAtDestination(specification, lastHandlingEvent);
      }
示例#16
0
 /// <summary>
 /// Registers new handling event into the history.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="location">Location where event occured.</param>
 /// <param name="registrationDate">Date when event was registered.</param>
 /// <param name="completionDate">Date when action represented by the event was completed.</param>
 public virtual void RegisterHandlingEvent(HandlingEventType eventType, UnLocode location, DateTime registrationDate, DateTime completionDate)
 {
    var @event = new HandlingEvent(eventType, location, registrationDate, completionDate);
    
    Publish(this, new CargoHandledEvent(Delivery.DerivedFrom(RouteSpecification, Itinerary, @event)));
 }      
示例#17
0
 private static bool CalculateUnloadedAtDestination(RouteSpecification specification, HandlingEvent lastHandlingEvent)
 {
    return lastHandlingEvent != null &&
             lastHandlingEvent.EventType == HandlingEventType.Unload &&
             specification.Destination == lastHandlingEvent.Location;
 }
示例#18
0
      public void IsExpected_LoadEvent_NoLegLocationMathesEventLocation_True()
      {
         Itinerary itinerary = new Itinerary(new[]
                                                {
                                                   new Leg(Krakow, DateTime.Now, Warszawa, DateTime.Now),
                                                   new Leg(Warszawa, DateTime.Now, Wroclaw, DateTime.Now)                                                   
                                                });

         HandlingEvent @event = new HandlingEvent(HandlingEventType.Load, Wroclaw, DateTime.Now, DateTime.Now, null);

         Assert.IsFalse(itinerary.IsExpected(@event));
      }
示例#19
0
      private HandlingActivity CalculateNextExpectedActivity(RouteSpecification routeSpecification, Itinerary itinerary, HandlingEvent lastHandlingEvent)
      {
         if (!OnTrack)
         {
            return null;
         }

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

         switch (lastHandlingEvent.EventType)
         {
            case HandlingEventType.Load:

               Leg lastLeg = itinerary.Legs.FirstOrDefault(x => x.LoadLocation == lastHandlingEvent.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 == lastHandlingEvent.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;
         }
      }
示例#20
0
 /// <summary>
 /// Creates a new delivery snapshot based on route specification, itinerary and last processed
 /// handling event.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <param name="lastEvent">Last processed handling event.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary, HandlingEvent lastEvent)
 {
    return new Delivery(lastEvent, itinerary, specification);
 }
示例#21
0
 private static bool CalculateMisdirectionStatus(Itinerary itinerary, HandlingEvent lastEvent)
 {
    if (lastEvent == null)
    {
       return false;
    }
    return !itinerary.IsExpected(lastEvent);
 }
示例#22
0
        /// <summary>
        /// Registers new handling event into the history.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="location">Location where event occured.</param>
        /// <param name="registrationDate">Date when event was registered.</param>
        /// <param name="completionDate">Date when action represented by the event was completed.</param>
        public virtual void RegisterHandlingEvent(HandlingEventType eventType, UnLocode location, DateTime registrationDate, DateTime completionDate)
        {
            HandlingEvent @event = new HandlingEvent(eventType, location, registrationDate, completionDate);

            Publish(this, new CargoHandledEvent(Delivery.DerivedFrom(_routeSpecification, _itinerary, @event)));
        }
示例#23
0
 /// <summary>
 /// Updates delivery progress information according to handling history.
 /// </summary>
 /// <param name="lastHandlingEvent">Most recent handling event.</param>
 public virtual void DeriveDeliveryProgress(HandlingEvent lastHandlingEvent)
 {
     Delivery = Delivery.DerivedFrom(RouteSpecification, Itinerary, lastHandlingEvent);
 }
示例#24
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));
 }
示例#25
0
 /// <summary>
 /// Registers new handling event into the history.
 /// </summary>
 /// <param name="eventType">Type of the event.</param>
 /// <param name="location">Location where event occured.</param>
 /// <param name="registrationDate">Date when event was registered.</param>
 /// <param name="completionDate">Date when action represented by the event was completed.</param>
 public virtual void RegisterHandlingEvent(HandlingEventType eventType, Location.Location location, DateTime registrationDate, DateTime completionDate)
 {
    HandlingEvent @event = new HandlingEvent(eventType, location, registrationDate, completionDate, this);
    _handlingEvents.Add(@event);
    _lastHandlingEvent = @event;
    Delivery currentDelivery = Delivery.DerivedFrom(_routeSpecification, _itinerary, @event);         
    DomainEvents.Raise(new CargoWasHandledEvent(this, currentDelivery, eventType));
 }