Exemplo n.º 1
0
        public async Task CommandBus_Publishes_To_Multiple_Subscribers() {
            var bus = new CommandBus();

            var source1 = new TaskCompletionSource<bool>();
            var source2 = new TaskCompletionSource<bool>();

            bus.Subscribe<SaveCommand>((cmd) => {
                var saveCommand = (SaveCommand)cmd;

                Assert.That(saveCommand.DeviceId, Is.EqualTo("1234"));

                source1.SetResult(true);
            });

            bus.Subscribe<SaveCommand>((cmd) => {
                var saveCommand = (SaveCommand)cmd;

                Assert.That(saveCommand.DeviceId, Is.EqualTo("1234"));

                source2.SetResult(true);
            });

            var command = new SaveCommand("1234");
            await bus.Publish(command);

            await Task.WhenAll(source1.Task, source2.Task).ContinueWith((obj) => {
                bus.RemoveAllSubscriptions();
            });
        }
Exemplo n.º 2
0
        public void FunctionFor0HandleresDoesNotDoAnythig()
        {
            var commanBus = new CommandBus();
            commanBus.RegisterHandlers<FuncCommand>("nonExistentNamespaceWillHave 0 handlers");

            commanBus.Publish(new FuncCommand());
        }
 public MessageLogger(
     CommandBus commandBus, 
     IAsyncQueryHandler<GetRoutesQuery, GetRoutesQueryResponse> getRoutesQueryHandler, 
     IAsyncQueryHandler<GetRouteQuery, GetRouteQueryResponse> getRouteQueryHandler)
 {
     this.commandBus = commandBus;
     this.getRoutesQueryHandler = getRoutesQueryHandler;
     this.getRouteQueryHandler = getRouteQueryHandler;
 }
        public void Setup()
        {
            command = new TestCommand();
            commandHandler = Substitute.For<ICommandHandler<TestCommand>>();
            
            commandHandlerResolver = Substitute.For<ICommandHandlerResolver>();
            commandHandlerResolver.ResolveCommandHandler<ICommandHandler<TestCommand>>().Returns(commandHandler);

            sut = new CommandBus(commandHandlerResolver);
        }
Exemplo n.º 5
0
        public void FunctionCallsAHandlerAndReturns()
        {
            var commanBus = new CommandBus();
            commanBus.RegisterHandlers<FuncCommand>("Commandos.Specs.Samples");

            var command = new FuncCommand();

            var result = commanBus.Publish<FuncCommand>((object) command);

            Assert.That(command, Is.SameAs(result));
        }
        public virtual void Setup()
        {
            Bus = MockRepository.GenerateStub<IBus>();
            TestController = new TestController();
            Container = MockRepository.GenerateStub<IContainer>();
            TestCommandMessage = MockRepository.GenerateStub<ITestCommandMessage>();

            Bus.Stub(bus => bus.CreateInstance<ITestCommandMessage>()).Return(TestCommandMessage);

            CommandBus = new CommandBus(Bus, Container);
        }
        public RabbitMQSubscriber(CommandBus bus)
        {
            this.bus = bus;
            Console.WriteLine("Creating factory...");
            factory = new ConnectionFactory();

            Console.WriteLine("Creating connection...");
            factory.Protocol = Protocols.FromEnvironment();
            factory.HostName = "localhost";
            conn = factory.CreateConnection();
        }
Exemplo n.º 8
0
 public Infrastructure(CommandBus commandBus,
     IEventAggregator eventAggregator,
     IWindowManager windowManager,
     ElasticOpsConfig config)
 {
     CommandBus = commandBus;
     EventAggregator = eventAggregator;
     WindowManager = windowManager;
     Config = config;
     Connection = new Connection();
 }
