public CargoDestinationChangedEvent(Cargo cargo, RouteSpecification oldSpecification, RouteSpecification newSpecification, Delivery delivery)
 {
    _cargo = cargo;
    _delivery = delivery;
    _newSpecification = newSpecification;
    _oldSpecification = oldSpecification;
 }
Example #2
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return(RoutingStatus.NotRouted);
     }
     return(specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted);
 }
Example #3
0
      public void ChangeDestination(TrackingId trackingId, UnLocode destinationUnLocode)
      {
         Cargo cargo = _cargoRepository.Find(trackingId);
         Location destination = _locationRepository.Find(destinationUnLocode);

         RouteSpecification routeSpecification = new RouteSpecification(cargo.RouteSpecification.Origin, destination, cargo.RouteSpecification.ArrivalDeadline);
         cargo.SpecifyNewRoute(routeSpecification);
      }
Example #4
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(_lastEvent, itinerary, routeSpecification));
 }
Example #5
0
      public IList<Itinerary> FetchRoutesForSpecification(RouteSpecification routeSpecification)
      {
         IList<TransitPath> paths = _graphTraversalService.FindShortestPaths(
            routeSpecification.Origin.UnLocode.CodeString,
            routeSpecification.Destination.UnLocode.CodeString,
            new Constraints(routeSpecification.ArrivalDeadline));

         return paths.Select(x => ToItinerary(x)).ToList();
      }      
Example #6
0
 /// <summary>
 /// Specifies a new route for this cargo.
 /// </summary>
 /// <param name="routeSpecification">Route specification.</param>
 public virtual void SpecifyNewRoute(RouteSpecification routeSpecification)
 {
     if (routeSpecification == null)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     RouteSpecification = routeSpecification;
     Delivery           = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
 }
Example #7
0
 /// <summary>
 /// Specifies a new route for this cargo.
 /// </summary>
 /// <param name="routeSpecification">Route specification.</param>
 public virtual void SpecifyNewRoute(RouteSpecification routeSpecification)
 {
     if (routeSpecification == null)
     {
         throw new ArgumentNullException("routeSpecification");
     }
     RouteSpecification = routeSpecification;
     Delivery = Delivery.UpdateOnRouting(RouteSpecification, Itinerary);
 }
        public void It_is_not_satisfied_if_destination_does_not_match()
        {
            var specification = new RouteSpecification(Krakow, Wroclaw, ArrivalDeadline);

            var itinerary = new Itinerary(new[]
                                              {
                                                  new Leg(null, Krakow, new DateTime(2011, 12, 1), Warszawa,
                                                          new DateTime(2011, 12, 2))
                                              });
            Assert.IsFalse(specification.IsSatisfiedBy(itinerary));
        }
Example #9
0
      /// <summary>
      /// Specifies a new route for this cargo.
      /// </summary>
      /// <param name="destination">New destination.</param>
      public virtual void SpecifyNewRoute(UnLocode destination)
      {
         if (destination == null)
         {
            throw new ArgumentNullException("destination");
         }
         var routeSpecification = new RouteSpecification(RouteSpecification.Origin, destination,
                                                                        RouteSpecification.ArrivalDeadline);

         Publish(this, new CargoDestinationChangedEvent(routeSpecification,
                                                DeliveryStatus.Derive(routeSpecification, Itinerary)));         
      }
Example #10
0
      private IEnumerable<Itinerary> GetAllPossibleRoutes(RouteSpecification routeSpecification)
      {
         IList<Voyage> voyages = _voyageRepository.FindBeginingBefore(routeSpecification.ArrivalDeadline);
         IList<TransitEdge> graph = voyages.SelectMany(v => v.Schedule.CarrierMovements.Select(m => ToEdge(v, m))).ToList();

         var allPaths = _graphTraversalService.FindPaths(
            routeSpecification.Origin.UnLocode.CodeString,
            routeSpecification.Destination.UnLocode.CodeString,
            graph,
            new Constraints(routeSpecification.ArrivalDeadline));
         return allPaths.Select(x => ToItinerary(x));
      }
