Example #1
0
 public HandlingEvent(Book book, LibraryAccount account, Library library, HandlingType handlingType) : base(Guid.NewGuid())
 {
     Assert.IsValid(book);
     Assert.IsValid(account);
     Assert.IsValid(library);
     OnEvent(new HandlingEventCreated(Id, book.Id, account.Id, library.Id, handlingType, DateTime.Now));
 }
Example #2
0
        public void SubmitReport(HandlingReport handlingReport)
        {
            IList <string> errors = new List <string>();

            DateTime?    completionTime = HandlingReportParser.ParseCompletionTime(handlingReport, errors);
            VoyageNumber voyageNumber   = HandlingReportParser.ParseVoyageNumber(handlingReport.VoyageNumber, errors);
            HandlingType type           = HandlingReportParser.ParseEventType(handlingReport.Type, errors);
            UnLocode     unLocode       = HandlingReportParser.ParseUnLocode(handlingReport.UnLocode, errors);

            foreach (string trackingIdStr in handlingReport.TrackingIds)
            {
                TrackingId trackingId = HandlingReportParser.ParseTrackingId(trackingIdStr, errors);

                if (errors.IsEmpty())
                {
                    DateTime registrationTime = DateTime.Now;
                    var      attempt          = new HandlingEventRegistrationAttempt(
                        registrationTime, completionTime.Value, trackingId, voyageNumber, type, unLocode);
                    applicationEvents.ReceivedHandlingEventRegistrationAttempt(attempt);
                }
                else
                {
                    string errorString = String.Join("\r\n", errors.ToArray());
                    logger.Error("Parse error in handling report: " + errorString);

                    throw new FaultException <HandlingReportException>(new HandlingReportException(errorString), new FaultReason(errorString));
                }
            }
        }