Exemplo n.º 9
0
        public void ActionCallsVoidHandler()
        {
            var commanBus = new CommandBus();
            commanBus.RegisterHandlers<FuncCommand>("Commandos.Specs.Samples");

            var command = new ActionCommand();

            commanBus.Publish(command);

            Assert.IsTrue(command.Called);
        }
 public void BuildOrder()
 {
     var commandBus = new CommandBus();
     var orderCommand = new BuildOrder
     {
         OrderNo = "ON1001",
         OrderAmount = 10000,
         ProductNo = "PN1001",
         UserIdentifier = "UID1001"
     };
     var result = commandBus.Excute(orderCommand);
     Assert.IsTrue(result.Result);
 }
Exemplo n.º 11
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var bus = new CommandBus();
            var commands = new CommandHandlers();
            bus.RegisterHandler<PostTransactionCommand>(commands.Handle);
            ServiceLocator.CommandBus = bus;

            var events = new EventHandlers();
            DomainEvents.Register<AccountLockedEvent>(events.Handle);
            DomainEvents.Register<AccountOverdrawnEvent>(events.Handle);
            DomainEvents.Register<TransationPostedEvent>(events.Handle);
        }
Exemplo n.º 12
0
        public UnitTest2()
        {
            CommandResultReposiotry commandResultReposiotry = new CommandResultReposiotry();
            CustomerRepository customerRepository = new CustomerRepository();
            CustomerCommandHandler customerCommandHandler = new CustomerCommandHandler(customerRepository, commandResultReposiotry);
            CommandResultQueryaHandler commandResultQueryaHandler = new CommandResultQueryaHandler(commandResultReposiotry);

            CommandBus commandBus = new CommandBus();
            commandBus.Registerd<CustomerCreateCommand>(customerCommandHandler);

            QueryBus queryBus = new QueryBus();
            queryBus.Registerd<CommandResultQuery>(commandResultQueryaHandler);

            _commandBus = commandBus;
            _queryBus = queryBus;
        }
        public static void Main(string[] args)
        {
            var commandBus = new CommandBus();

            var sessionFactory = DbConfig();

            var accountReportView = new AccountReportView(sessionFactory);

            commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle);

            commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle);

            var r = new RunRabbitMQSubscriber(commandBus);
        }
Exemplo n.º 14
0
        public async Task CommandBus_Publishes_To_Single_Subscriber() {
            var bus = new CommandBus();
            var source = new TaskCompletionSource<bool>();

            bus.Subscribe<SaveCommand>((cmd) => {
                var saveCommand = (SaveCommand)cmd;

                Assert.That(saveCommand.DeviceId, Is.EqualTo("1234"));
                bus.RemoveAllSubscriptions();

                source.SetResult(true);
            });

            var command = new SaveCommand("1234");
            await bus.Publish(command);

            await source.Task;
        }
Exemplo n.º 15
0
        public async Task CommandBus_Subscribes_With_Command_String() {
            var bus = new CommandBus();
            var source = new TaskCompletionSource<bool>();

            bus.Subscribe("SaveCommand", (cmd) => {
                var saveCommand = (SaveCommand)cmd;

                Assert.That(saveCommand.DeviceId, Is.EqualTo("1234"));
                bus.RemoveAllSubscriptions();

                source.SetResult(true);

                return null;
            });

            var command = new SaveCommand("1234");
            await bus.Publish(command);

            await source.Task;
        }
Exemplo n.º 16
0
        internal TransportConfigurator RegisterDomainBuses(IContainer container)
        {
            var serviceBus = container.GetInstance<ServiceBus>();
            var serviceProvider = container.GetInstance<IServiceProvider>();
            var entityIdGenerator = container.GetInstance<IEntityIdGenerator>();
            var validationRegistry = new FluentValidatorsRegistry(serviceProvider);
            validationRegistry.Register(typeof(Namespace_DomainProject).Assembly);

            var commandValidationFactory = new FluentCommandValidationFacade(validationRegistry);
            var commandBus = new CommandBus(serviceBus, EndpointAddress.Create("whowhat.input", Environment.MachineName), entityIdGenerator, commandValidationFactory);
            var eventBus = new EventBus(serviceBus, EndpointAddress.Create("whowhat.input", Environment.MachineName));

            container.Configure(config =>
            {
                config.For<CommandBus>().Singleton().Use(commandBus);
                config.For<EventBus>().Singleton().Use(eventBus);
            });

            return this;
        }