Example #11
0
      public TrackingId BookNewCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, DateTime arrivalDeadline)
      {
         Location origin = _locationRepository.Find(originUnLocode);
         Location destination = _locationRepository.Find(destinationUnLocode);

         RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
         TrackingId trackingId = _cargoRepository.NextTrackingId();
         Cargo cargo = new Cargo(trackingId, routeSpecification);

         _cargoRepository.Store(cargo);
         return trackingId;
      }
Example #12
0
        /// <summary>
        /// Specifies a new route for this cargo.
        /// </summary>
        /// <param name="destination">New destination.</param>
        public virtual void SpecifyNewRoute(UnLocode destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            RouteSpecification routeSpecification = new RouteSpecification(_routeSpecification.Origin, destination,
                                                                           _routeSpecification.ArrivalDeadline);

            Publish(this, new CargoDestinationChangedEvent(routeSpecification,
                                                           _deliveryStatus.Derive(routeSpecification, _itinerary)));
        }
        public void It_is_satisfied_if_origin_and_destination_match_and_deadline_is_not_exceeded()
        {
            var specification = new RouteSpecification(Krakow, Wroclaw, ArrivalDeadline);

            var itinerary = new Itinerary(new[]
                                              {
                                                  new Leg(null, Krakow, new DateTime(2011, 12, 1), Warszawa,
                                                          new DateTime(2011, 12, 2)),
                                                  new Leg(null, Warszawa, new DateTime(2011, 12, 13), Wroclaw,
                                                          ArrivalDeadline)
                                              });
            Assert.IsTrue(specification.IsSatisfiedBy(itinerary));
        }
Example #14
0
        /// <summary>
        /// Assigns cargo to a provided route.
        /// </summary>
        /// <param name="itinerary">New itinerary</param>
        public virtual void AssignToRoute(Itinerary itinerary)
        {
            if (itinerary == null)
            {
                throw new ArgumentNullException("itinerary");
            }
            if (!RouteSpecification.IsSatisfiedBy(itinerary))
            {
                throw new InvalidOperationException("Provided itinerary doesn't satisfy this cargo's route specification.");
            }

            Publish(this, new CargoAssignedToRouteEvent(itinerary, DeliveryStatus.Derive(RouteSpecification, itinerary)));
        }
Example #15
0
      /// <summary>
      /// Specifies a new route for this cargo.
      /// </summary>
      /// <param name="destination">New destination.</param>
      public virtual void SpecifyNewRoute(Location.Location destination)
      {
         if (destination == null)
         {
            throw new ArgumentNullException("destination");
         }
         RouteSpecification routeSpecification = new RouteSpecification(_routeSpecification.Origin, destination, _routeSpecification.ArrivalDeadline);

         Delivery delivery = Delivery.DerivedFrom(routeSpecification, _itinerary, _lastHandlingEvent);
         CargoDestinationChangedEvent @event = new CargoDestinationChangedEvent(this, routeSpecification, _routeSpecification, delivery);         
         _routeSpecification = routeSpecification;
         DomainEvents.Raise(@event);
      }
Example #16
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);
        }
Example #17
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);
 }
Example #18
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");
         }

         Publish(this, new CargoRegisteredEvent(trackingId, routeSpecification,
                                        Delivery.DerivedFrom(RouteSpecification, Itinerary)));         
      }
Example #19
0
        /// <summary>
        /// Specifies a new route for this cargo.
        /// </summary>
        /// <param name="destination">New destination.</param>
        public virtual void SpecifyNewRoute(Location.Location destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            RouteSpecification routeSpecification = new RouteSpecification(_routeSpecification.Origin, destination, _routeSpecification.ArrivalDeadline);

            Delivery delivery = Delivery.DerivedFrom(routeSpecification, _itinerary, _lastHandlingEvent);
            CargoDestinationChangedEvent @event = new CargoDestinationChangedEvent(this, routeSpecification, _routeSpecification, delivery);

            _routeSpecification = routeSpecification;
            DomainEvents.Raise(@event);
        }
Example #20
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);
 }
Example #21
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");
            }

            Publish(this, new CargoRegisteredEvent(trackingId, routeSpecification,
                                                   Delivery.DerivedFrom(_routeSpecification, _itinerary)));
        }