Example #3
0
        public String GetNextExpectedActivity()
        {
            HandlingActivity activity = cargo.Delivery.NextExpectedActivity;

            if (activity == null)
            {
                return("");
            }

            //TODO: atrosin refactor repetead string format\concatination
            string       text = "Next expected activity is to ";
            HandlingType type = activity.Type;

            if (type.SameValueAs(HandlingType.LOAD))
            {
                return
                    (text + type.DisplayName.ToLower() + " cargo into voyage " + activity.Voyage.VoyageNumber +
                     " in " + activity.Location.Name);
            }
            else if (type.SameValueAs(HandlingType.UNLOAD))
            {
                return
                    (text + type.DisplayName.ToLower() + " cargo off of " + activity.Voyage.VoyageNumber +
                     " in " + activity.Location.Name);
            }
            else
            {
                return(text + type.DisplayName.ToLower() + " cargo in " + activity.Location.Name);
            }
        }
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
               it is determined wether the incoming data, the attempt, actually is capable
               of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                   state of the handling event aggregate (but not the cargo aggregate -
                   that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
        public void RegisterHandlingEvent(DateTime completionTime,
                                          TrackingId trackingId,
                                          VoyageNumber voyageNumber,
                                          UnLocode unLocode,
                                          HandlingType type)
        {
            //TODO: Revise transaciton and UoW logic
            using (var transactionScope = new TransactionScope())
            {
                var registrationTime = new DateTime();

                /* Using a factory to create a HandlingEvent (aggregate). This is where
                 * it is determined wether the incoming data, the attempt, actually is capable
                 * of representing a real handling event. */
                HandlingEvent evnt = handlingEventFactory.CreateHandlingEvent(
                    registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

                /* Store the new handling event, which updates the persistent
                 * state of the handling event aggregate (but not the cargo aggregate -
                 * that happens asynchronously!)*/

                handlingEventRepository.Store(evnt);

                /* Publish an event stating that a cargo has been handled. */
                applicationEvents.CargoWasHandled(evnt);

                transactionScope.Complete();
            }
            logger.Info("Registered handling event");
        }
        public HandlingActivity(HandlingType type, Location location)
        {
            Validate.NotNull(type, "Handling event type is required");
            Validate.NotNull(location, "Location is required");

            this.type     = type;
            this.location = location;
        }
Example #7
0
 public HandlingEventCreated(Guid id, Guid bookId, Guid accountId, Guid libraryId, HandlingType handlingType, DateTime time)
 {
     Id           = id;
     BookId       = bookId;
     AccountId    = accountId;
     LibraryId    = libraryId;
     HandlingType = handlingType;
     Time         = time;
 }
Example #8
0
 private void SetOmitHandlingType()
 {
     handlingType = HandlingType.Omit;
     Piet.Dispatcher.handlingType = HandlingType.Omit;
     cutOffImage.Source           = new BitmapImage(new Uri("/resources/Columns_Deselected.png", UriKind.Relative));
     cutOffImageLabel.Foreground  = System.Windows.Application.Current.FindResource("ColumnsRowsDeselectedTextColor") as SolidColorBrush;
     omitImage.Source             = new BitmapImage(new Uri("/resources/Omit_Selected.png", UriKind.Relative));
     omitImageLabel.Foreground    = System.Windows.Application.Current.FindResource("ColumnsRowsSelectedTextColor") as SolidColorBrush;
 }
Example #9
0
 public Lane(int x, int y, Measure laneMaxMeasure, int offsetSize, ArrangementMode arrangementMode, int cornerRadius, HandlingType handlingType)
 {
     this.x = x;
     this.y = y;
     this.laneMaxMeasure  = laneMaxMeasure;
     this.offsetSize      = offsetSize;
     this.arrangementMode = arrangementMode;
     this.cornerRadius    = cornerRadius;
     this.handlingType    = handlingType;
 }
Example #10
0
 public HandlingEventRegistrationAttempt(DateTime registrationDate,
                                         DateTime completionDate,
                                         TrackingId trackingId,
                                         VoyageNumber voyageNumber,
                                         HandlingType type,
                                         UnLocode unLocode)
 {
     registrationTime  = registrationDate;
     completionTime    = completionDate;
     this.trackingId   = trackingId;
     this.voyageNumber = voyageNumber;
     this.type         = type;
     this.unLocode     = unLocode;
 }
 public HandlingEventRegistrationAttempt(DateTime registrationDate,
     DateTime completionDate,
     TrackingId trackingId,
     VoyageNumber voyageNumber,
     HandlingType type,
     UnLocode unLocode)
 {
     registrationTime = registrationDate;
     completionTime = completionDate;
     this.trackingId = trackingId;
     this.voyageNumber = voyageNumber;
     this.type = type;
     this.unLocode = unLocode;
 }
Example #12
0
 public Grid(int lanesNum, ArrangementMode arrangementMode, HandlingType handlingType, List <String> imageFilePaths, int offsetSize, int[] offsetColor, int cornerRadius)
 {
     this.lanesNum         = lanesNum;
     this.arrangementMode  = arrangementMode;
     this.imageFilePaths   = imageFilePaths;
     this.offsetSize       = offsetSize;
     this.offsetColor      = offsetColor;
     this.handlingType     = handlingType;
     this.cornerRadius     = cornerRadius;
     (maxWidth, maxHeight) = GetMaxScreenSize();
     this.laneMaxMeasure   = arrangementMode == ArrangementMode.Column
         ? new Measure((maxWidth - (lanesNum + 1) * offsetSize) / lanesNum, maxHeight)
         : new Measure(maxWidth, (maxHeight - (lanesNum + 1) * offsetSize) / lanesNum);
     lanes = InitializeLanes();
     imageFilePaths.Shuffle();
 }
        private void AssertHandlingEvent(Cargo cargo, HandlingEvent evnt, HandlingType expectedEventType,
                                         Location expectedLocation, int completionTimeMs, int registrationTimeMs,
                                         Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, evnt.Type);
            Assert.AreEqual(expectedLocation, evnt.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.Offset(completionTimeMs);
            Assert.AreEqual(expectedCompletionTime, evnt.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.Offset(registrationTimeMs);
            Assert.AreEqual(expectedRegistrationTime, evnt.RegistrationTime);

            Assert.AreEqual(voyage, evnt.Voyage);
            Assert.AreEqual(cargo, evnt.Cargo);
        }
Example #14
0
        private void SetInitialValuesFromSettingPage()
        {
            offsetSize = Properties.Settings.Default.offsetSize;

            var handlingTypeSettings = Properties.Settings.Default.handlingType;

            handlingType = Enum.IsDefined(typeof(HandlingType), handlingTypeSettings)
                ? (HandlingType)handlingTypeSettings
                : HandlingType.Omit;

            Color color = ((SolidColorBrush) new BrushConverter().ConvertFromString(Properties.Settings.Default.offsetBackgroundColor)).Color;

            offsetColor = new int[] { color.R, color.G, color.B };

            cornerRadius = Properties.Settings.Default.imageCornerRadius;
        }
 public void Ctor__NoTrackingIdGiven__ThrowsArgumentNullException(
     HandlingType type,
     UnLocode location,
     VoyageNumber voyage,
     DateTime completed,
     DateTime registered
     )
 {
     Assert.Throws <ArgumentNullException>(() => new HandlingEvent(
                                               null,
                                               type,
                                               location,
                                               voyage,
                                               completed,
                                               registered
                                               ));
 }
Example #16
0
        public void IsExpected__EventClaimsOrCustomGiven_AtFinalUnloadingLocation__ReturnsTrue(
            HandlingType type)
        {
            // ARRANGE
            var sut = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            var eventFixture = new Fixture();

            eventFixture.Customizations.Add(new HandlingEventBuilder().With(type).With(sut.LastUnloadLocation));
            var @event = eventFixture.Create <HandlingEvent>();

            // ACT
            var r = sut.IsExpected(@event);

            // ASSERT
            Assert.True(r);
        }
 public void Ctor__NoLocationGiven__ThrowsArgumentNullException(
     TrackingId trackingId,
     HandlingType type,
     VoyageNumber voyage,
     DateTime completed,
     DateTime registered
     )
 {
     Assert.Throws <ArgumentNullException>(() => new HandlingEvent(
                                               trackingId,
                                               type,
                                               null,
                                               voyage,
                                               completed,
                                               registered
                                               ));
 }
 public void Ctor__UnloadOrLoadAndNoVoyage__ThrowsArgumentNullException(
     HandlingType type,
     TrackingId trackingId,
     UnLocode location,
     DateTime completed,
     DateTime registered
     )
 {
     Assert.Throws <InvalidOperationException>(() => new HandlingEvent(
                                                   trackingId,
                                                   type,
                                                   location,
                                                   null,
                                                   completed,
                                                   registered
                                                   ));
 }
Example #19
0
        private void AssertHandlingEvent(Cargo cargo, HandlingEvent evnt, HandlingType expectedEventType,
                                         Location expectedLocation, int completionTimeMs, int registrationTimeMs,
                                         Voyage voyage)
        {
            Assert.AreEqual(expectedEventType, evnt.Type);
            Assert.AreEqual(expectedLocation, evnt.Location);

            DateTime expectedCompletionTime = SampleDataGenerator.Offset(completionTimeMs);

            Assert.AreEqual(expectedCompletionTime, evnt.CompletionTime);

            DateTime expectedRegistrationTime = SampleDataGenerator.Offset(registrationTimeMs);

            Assert.AreEqual(expectedRegistrationTime, evnt.RegistrationTime);

            Assert.AreEqual(voyage, evnt.Voyage);
            Assert.AreEqual(cargo, evnt.Cargo);
        }
Example #20
0
        public void Ctor__EventWithNoVoyageNumber__CurrentVoyageSetToNone(
            HandlingType type
            , RouteSpecification routeSpec)
        {
            // ARRANGE
            var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            var eventFixture = new Fixture();

            eventFixture.Customizations.Add(new HandlingEventBuilder().With(type).With((VoyageNumber)null));

            var @event = eventFixture.Create <HandlingEvent>();

            // ACT
            var sut = new Delivery(routeSpec, itinerary, @event);

            // ASSERT
            Assert.Null(sut.CurrentVoyage);
        }
Example #21
0
        public HandlingActivity(HandlingType type
                                , UnLocode location
                                , VoyageNumber voyage)
        {
            Location = location ?? throw new ArgumentNullException(nameof(location));

            if (type == HandlingType.Load && voyage == null)
            {
                throw new InvalidOperationException("a load activity needs a voyage");
            }

            if (type == HandlingType.Unload && voyage == null)
            {
                throw new InvalidOperationException("an unload activity needs a voyage");
            }

            Type   = type;
            Voyage = voyage;
        }
Example #22
0
        public void Ctor__HandlingTypeMappedToTransportStatusCorrectly(
            HandlingType type
            , TransportStatus status)
        {
            // ARRANGE
            var routeSpec = new Fixture().Create <RouteSpecification>();
            var itinerary = new Fixture().Customize(new DefaultItineraryCustomization()).Create <Itinerary>();

            var eventFixture = new Fixture();

            eventFixture.Customizations.Add(new HandlingEventBuilder().With(type));
            var @event = eventFixture.Create <HandlingEvent>();

            // ACT
            var sut = new Delivery(routeSpec, itinerary, @event);

            // ASSERT
            Assert.Equal(status, sut.TransportStatus);
        }
Example #23
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);
            }
        }