Exemplo n.º 17
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);

            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();

            var ctx1 = new RegisterUserContext();

            var commandBus = new CommandBus();
            commandBus.RegisterHandlerCommand<RegisterUserCommand>(ctx1.Handle);

            builder.Register<IBus>(c => commandBus).As<IBus>();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Exemplo n.º 18
0
 public ProductController(ISessionFactory sf)
 {
     this.sf = sf;
     this._cmdBus = ServiceLocator.Bus;
 }
Exemplo n.º 19
0
        public async Task <IActionResult> DisableField(string app, string name, long id)
        {
            await CommandBus.PublishAsync(new DisableField { FieldId = id });

            return(NoContent());
        }
 public LogMessageProcessingFailureController(CommandBus commandBus)
 {
     this.commandBus = commandBus;
 }
Exemplo n.º 21
0
        public async Task <IActionResult> DeleteSchema(string app, string name)
        {
            await CommandBus.PublishAsync(new DeleteSchema());

            return(NoContent());
        }
        private void QueChannel(CommandBus bus)
        {
            using (IModel model = conn.CreateModel())
            {
                var subscription = new Subscription(model, "queue", false);

                while (true)
                {
                    BasicDeliverEventArgs basicDeliveryEventArgs =
                        subscription.Next();
                    var @event = StreamExtension.Deserialize<Vaccine.Events.DomainEvent>(basicDeliveryEventArgs.Body);

                    //Encoding.UTF8.GetString(basicDeliveryEventArgs.Body);
                    Console.WriteLine(@event.GetType());

                    bus.Publish(@event);

                    subscription.Ack(basicDeliveryEventArgs);
                }
            }
        }
        public RunRabbitMQSubscriber(CommandBus bus)
        {
            this.bus = bus;
            Console.WriteLine("Creating factory...");
            factory = new ConnectionFactory();

            Console.WriteLine("Creating connection...");
            factory.Protocol = Protocols.FromEnvironment();
            factory.HostName = "localhost";
            conn = factory.CreateConnection();

            Console.WriteLine("Creating channel...");
            try
            {
                QueChannel(bus);
            }
            catch
            {
                Thread.Sleep(100000);
                QueChannel(bus);
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> DeleteSchema(string app, string name, Guid id)
        {
            await CommandBus.PublishAsync(new DeleteWebhook { Id = id });

            return(NoContent());
        }
        private static void RegisterHandlers(IKernel kernel)
        {
            kernel.Bind(
                convention =>
                    convention.From(Assembly.GetAssembly(typeof(CommandBus)))
                        .SelectAllClasses()
                        .InNamespaces("WaiterManagement.BLL.Commands.Handlers")
                        .BindAllInterfaces());

            var commandBus = new CommandBus(x => kernel.GetAll<IHandleCommand>().First(y => y.GetType().GetInterfaces()[1].GetGenericArguments()[0] == x));
            kernel.Bind<ICommandBus>().ToConstant(commandBus);

            kernel.Bind(
                convention =>
                    convention.From(Assembly.GetAssembly(typeof(EventBus)))
                        .SelectAllClasses()
                        .InNamespaces("WaiterManagement.BLL.Events.Handlers")
                        .BindAllInterfaces());

            kernel.Bind<IEventBus>().ToMethod(c => new EventBus(x => kernel.GetAll<IHandleEvent>().Where(y => y.GetType().GetInterfaces().Any(z => z.IsGenericType && z.GetGenericArguments()[0] == x))));
        }
Exemplo n.º 26
0
        public async Task <IActionResult> PutNestedField(string app, string name, long parentId, long id, [FromBody] UpdateFieldDto request)
        {
            await CommandBus.PublishAsync(request.ToCommand(id, parentId));

            return(NoContent());
        }
Exemplo n.º 27
0
 public void Setup()
 {
     commandHandlerFactory = MockRepository.GenerateMock<ICommandHandlerFactory>();
     commandBus = new CommandBus(commandHandlerFactory);
 }
Exemplo n.º 28
0
        public async Task <IActionResult> PutNestedFieldOrdering(string app, string name, long parentId, [FromBody] ReorderFieldsDto request)
        {
            await CommandBus.PublishAsync(request.ToCommand(parentId));

            return(NoContent());
        }
Exemplo n.º 29
0
 protected WorkflowHandler(ViewContext context, CommandBus commandBus, IEntityIdGenerator idGenerator)
 {
     _context = context;
     _commandBus = commandBus;
     _idGenerator = idGenerator;
 }
Exemplo n.º 30
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);

            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();

            builder.RegisterModule(new NHibernateSessionModule());

            //builder.RegisterModule(new ReportingSessionModule());

            builder.RegisterModule(new QueryModule());

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();

            _container = container;

            QueryModule._container = _container;

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var rabbitMQPublisher = new RabbitMQPublisher(System.Configuration.ConfigurationManager.AppSettings["CLOUDAMQP_URL"]);

            //Use RabbitMQ
            //var commandBus = new CommandBus(rabbitMQPublisher);

            var commandBus = new CommandBus();

            var sessionFactory = container.Resolve<ISessionFactory>();
            IEventStore eventStore = new NHibernateEventStore(commandBus, sessionFactory);

            //Context
            var transferMoneyContext = new TransferMoneyContext(eventStore);
            var createBankAccountContext = new CreateBankAccountContext(eventStore);
            var changeAccountAndBalanceContext = new ChangeAccountNameAndBalanceContext(eventStore);
            var createCustomerContext = new CreateCustomerContext(eventStore);
            var addCustomerAddressContext = new AddCustomerAddressContext(eventStore);
            var stockNewProductContext = new StockNewProductContext(eventStore);
            var placeOrderContext = new PlaceOrderContext(eventStore);

            //Register Command
            commandBus.RegisterHandlerCommand<OpenAccountCommand>(createBankAccountContext.Handle);
            commandBus.RegisterHandlerCommand<TransferMoneyCommand>(transferMoneyContext.Handle);
            commandBus.RegisterHandlerCommand<ChangeAccountNameAndBalanceCommand>(changeAccountAndBalanceContext.Handle);
            commandBus.RegisterHandlerCommand<CreateCustomerCommand>(createCustomerContext.Handle);
            commandBus.RegisterHandlerCommand<AddCustomerAddressCommand>(addCustomerAddressContext.Handle);
            commandBus.RegisterHandlerCommand<CreateProductCommand>(stockNewProductContext.Handle);
            commandBus.RegisterHandlerCommand<PlaceOrderCommand>(placeOrderContext.Handle);

            //Report View
            var accountReportView = new AccountReportView(sessionFactory);

            //Register Event
            commandBus.RegisterHandlerEvent<AccountCreatedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<AccountNameAndBalanceChangedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<BalanceDecreasedEvent>(accountReportView.Handle);
            commandBus.RegisterHandlerEvent<BalanceIncreasedEvent>(accountReportView.Handle);

            //Report View
            var customerReportView = new CustomerReportView(container.Resolve<ISessionFactory>());

            //Register Event
            commandBus.RegisterHandlerEvent<CustomerCreatedEvent>(customerReportView.Handle);
            commandBus.RegisterHandlerEvent<CustomerAddressAddedEvent>(customerReportView.Handle);

            var placeOrderView = new PlaceOrderView(container.Resolve<ISessionFactory>());

            commandBus.RegisterHandlerEvent<OrderPlacedEvent>(placeOrderView.Handle);

            var productStockReportView = new ProductStockReportView(container.Resolve<ISessionFactory>());

            commandBus.RegisterHandlerEvent<ProductCreatedEvent>(productStockReportView.Handle);

            //ServiceLocator.Pub = rabbitMQPublisher;
            ServiceLocator.Bus = commandBus;
            //ServiceLocator.Sub = rabbitMQSubsriber;
        }