Example #22
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");
         }
         _handlingEvents = new List<HandlingEvent>();

         TrackingId = trackingId;
         _routeSpecification = routeSpecification;
         Delivery delivery = Delivery.DerivedFrom(_routeSpecification, _itinerary, _lastHandlingEvent);         
         DomainEvents.Raise(new CargoRegisteredEvent(this, _routeSpecification, delivery));
      }
Example #23
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");
            }
            _handlingEvents = new List <HandlingEvent>();

            TrackingId          = trackingId;
            _routeSpecification = routeSpecification;
            Delivery delivery = Delivery.DerivedFrom(_routeSpecification, _itinerary, _lastHandlingEvent);

            DomainEvents.Raise(new CargoRegisteredEvent(this, _routeSpecification, delivery));
        }
 public IList<Itinerary> FetchRoutesForSpecification(RouteSpecification routeSpecification)
 {
    if (routeSpecification.Destination == ScenarioTest.STOCKHOLM) {
       // Hongkong - NYC - Chicago - Stockholm, initial routing
       return new List<Itinerary>{
                                    new Itinerary(new List<Leg>{
                                                                  new Leg(ScenarioTest.HONGKONG, new DateTime(2009,3,03), ScenarioTest.NEWYORK, new DateTime(2009,3,9)),
                                                                  new Leg(ScenarioTest.NEWYORK, new DateTime(2009,3,10), ScenarioTest.CHICAGO, new DateTime(2009,3,14)),
                                                                  new Leg(ScenarioTest.CHICAGO, new DateTime(2009,3,7), ScenarioTest.STOCKHOLM, new DateTime(2009,3,11))
                                                               })
                                 };
    } else {
       // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo 
       return new List<Itinerary>{
                                    new Itinerary(new List<Leg>{
                                                                  new Leg(ScenarioTest.HONGKONG, new DateTime(2009,3,8), ScenarioTest.HAMBURG, new DateTime(2009,3,12)),
                                                                  new Leg(ScenarioTest.HAMBURG, new DateTime(2009,3,14), ScenarioTest.GOETEBORG, new DateTime(2009,3,15))
                                                               })
                                 };
    }
 }
Example #25
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);
            }
        }
Example #26
0
 private static bool CalculateUnloadedAtDestination(HandlingEvent lastEvent, RouteSpecification specification)
 {
     return(lastEvent != null &&
            lastEvent.EventType == HandlingEventType.Unload &&
            specification.Destination == lastEvent.Location);
 }
 public CargoDestinationChangedEvent(RouteSpecification newSpecification, Delivery delivery)
 {
     Delivery         = delivery;
     NewSpecification = newSpecification;
 }
Example #28
0
 private bool CalculateUnloadedAtDestination(RouteSpecification specification)
 {
    return LastEvent != null &&
             LastEvent.EventType == HandlingEventType.Unload &&
             specification.Destination == LastEvent.Location;
 }
 public CargoRegisteredEvent(Cargo cargo, RouteSpecification routeSpecification, Delivery delivery)
 {
    _cargo = cargo;
    _routeSpecification = routeSpecification;
    _delivery = delivery;         
 }
Example #30
0
 private bool CalculateUnloadedAtDestination(RouteSpecification specification)
 {
     return(LastEvent != null &&
            LastEvent.EventType == HandlingEventType.Unload &&
            specification.Destination == LastEvent.Location);
 }
Example #31
0
 /// <summary>
 /// Creates a new delivery snapshot based only on route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary)
 {
    return new Delivery(null, itinerary, specification);
 }
Example #32
0
 /// <summary>
 /// Creates a new delivery snapshot based on the previous (current) one and (possibly changed)
 /// specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public Delivery Derive(RouteSpecification specification, Itinerary itinerary)
 {
    return new Delivery(LastEvent, itinerary, specification);
 }
Example #33
0
 /// <summary>
 /// Creates a new delivery snapshot based only on route specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public static Delivery DerivedFrom(RouteSpecification specification, Itinerary itinerary)
 {
     return(new Delivery(null, itinerary, specification));
 }
 public CargoDestinationChangedEvent(Cargo cargo, RouteSpecification oldSpecification, RouteSpecification newSpecification, Delivery delivery)
 {
     _cargo            = cargo;
     _delivery         = delivery;
     _newSpecification = newSpecification;
     _oldSpecification = oldSpecification;
 }
 public CargoRegisteredEvent(TrackingId trackingId, RouteSpecification routeSpecification, Delivery delivery)
 {
     RouteSpecification = routeSpecification;
     TrackingId         = trackingId;
     Delivery           = delivery;
 }