Example #24
0
        private void QueueAttempt(string completionTimeStr, string trackingIdStr, string voyageNumberStr,
                                  string unLocodeStr, string eventTypeStr)
        {
            var errors = new List <string>();

            DateTime     date         = HandlingReportParser.ParseDate(completionTimeStr, errors);
            TrackingId   trackingId   = HandlingReportParser.ParseTrackingId(trackingIdStr, errors);
            VoyageNumber voyageNumber = HandlingReportParser.ParseVoyageNumber(voyageNumberStr, errors);
            HandlingType eventType    = HandlingReportParser.ParseEventType(eventTypeStr, errors);
            UnLocode     unLocode     = HandlingReportParser.ParseUnLocode(unLocodeStr, errors);

            if (errors.IsEmpty())
            {
                var attempt = new HandlingEventRegistrationAttempt(DateTime.Now, date,
                                                                   trackingId, voyageNumber,
                                                                   eventType, unLocode);
                AppEvents.ReceivedHandlingEventRegistrationAttempt(attempt);
            }
            else
            {
                throw new Exception(ToStringBuilder.ReflectionToString(errors));
            }
        }
Example #25
0
        public HandlingEvent(
            TrackingId trackingId
            , HandlingType type
            , UnLocode location
            , VoyageNumber voyage
            , DateTime completed
            , DateTime registered)
        {
            if ((type == HandlingType.Load || type == HandlingType.Unload)
                &&
                (voyage == null)
                )
            {
                throw new InvalidOperationException("loading/unloading events need a voyage");
            }

            TrackingId = trackingId ?? throw new ArgumentNullException(nameof(trackingId));
            Location   = location ?? throw new ArgumentNullException(nameof(location));
            Type       = type;
            Voyage     = voyage;
            Completed  = completed;
            Registered = registered;
        }
