/// <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="type">type of event</param> /// <param name="location">where the event took place</param> /// <param name="voyage">the voyage</param> /// <param name="operatorCode">operator code for port operator</param> internal HandlingEvent(Cargo cargo, DateTime completionTime, DateTime registrationTime, HandlingActivityType type, Location location, Voyage voyage, OperatorCode operatorCode) { Validate.notNull(cargo, "Cargo is required"); Validate.notNull(location, "Location is required"); Validate.notNull(voyage, "Voyage is required"); Validate.notNull(operatorCode, "Operator code is required"); if (!type.isVoyageRelated()) { throw new ArgumentException("Voyage is not allowed with event type " + type); } SequenceNumber = EventSequenceNumber.Next(); Cargo = cargo; CompletionTime = completionTime; RegistrationTime = registrationTime; Activity = new HandlingActivity(type, location, voyage); OperatorCode = operatorCode; }
/// <summary> /// Creates a handling event. /// </summary> /// <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> /// <param name="operatorCode">operator code</param> /// <returns>A handling event.</returns> /// <exception cref="UnknownVoyageException">if there's no voyage with this number</exception> /// <exception cref="UnknownCargoException">if there's no cargo with this tracking id</exception> /// <exception cref="UnknownLocationException">if there's no location with this UN Locode</exception> public HandlingEvent createHandlingEvent(DateTime completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingActivityType type, OperatorCode operatorCode) { var cargo = findCargo(trackingId); var voyage = findVoyage(voyageNumber); var location = findLocation(unlocode); try { var registrationTime = DateTime.Now; if (voyage == null) { return(new HandlingEvent(cargo, completionTime, registrationTime, type, location)); } else { return(new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode)); } } catch (Exception e) { throw new CannotCreateHandlingEventException(e.Message, e); } }