Example #36
0
 /// <summary>
 /// Creates a new delivery snapshot based on the previous (current) one and (possibly changed)
 /// specification and itinerary.
 /// </summary>
 /// <param name="specification">Current route specification.</param>
 /// <param name="itinerary">Current itinerary.</param>
 /// <returns>Delivery status description.</returns>
 public Delivery Derive(RouteSpecification specification, Itinerary itinerary)
 {
     return(new Delivery(_lastEvent, itinerary, specification));
 }
Example #37
0
 private void OnCargoDestinationChanged(CargoDestinationChangedEvent @event)
 {
     _routeSpecification = @event.NewSpecification;
     _deliveryStatus     = @event.Delivery;
 }
Example #38
0
 public IList<Itinerary> FetchRoutesForSpecification(RouteSpecification routeSpecification)
 {
    return GetAllPossibleRoutes(routeSpecification).ToList();         
 }
Example #39
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(_lastEvent, itinerary, routeSpecification);
 }
Example #40
0
 private void OnCargoRegistered(CargoRegisteredEvent @event)
 {
     _trackingId         = @event.TrackingId;
     _routeSpecification = @event.RouteSpecification;
     _deliveryStatus     = @event.Delivery;
 }
Example #41
0
        private Delivery(HandlingEvent lastHandlingEvent, Itinerary itinerary, RouteSpecification specification)
        {
            _calculatedAt = DateTime.Now;
            _lastEvent = lastHandlingEvent;

            _misdirected = CalculateMisdirectionStatus(LastEvent, itinerary);
            _routingStatus = CalculateRoutingStatus(itinerary, specification);
            _transportStatus = CalculateTransportStatus(LastEvent);
            _lastKnownLocation = CalculateLastKnownLocation(LastEvent);
            _eta = CalculateEta(itinerary);
            _nextExpectedActivity = CalculateNextExpectedActivity(LastEvent, specification, itinerary);
            _isUnloadedAtDestination = CalculateUnloadedAtDestination(LastEvent, specification);
        }
Example #42
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);
      }
Example #43
0
 private static bool CalculateUnloadedAtDestination(HandlingEvent lastEvent, RouteSpecification specification)
 {
     return lastEvent != null &&
              lastEvent.EventType == HandlingEventType.Unload &&
              specification.Destination == lastEvent.Location;
 }
Example #44
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;
            }
        }
Example #45
0
 private static RoutingStatus CalculateRoutingStatus(Itinerary itinerary, RouteSpecification specification)
 {
     if (itinerary == null)
     {
         return RoutingStatus.NotRouted;
     }
     return specification.IsSatisfiedBy(itinerary) ? RoutingStatus.Routed : RoutingStatus.Misrouted;
 }
Example #46
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));
 }
Example #47
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);
 }
Example #48
0
 private void OnCargoDestinationChanged(CargoDestinationChangedEvent @event)
 {
    _routeSpecification = @event.NewSpecification;
    _deliveryStatus = @event.Delivery;
 }