Example #26
0
        private void SetSettingsValues()
        {
            offsetSize = Properties.Settings.Default.offsetSize;
            offsetSizeBox.SetValue(offsetSize);
            Piet.Dispatcher.offsetSize = offsetSize;

            var handlingTypeSettings = Properties.Settings.Default.handlingType;

            handlingType = Enum.IsDefined(typeof(HandlingType), handlingTypeSettings)
                ? (HandlingType)handlingTypeSettings
                : HandlingType.Omit;
            if (handlingType == HandlingType.Omit)
            {
                SetOmitHandlingType();
            }
            else
            {
                SetCutOffHandlingType();
            }

            offsetBackgroundColor        = Properties.Settings.Default.offsetBackgroundColor;
            colorToggleButton.Background = (SolidColorBrush) new BrushConverter().ConvertFromString(offsetBackgroundColor);

            cornerRadius = Properties.Settings.Default.imageCornerRadius;
            imageCornerRadiusBox.SetValue(cornerRadius);
            Piet.Dispatcher.cornerRadius = cornerRadius;

            runOnStartup = Properties.Settings.Default.runOnStartup;
            if (runOnStartup)
            {
                SetRunOnStartupEnabled();
            }
            else
            {
                SetRunOnStartupDisabled();
            }
        }
 public HandlingEventBuilder With(HandlingType type)
 {
     _typeSet = true;
     Type     = type;
     return(this);
 }
Example #28
0
 public HandlingEvent(Book book, LibraryAccount account, Library library, HandlingType handlingType) : base(Guid.NewGuid())
 {
     OnEventHappened(new HandlingEventCreated(Id, book.Id, account.Id, library.Id, handlingType, DateTime.Now));
 }