Exemplo n.º 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));
      }
Exemplo n.º 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;
 }
Exemplo n.º 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));
      }
Exemplo n.º 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));
      }
Exemplo n.º 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));
      }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
      }
Exemplo n.º 11
0
 private static UnLocode CalculateLastKnownLocation(HandlingEvent lastHandlingEvent)
 {
    return lastHandlingEvent != null ? lastHandlingEvent.Location : null;
 }
Exemplo n.º 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;
         }
      }
Exemplo n.º 13
0
 private static bool CalculateUnloadedAtDestination(HandlingEvent lastEvent, RouteSpecification specification)
 {
     return(lastEvent != null &&
            lastEvent.EventType == HandlingEventType.Unload &&
            specification.Destination == lastEvent.Location);
 }
Exemplo n.º 14
0
 private static Location.Location CalculateLastKnownLocation(HandlingEvent lastEvent)
 {
     return(lastEvent != null ? lastEvent.Location : null);
 }
Exemplo n.º 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);
      }
Exemplo n.º 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)));
 }      
Exemplo n.º 17
0
 private static bool CalculateUnloadedAtDestination(RouteSpecification specification, HandlingEvent lastHandlingEvent)
 {
    return lastHandlingEvent != null &&
             lastHandlingEvent.EventType == HandlingEventType.Unload &&
             specification.Destination == lastHandlingEvent.Location;
 }
Exemplo n.º 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));
      }
Exemplo n.º 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;
         }
      }
Exemplo n.º 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);
 }
Exemplo n.º 21
0
 private static bool CalculateMisdirectionStatus(Itinerary itinerary, HandlingEvent lastEvent)
 {
    if (lastEvent == null)
    {
       return false;
    }
    return !itinerary.IsExpected(lastEvent);
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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));
 }
Exemplo n.º 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));
 }