Exemplo n.º 31
0
        public async Task <IActionResult> ChangePlanAsync(string app, [FromBody] ChangePlanDto request)
        {
            await CommandBus.PublishAsync(SimpleMapper.Map(request, new ChangePlan()));

            return(NoContent());
        }
        private static UnityContainer CreateContainer()
        {
            var container = new UnityContainer();

            // infrastructure
            var serializer = new JsonTextSerializer();
            container.RegisterInstance<ITextSerializer>(serializer);

#if LOCAL
            container.RegisterType<IMessageSender, MessageSender>(
                "Commands", new TransientLifetimeManager(), new InjectionConstructor(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Commands"));
            container.RegisterType<ICommandBus, CommandBus>(
                new ContainerControlledLifetimeManager(), new InjectionConstructor(new ResolvedParameter<IMessageSender>("Commands"), serializer));
#else
            var settings = InfrastructureSettings.Read(HttpContext.Current.Server.MapPath(@"~\bin\Settings.xml")).ServiceBus;
            new ServiceBusConfig(settings).Initialize();

            var commandBus = new CommandBus(new TopicSender(settings, "conference/commands"), new StandardMetadataProvider(), serializer);

            container.RegisterInstance<ICommandBus>(commandBus);
#endif

            // repository

            container.RegisterType<IBlobStorage, SqlBlobStorage>(new ContainerControlledLifetimeManager(), new InjectionConstructor("BlobStorage"));
            container.RegisterType<ConferenceRegistrationDbContext>(new TransientLifetimeManager(), new InjectionConstructor("ConferenceRegistration"));
            container.RegisterType<PaymentsReadDbContext>(new TransientLifetimeManager(), new InjectionConstructor("Payments"));

            container.RegisterType<IOrderDao, OrderDao>();
            container.RegisterType<IConferenceDao, ConferenceDao>();
            container.RegisterType<IPaymentDao, PaymentDao>();

            return container;
        }
Exemplo n.º 33
0
        public async Task <IActionResult> DeleteNestedField(string app, string name, long parentId, long id)
        {
            await CommandBus.PublishAsync(new DeleteField { ParentFieldId = parentId, FieldId = id });

            return(NoContent());
        }
Exemplo n.º 34
0
        private void ConfigureCommands()
        {
            _kernel.Bind(
                convention =>
                    convention.From(Assembly.GetAssembly(typeof(CommandBus)))
                        .SelectAllClasses()
                        .InNamespaces("Organizer.BLL.Commands.Handlers")
                        .BindAllInterfaces());
            _kernel.Bind(
                convention =>
                    convention.From(Assembly.GetAssembly(typeof(CommandBus)))
                        .SelectAllClasses()
                        .InNamespaces("Organizer.BLL.Commands.Concrete")
                        .BindAllInterfaces());

            var commandBus = new CommandBus(x => _kernel.GetAll<IHandleCommand>().First(y => y.GetType().GetInterfaces()[1].GetGenericArguments()[0] == x));

            _kernel.Bind<ICommandBus>().ToConstant(commandBus);
        }
Exemplo n.º 35
0
        public async Task <IActionResult> DeleteAssetFolder(string app, Guid id)
        {
            await CommandBus.PublishAsync(new DeleteAssetFolder { AssetFolderId = id });

            return(NoContent());
        }
 public LogCommandProcessingController(CommandBus commandBus)
 {
     this.commandBus = commandBus;
 }
 public BankAccountController(ISessionFactory sf)
 {
     this.sf = sf;
     this._cmdBus = ServiceLocator.Bus;
 }
 public CustomerReportController(ISessionFactory sf)
 {
     this.sf = sf;
     this._cmdBus = ServiceLocator.Bus;
 }
Exemplo n.º 39
0
 public EnemiesWaveMaintainerSystem(CommandBus commandBus, EnemiesSettings enemiesSettings)
 {
     _commandBus      = commandBus;
     _enemiesSettings = enemiesSettings;
 }