Example #49
0
 public CargoRegisteredEvent(Cargo cargo, RouteSpecification routeSpecification, Delivery delivery)
 {
     _cargo = cargo;
     _routeSpecification = routeSpecification;
     _delivery           = delivery;
 }
      public void CanTransportFromHongkongToStockholm()
      {
         /* Test setup: A cargo should be shipped from Hongkong to Stockholm,
            and it should arrive in no more than two weeks. */
         Location origin = HONGKONG;
         Location destination = STOCKHOLM;
         DateTime arrivalDeadline = new DateTime(2009, 3, 18);

         /* Use case 1: booking

            A new cargo is booked, and the unique tracking id is assigned to the cargo. */
         TrackingId trackingId = BookingService.BookNewCargo(
            origin.UnLocode, destination.UnLocode, arrivalDeadline
            );

         /* The tracking id can be used to lookup the cargo in the repository.

            Important: The cargo, and thus the domain model, is responsible for determining
            the status of the cargo, whether it is on the right track or not and so on.
            This is core domain logic.

            Tracking the cargo basically amounts to presenting information extracted from
            the cargo aggregate in a suitable way. */
         Cargo cargo = CargoRepository.Find(trackingId);
         Assert.IsNotNull(cargo);
         Assert.AreEqual(TransportStatus.NotReceived, cargo.Delivery.TransportStatus);
         Assert.AreEqual(RoutingStatus.NotRouted, cargo.Delivery.RoutingStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         Assert.IsNull(cargo.Delivery.EstimatedTimeOfArrival);
         //Assert.IsNull(cargo.Delivery.NextExpectedActivity);

         /* Use case 2: routing

            A number of possible routes for this cargo is requested and may be
            presented to the customer in some way for him/her to choose from.
            Selection could be affected by things like price and time of delivery,
            but this test simply uses an arbitrary selection to mimic that process.

            The cargo is then assigned to the selected route, described by an itinerary. */
         IList<Itinerary> itineraries = BookingService.RequestPossibleRoutesForCargo(trackingId);
         Itinerary itinerary = SelectPreferedItinerary(itineraries);
         cargo.AssignToRoute(itinerary);

         Assert.AreEqual(TransportStatus.NotReceived, cargo.Delivery.TransportStatus);
         Assert.AreEqual(RoutingStatus.Routed, cargo.Delivery.RoutingStatus);
         Assert.IsNotNull(cargo.Delivery.EstimatedTimeOfArrival);
         //Assert.AreEqual(new HandlingActivity(RECEIVE, HONGKONG), cargo.Delivery.nextExpectedActivity());

         /*
           Use case 3: handling

           A handling event registration attempt will be formed from parsing
           the data coming in as a handling report either via
           the web service interface or as an uploaded CSV file.

           The handling event factory tries to create a HandlingEvent from the attempt,
           and if the factory decides that this is a plausible handling event, it is stored.
           If the attempt is invalid, for example if no cargo exists for the specfied tracking id,
           the attempt is rejected.

           Handling begins: cargo is received in Hongkong.
           */
         HandlingEventService.RegisterHandlingEvent(
            new DateTime(2009, 3, 1), trackingId, HONGKONG.UnLocode, HandlingEventType.Receive
            );

         Assert.AreEqual(TransportStatus.InPort, cargo.Delivery.TransportStatus);
         Assert.AreEqual(HONGKONG, cargo.Delivery.LastKnownLocation);

         // Next event: Load onto voyage CM003 in Hongkong
         HandlingEventService.RegisterHandlingEvent(
            new DateTime(2009, 3, 3), trackingId, HONGKONG.UnLocode, HandlingEventType.Load
            );

         // Check current state - should be ok
         //Assert.AreEqual(v100, cargo.Delivery.currentVoyage());
         Assert.AreEqual(HONGKONG, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.OnboardCarrier, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.AreEqual(new HandlingActivity(UNLOAD, NEWYORK, v100), cargo.Delivery.nextExpectedActivity());


         /*
           Here's an attempt to register a handling event that's not valid
           because there is no voyage with the specified voyage number,
           and there's no location with the specified UN Locode either.

           This attempt will be rejected and will not affect the cargo delivery in any way.
          */
         //VoyageNumber noSuchVoyageNumber = new VoyageNumber("XX000");
         //UnLocode noSuchUnLocode = new UnLocode("ZZZZZ");
         //try
         //{
         //   HandlingEventService.RegisterHandlingEvent(
         //   new DateTime(2009, 3, 5), trackingId, noSuchUnLocode, HandlingEventType.Load
         //   );
         //   Assert.Fail("Should not be able to register a handling event with invalid location and voyage");
         //}
         //catch (ArgumentException)
         //{
         //}


         // Cargo is now (incorrectly) unloaded in Tokyo
         HandlingEventService.RegisterHandlingEvent(
            new DateTime(2009, 3, 5), trackingId, TOKYO.UnLocode, HandlingEventType.Unload
            );

         // Check current state - cargo is misdirected!
         //Assert.AreEqual(NONE, cargo.Delivery.currentVoyage());
         Assert.AreEqual(TOKYO, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.InPort, cargo.Delivery.TransportStatus);
         Assert.IsTrue(cargo.Delivery.IsMisdirected);
         //Assert.IsNull(cargo.Delivery.nextExpectedActivity());


         // -- Cargo needs to be rerouted --

         // TODO cleaner reroute from "earliest location from where the new route originates"

         // Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
         RouteSpecification fromTokyo = new RouteSpecification(TOKYO, STOCKHOLM, arrivalDeadline);
         cargo.SpecifyNewRoute(fromTokyo);

         // The old itinerary does not satisfy the new specification
         Assert.AreEqual(RoutingStatus.Misrouted, cargo.Delivery.RoutingStatus);
         //Assert.IsNull(cargo.Delivery.nextExpectedActivity());

         // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
         IList<Itinerary> newItineraries = BookingService.RequestPossibleRoutesForCargo(cargo.TrackingId);
         Itinerary newItinerary = SelectPreferedItinerary(newItineraries);
         cargo.AssignToRoute(newItinerary);

         // New itinerary should satisfy new route
         Assert.AreEqual(RoutingStatus.Routed, cargo.Delivery.RoutingStatus);

         // TODO we can't handle the face that after a reroute, the cargo isn't misdirected anymore
         //Assert.IsFalse(cargo.isMisdirected());
         //Assert.AreEqual(new HandlingActivity(LOAD, TOKYO), cargo.nextExpectedActivity());


         // -- Cargo has been rerouted, shipping continues --


         // Load in Tokyo
         HandlingEventService.RegisterHandlingEvent(new DateTime(2009, 3, 8), trackingId, TOKYO.UnLocode, HandlingEventType.Load);

         // Check current state - should be ok
         //Assert.AreEqual(v300, cargo.Delivery.currentVoyage());
         Assert.AreEqual(TOKYO, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.OnboardCarrier, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.AreEqual(new HandlingActivity(UNLOAD, HAMBURG, v300), cargo.Delivery.nextExpectedActivity());

         // Unload in Hamburg
         HandlingEventService.RegisterHandlingEvent(new DateTime(2009, 3, 12), trackingId, HAMBURG.UnLocode, HandlingEventType.Unload);

         // Check current state - should be ok
         //Assert.AreEqual(NONE, cargo.Delivery.currentVoyage());
         Assert.AreEqual(HAMBURG, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.InPort, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.AreEqual(new HandlingActivity(LOAD, HAMBURG, v400), cargo.Delivery.nextExpectedActivity());


         // Load in Hamburg
         HandlingEventService.RegisterHandlingEvent(new DateTime(2009, 3, 14), trackingId, HAMBURG.UnLocode, HandlingEventType.Load);

         // Check current state - should be ok
         //Assert.AreEqual(v400, cargo.Delivery.currentVoyage());
         Assert.AreEqual(HAMBURG, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.OnboardCarrier, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.AreEqual(new HandlingActivity(UNLOAD, STOCKHOLM, v400), cargo.Delivery.nextExpectedActivity());


         // Unload in Stockholm
         HandlingEventService.RegisterHandlingEvent(new DateTime(2009, 3, 15), trackingId, STOCKHOLM.UnLocode, HandlingEventType.Unload);

         // Check current state - should be ok
         //Assert.AreEqual(NONE, cargo.Delivery.currentVoyage());
         Assert.AreEqual(STOCKHOLM, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.InPort, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.AreEqual(new HandlingActivity(CLAIM, STOCKHOLM), cargo.Delivery.nextExpectedActivity());

         // Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
         HandlingEventService.RegisterHandlingEvent(new DateTime(2009, 3, 16), trackingId, STOCKHOLM.UnLocode, HandlingEventType.Claim);

         // Check current state - should be ok
         //Assert.AreEqual(NONE, cargo.Delivery.currentVoyage());
         Assert.AreEqual(STOCKHOLM, cargo.Delivery.LastKnownLocation);
         Assert.AreEqual(TransportStatus.Claimed, cargo.Delivery.TransportStatus);
         Assert.IsFalse(cargo.Delivery.IsMisdirected);
         //Assert.IsNull(cargo.Delivery.nextExpectedActivity());
      }
Example #51
0
 private void OnCargoRegistered(CargoRegisteredEvent @event)
 {
    _trackingId = @event.TrackingId;
    _routeSpecification = @event.RouteSpecification;
    _deliveryStatus = @event.Delivery;
 }