public override AddOrderCommand Handle(AddOrderCommand addOrderCommand)
        {
            using (var scope = _ordersDao.BeginTransaction())
            {
                base.logger.DebugFormat(string.Format("Writing new order for customer: {0}", addOrderCommand.CustomerName));
                var inserted = _ordersDao.Add(
                    new Order(
                        customerName: addOrderCommand.CustomerName,
                        orderDescription: addOrderCommand.OrderDescription,
                        dueDate: addOrderCommand.OrderDueDate
                        )
                    );

                scope.Commit();

                addOrderCommand.OrderId = inserted.Id;
            }

            _commandProcessor.Publish(
                new OrderAddedEvent(
                    addOrderCommand.CustomerName,
                    addOrderCommand.OrderDescription,
                    addOrderCommand.OrderDueDate));

            return(base.Handle(addOrderCommand));
        }
Exemplo n.º 2
0
        protected void DispatchRequest(MessageHeader messageHeader, TRequest request)
        {
            _logger.Value.DebugFormat("MessagePump: Dispatching message {0} from {2} on thread # {1}", request.Id, Thread.CurrentThread.ManagedThreadId, Channel.Name);

            if (messageHeader.MessageType == MessageType.MT_COMMAND && request is IEvent)
            {
                throw new ConfigurationException(string.Format("Message {0} mismatch. Message type is '{1}' yet mapper produced message of type IEvent", request.Id, MessageType.MT_COMMAND));
            }
            if (messageHeader.MessageType == MessageType.MT_EVENT && request is ICommand)
            {
                throw new ConfigurationException(string.Format("Message {0} mismatch. Message type is '{1}' yet mapper produced message of type ICommand", request.Id, MessageType.MT_EVENT));
            }

            switch (messageHeader.MessageType)
            {
            case MessageType.MT_COMMAND:
            {
                _commandProcessor.Send(request);
                break;
            }

            case MessageType.MT_DOCUMENT:
            case MessageType.MT_EVENT:
            {
                _commandProcessor.Publish(request);
                break;
            }
            }
        }
Exemplo n.º 3
0
        public override AddProductCommand Handle(AddProductCommand addProductCommand)
        {
            Product insertedProduct;

            using (var scope = _productsDao.BeginTransaction())
            {
                insertedProduct = _productsDao.Add(
                    new Product(
                        productName: addProductCommand.ProductName,
                        productDescription: addProductCommand.ProductDescription,
                        productPrice: addProductCommand.ProductPrice)
                    );

                scope.Commit();

                addProductCommand.ProductId = insertedProduct.Id;
            }

            if (insertedProduct != null)
            {
                _commandProcessor.Publish(new ProductAddedEvent(insertedProduct.Id, insertedProduct.ProductName, insertedProduct.ProductDescription, insertedProduct.ProductPrice));
            }

            return(base.Handle(addProductCommand));
        }
        public override AddOrganizationCommand Handle(AddOrganizationCommand addOrganizationCommand)
        {
            Logger.Info("EFAddOrganizationCommand handles command");
            Organization pm = _domainFactory.CreateOrganizationDomainObject(addOrganizationCommand);

            //Save in the local repository
            _repository.Insert(pm);

            //Assign Id to the command
            addOrganizationCommand.OrganizationId = pm.Id;

            //Publishes event to others subscribers
            _commandProcessor.Publish(new OrganizationAddedEvent());
            return(base.Handle(addOrganizationCommand));
        }
Exemplo n.º 5
0
        public override RemoveProductCommand Handle(RemoveProductCommand removeProductCommand)
        {
            Product product;

            using (var scope = _productsDao.BeginTransaction())
            {
                product = _productsDao.FindById(removeProductCommand.ProductId);
                _productsDao.Delete(removeProductCommand.ProductId);
            }

            if (product != null)
            {
                _commandProcessor.Publish(new ProductRemovedEvent(product.Id, product.ProductName, product.ProductDescription, product.ProductPrice));
            }

            return(base.Handle(removeProductCommand));
        }
Exemplo n.º 6
0
        public override AddOrganizationCommand Handle(AddOrganizationCommand addOrganizationCommand)
        {
            Logger.Info("Normal AddOrganizationCommand handles command");
            using (TransactionScope scope = new TransactionScope())
            {
                Organization pm = _domainFactory.CreateOrganizationDomainObject(addOrganizationCommand);

                //Save in the local repository
                _repository.Insert(pm);

                //Assign Id to the command
                addOrganizationCommand.OrganizationId = pm.Id;

                scope.Complete();
            }

            //Publishes event synchronously to others subscribers
            _commandProcessor.Publish(new OrganizationAddedEvent());
            return(base.Handle(addOrganizationCommand));
        }
Exemplo n.º 7
0
        private void DispatchRequest(MessageType messageType, TRequest request)
        {
            if (Logger != null)
            {
                Logger.Debug(m => m("MessagePump: Dispatching message {0} on thread # {1}", request.Id, Thread.CurrentThread.ManagedThreadId));
            }
            switch (messageType)
            {
            case MessageType.MT_COMMAND:
            {
                commandProcessor.Send(request);
                break;
            }

            case MessageType.MT_DOCUMENT:
            case MessageType.MT_EVENT:
            {
                commandProcessor.Publish(request);
                break;
            }
            }
        }
        public override ChangeProductCommand Handle(ChangeProductCommand changeProductCommand)
        {
            Product product;

            using (var scope = _productsDao.BeginTransaction())
            {
                product                    = _productsDao.FindById(changeProductCommand.ProductId);
                product.ProductName        = changeProductCommand.ProductName;
                product.ProductDescription = changeProductCommand.ProductDescription;
                product.ProductPrice       = changeProductCommand.Price;

                _productsDao.Update(product);
                scope.Commit();
            }

            if (product != null)
            {
                _commandProcessor.Publish(new ProductChangedEvent(product.Id, product.ProductName, product.ProductDescription, product.ProductPrice));
            }

            return(base.Handle(changeProductCommand));
        }
Exemplo n.º 9
0
 public void Publish <T>(T @event)
     where T : class, IRequest
 {
     _commandProcessor.Publish(@event);
 }