Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cargo">cargo</param>
        /// <param name="completionTime">completion time, the reported time that the event actually happened (e.g. the receive took place).</param>
        /// <param name="registrationTime">registration time, the time the message is received</param>
        /// <param name="eventType">type of event</param>
        /// <param name="location">where the event took place</param>
        /// <param name="voyage">the voyage</param>
        public HandlingEvent(Cargo cargo,
                             DateTime completionTime,
                             DateTime registrationTime,
                             HandlingType eventType,
                             Location location,
                             Voyage voyage)
        {
            Validate.NotNull(cargo, "Cargo is required");
            Validate.NotNull(completionTime, "Completion time is required");
            Validate.NotNull(registrationTime, "Registration time is required");
            Validate.NotNull(eventType, "Handling event eventType is required");
            Validate.NotNull(location, "Location is required");
            Validate.NotNull(voyage, "Voyage is required");

            if (eventType.ProhibitsVoyage())
            {
                throw new ArgumentException("Voyage is not allowed with event eventType " + eventType);
            }

            this.voyage           = voyage;
            this.completionTime   = completionTime;
            this.registrationTime = registrationTime;
            type          = eventType;
            this.location = location;
            this.cargo    = cargo;
        }
Esempio n. 2
0
        public HandlingEvent(Cargo cargo,
                             DateTime completionTime,
                             DateTime registrationTime,
                             HandlingType type,
                             Location location)
        {
            Validate.NotNull(cargo, "Cargo is required");
            Validate.NotNull(completionTime, "Completion time is required");
            Validate.NotNull(registrationTime, "Registration time is required");
            Validate.NotNull(type, "Handling event type is required");
            Validate.NotNull(location, "Location is required");

            if (type.RequiresVoyage())
            {
                throw new ArgumentException("Voyage is required for event type " + type);
            }

            this.completionTime   = completionTime;
            this.registrationTime = registrationTime;
            this.type             = type;
            this.locationId       = location.id;
            this.cargoId          = cargo.id;
            this.location         = location;
            this.cargo            = cargo;
            voyage = null;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates handling event
        /// throws UnknownVoyageException   if there's no voyage with this number
        /// throws UnknownCargoException    if there's no cargo with this tracking id
        /// throws UnknownLocationException if there's no location with this UN Locode
        /// </summary>
        /// <param name="registrationTime"> time when this event was received by the system</param>
        /// <param name="completionTime">when the event was completed, for example finished loading</param>
        /// <param name="trackingId">cargo tracking id</param>
        /// <param name="voyageNumber">voyage number</param>
        /// <param name="unlocode">United Nations Location Code for the location of the event</param>
        /// <param name="type">type of event</param>
        /// <returns> A handling event.</returns>
        public HandlingEvent CreateHandlingEvent(DateTime registrationTime, DateTime completionTime,
                                                 TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode,
                                                 HandlingType type)
        {
            Cargo    cargo    = FindCargo(trackingId);
            Voyage   voyage   = FindVoyage(voyageNumber);
            Location location = FindLocation(unlocode);

            try
            {
                if (voyage == null)
                {
                    return(new HandlingEvent(cargo, completionTime, registrationTime, type, location));
                }

                return(new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage));
            }
            catch (Exception e)
            {
                throw new CannotCreateHandlingEventException(e);
            }
        }