private static void AssignCargoToRoute(TrackingId trackingId, RouteCandidateDTO selectedRoute)
        {
            var assignToRouteCommand = new AssignCargoToRouteCommand()
            {
                Route      = selectedRoute,
                TrackingId = trackingId.IdString
            };

            CommandPipeline.Process(assignToRouteCommand);
        }
Esempio n. 2
0
        internal Options(ICommandRegistry commandRegistry, IHandlerFactory handlerFactory, CommandPipeline commandPipeline)
        {
            Guard.EnsureNotNull(commandRegistry, nameof(commandRegistry));
            Guard.EnsureNotNull(handlerFactory, nameof(handlerFactory));
            Guard.EnsureNotNull(commandPipeline, nameof(commandPipeline));

            CommandRegistry = commandRegistry;
            HandlerFactory  = handlerFactory;
            CommandPipeline = commandPipeline;
        }
Esempio n. 3
0
        internal HttpOptions(string commandPath, ICommandRegistry commandRegistry, IHandlerFactory handlerFactory, ICommandNameResolver commandNameResolver, CommandFactory commandFactory, CommandPipeline commandPipeline)
            : base(commandRegistry, handlerFactory, commandPipeline)
        {
            Guard.EnsureNotNullOrWhitespace(commandPath, nameof(commandPath));
            Guard.EnsureNotNull(commandNameResolver, nameof(commandNameResolver));
            Guard.EnsureNotNull(commandFactory, nameof(commandFactory));

            CommandPath = commandPath;
            CommandNameResolver = commandNameResolver;
            CommandFactory = commandFactory;
        }
        private static void RegisterHandlingEvent(DateTime completionTime, TrackingId trackingId, UnLocode occuranceLocation, HandlingEventType handlingEventType)
        {
            var registerHandlingEventCommand = new RegisterHandlingEventCommand()
            {
                CompletionTime    = completionTime,
                OccuranceLocation = occuranceLocation.CodeString,
                TrackingId        = trackingId.IdString,
                Type = handlingEventType
            };

            CommandPipeline.Process(registerHandlingEventCommand);
        }
        private static IEnumerable <RouteCandidateDTO> RequestPossibleRoutesForCargo(TrackingId trackingId)
        {
            var requestPossibleRoutesForCargoCommand
                = new RequestPossibleRoutesForCargoCommand
                {
                TrackingId = trackingId.IdString
                };

            var result = (RequestPossibleRoutesForCargoCommandResult)CommandPipeline.Process(requestPossibleRoutesForCargoCommand);

            return(result.RouteCandidates);
        }
Esempio n. 6
0
        protected CommandPipeline CreateCommandPipeline()
        {
            var commandPipeline = new CommandPipeline(new ExclusiveHandlerCommandBus(handlerFactory));

            if (configurePipeline != null)
            {
                var pipelineRoot = configurePipeline(commandPipeline);
                commandPipeline.SetRoot(pipelineRoot);
            }

            commandPipeline.IssueCommand.Next = postProcessPipelineStage;
            return(commandPipeline);
        }
        public void Dispatch_should_only_handle_appropriate_request_methods(string requestMethod, Type expectedResultType)
        {
            // Given a POST FooRequest CommandPipeline
            CommandPipeline <FooRequest> pipeline = new CommandPipeline <FooRequest>(HttpVerb.Post, new TestFooHandler());

            // And an HttpContext for a GET operation
            HttpContext httpContext = new DefaultHttpContext();

            httpContext.Request.Method = requestMethod;

            // When I try to dispatch a FooRequest
            FooRequest     request       = new FooRequest();
            IHandlerResult handlerResult = pipeline.Dispatch(httpContext, request);

            // Then the pipeline should not handle the request
            handlerResult.Should().BeOfType(expectedResultType);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Processes the specified context.
        /// </summary>
        /// <param name="context">
        ///  The context.
        /// </param>
        /// <returns>
        ///  The ContinuationStatus.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public ContinuationStatus Process(ExecutionCommandContext <T> context)
        {
            DebugContract.Requires(context, "context");

            var pipe = new CommandPipeline(context, _handler);

            // Cette info est activée lors du chargement des metadonnées d'un domainModel.
            // Il n'est pas possible d'activer des rules sur les métadonnées.
            var skipRules = (Session.Current.Mode & SessionMode.SkipInterceptors) == SessionMode.SkipInterceptors;

            // Preconditions
            if (_interceptors != null && !skipRules)
            {
                pipe.Register(GetInterceptorsFor(context.CurrentSession, context.Command).ToList());
            }

            return(pipe.Execute());
        }
        public void Run()
        {
            Event[] updateEvents = null;
            var     es           = new MockEventStore();
            var     sut          = new CommandPipeline(es, Load, Process_with_notifications, Update);

            var cmd = new MyCommand {
                Parameter = "123"
            };
            var result = sut.Handle(cmd);

            Assert.IsType <Success>(result.Msg);
            Assert.Equal(2, es.Events.Count);
            Assert.Equal("54321", (es.Events[0] as MyEvent).Reversed);
            Assert.Equal(5, (es.Events[1] as YourEvent).Count);
            Assert.Equal(2, updateEvents.Length);
            Assert.IsType <MyNotification>(result.Notifications[0]);


            (CommandStatus, Event[], string, Notification[]) Process_with_notifications(IMessage msg, IMessageContextModel ctx, string version)
Esempio n. 10
0
        internal void AddRoute <TRequest>(HttpVerb verb, string routeTemplate, Type[] commandHandlerTypes)
        {
            // Instanciate concrete instances for each handler in the command pipeline
            CommandPipeline <TRequest> pipeline = new CommandPipeline <TRequest>(verb);

            foreach (Type handlerType in commandHandlerTypes)
            {
                var handler = (ICommandHandler <TRequest>)ActivatorUtilities.CreateInstance(ServiceProvider, handlerType);
                pipeline.AddHandler(handler);
            }

            // Register a route for the command pipeline
            var constraintsResolver = ServiceProvider.GetService <IInlineConstraintResolver>();

            Routes.Add(new TemplateRoute(
                           new CommandRoute <TRequest>(pipeline),
                           routeTemplate,
                           constraintsResolver
                           ));
        }
Esempio n. 11
0
        /// <summary>
        /// Demo init.
        /// </summary>
        private static void Init()
        {
            Paging.Try1();

            /*
             * var config = Saritasa.Tools.Messages.Configuration.XmlConfiguration.AppConfig;
             * CommandPipeline = (ICommandPipeline)config.First();
             */

            // We will use in memory repository.
            inMemoryMessageRepository = new InMemoryMessageRepository();

            // Create command pipeline manually.
            CommandPipeline = new CommandPipeline();
            CommandPipeline.AddMiddlewares(
                new CommandValidationMiddleware(),
                new CommandHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new CommandHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create query pipeline manually.
            QueryPipeline = new QueryPipeline();
            QueryPipeline.AddMiddlewares(
                new QueryObjectResolverMiddleware(),
                new QueryExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );

            // Create event pipeline manually.
            EventPipeline = new EventPipeline();
            EventPipeline.AddMiddlewares(
                new EventHandlerLocatorMiddleware(Assembly.GetEntryAssembly()),
                new EventHandlerExecutorMiddleware(),
                new RepositoryMiddleware(inMemoryMessageRepository)
                );
        }
Esempio n. 12
0
 public void FeatureBackground()
 {
     pipeline = new CommandPipeline(new ExclusiveHandlerCommandBus(new ReflectionHandlerFactory(Assembly.GetAssembly(typeof(TrackedCommand)))));
 }
Esempio n. 13
0
        protected CommandPipeline CreateCommandPipeline()
        {
            var commandPipeline = new CommandPipeline(new ExclusiveHandlerCommandBus(handlerFactory));

            if (configurePipeline != null)
            {
                var pipelineRoot = configurePipeline(commandPipeline);
                commandPipeline.SetRoot(pipelineRoot);
            }

            commandPipeline.IssueCommand.Next = postProcessPipelineStage;
            return commandPipeline;
        }
Esempio n. 14
0
 public ExecuteCommandPipeline(OwinMiddleware next, CommandPipeline pipeline) : base(next)
 {
     this.pipeline = pipeline;
 }
Esempio n. 15
0
 public static IServiceCollection RegisterCommandWithPipeline <TCommand, THandler>(this IServiceCollection services, CommandPipeline <TCommand> pipeline)
 {
     services.AddTransient(typeof(ICommandHandler <TCommand>), typeof(THandler));
     services.Decorate(typeof(ICommandHandler <TCommand>), (obj, provider) => pipeline(obj, provider));
     return(services);
 }
        public void CanTransportFromHongkongToStockholm()
        {
            /* Test setup: A cargo should be shipped from Hongkong to Stockholm,
             * and it should arrive in no more than two weeks. */
            var origin          = Hongkong;
            var destination     = Stockholm;
            var arrivalDeadline = DateTime.Now.AddDays(60);

            /* Use case 1: booking
             *
             * A new cargo is booked, and the unique tracking id is assigned to the cargo. */
            var bookNewCargoCommand = new BookNewCargoCommand
            {
                Origin          = origin.UnLocode.CodeString,
                Destination     = destination.UnLocode.CodeString,
                ArrivalDeadline = arrivalDeadline
            };
            var        bookNewCargoCommandResult = (BookNewCargoCommandResult)CommandPipeline.Process(bookNewCargoCommand);
            TrackingId trackingId = new TrackingId(bookNewCargoCommandResult.TrackingId);

            /* 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. */
            var 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. */
            var routeCandidates = RequestPossibleRoutesForCargo(trackingId);

            var selectedRoute = SelectPreferedItinerary(routeCandidates);

            AssignCargoToRoute(trackingId, selectedRoute);

            Assert.AreEqual(TransportStatus.NotReceived, cargo.Delivery.TransportStatus);
            Assert.AreEqual(RoutingStatus.Routed, cargo.Delivery.RoutingStatus);
            Assert.IsNotNull(cargo.Delivery.EstimatedTimeOfArrival);
            Assert.AreEqual(new HandlingActivity(HandlingEventType.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.
             */
            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
            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
            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
            var 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
            var newRoutes        = RequestPossibleRoutesForCargo(trackingId);
            var newSelectedRoute = SelectPreferedItinerary(newRoutes);

            AssignCargoToRoute(trackingId, newSelectedRoute);

            // 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
            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
            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
            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
            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.
            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());
        }
Esempio n. 17
0
 public Mediator(CommandPipeline pipeline)
 {
     this.pipeline = pipeline;
 }
Esempio n. 18
0
        internal HttpOptions(string commandPath, ICommandRegistry commandRegistry, IHandlerFactory handlerFactory, ICommandNameResolver commandNameResolver, CommandFactory commandFactory, CommandPipeline commandPipeline) : base(commandRegistry, handlerFactory, commandPipeline)
        {
            Guard.EnsureNotNullOrWhitespace(commandPath, nameof(commandPath));
            Guard.EnsureNotNull(commandNameResolver, nameof(commandNameResolver));
            Guard.EnsureNotNull(commandFactory, nameof(commandFactory));

            CommandPath         = commandPath;
            CommandNameResolver = commandNameResolver;
            CommandFactory      = commandFactory;
        }
Esempio n. 19
0
 public void Register <TMessage>(LoadContextModel load, ProcessCommand processCommand, UpdateContextModel update)
 {
     _broadcast.Subscribe(update);
     _pipelines[typeof(TMessage)] = new CommandPipeline(_es, load, processCommand, _broadcast.Update);
 }
Esempio n. 20
0
 public void FeatureBackground()
 {
     pipeline = new CommandPipeline(new ExclusiveHandlerCommandBus(new ReflectionHandlerFactory(Assembly.GetAssembly(typeof(TrackedCommand)))));
 }