public void ProcessMessage(IHandlerContext <AddRoleCommand> context) { var message = context.Message; if (string.IsNullOrEmpty(message.Name)) { return; } using (_databaseContextFactory.Create()) { var key = Role.Key(message.Name); if (_keyStore.Contains(key)) { return; } var id = Guid.NewGuid(); _keyStore.Add(id, key); var role = new Role(id); var stream = _eventStore.CreateEventStream(id); stream.AddEvent(role.Add(message.Name)); _eventStore.Save(stream); } }
public void ProcessMessage(IHandlerContext <RegisterOrderProcessCommand> context) { var message = context.Message; var orderProcess = new OrderProcess(); var stream = _eventStore.CreateEventStream(orderProcess.Id); var initialized = orderProcess.Initialize(); stream.AddEvent(initialized); stream.AddEvent(orderProcess.AssignCustomer(message.CustomerName, message.CustomerEMail)); stream.AddEvent(orderProcess.AssignTargetSystem(message.TargetSystem, message.TargetSystemUri)); var status = orderProcess.ChangeStatus("Cooling Off"); stream.AddEvent(status); foreach (var quotedProduct in message.QuotedProducts) { stream.AddEvent(orderProcess.AddItem(quotedProduct.ProductId, quotedProduct.Description, quotedProduct.Price)); } using (_databaseContextFactory.Create(ProcessManagementData.ConnectionStringName)) { _eventStore.Save(stream); } context.Publish(new OrderProcessRegisteredEvent { OrderProcessId = orderProcess.Id, QuotedProducts = message.QuotedProducts, CustomerName = message.CustomerName, CustomerEMail = message.CustomerEMail, OrderNumber = initialized.OrderNumber, OrderDate = initialized.DateRegistered, OrderTotal = orderProcess.Total, Status = status.Status, StatusDate = status.StatusDate, TargetSystem = message.TargetSystem, TargetSystemUri = message.TargetSystemUri }); context.Send(new AcceptOrderProcessCommand { OrderProcessId = orderProcess.Id }, c => c.Defer(DateTime.Now.AddSeconds(10)).Local()); }
public void ProcessMessage(IHandlerContext <RegisterUserCommand> context) { var message = context.Message; if (string.IsNullOrEmpty(message.Username)) { return; } if (string.IsNullOrEmpty(message.RegisteredBy)) { return; } var id = Guid.NewGuid(); using (_databaseContextFactory.Create()) { var key = User.Key(message.Username); if (_keyStore.Contains(key)) { return; } var count = _systemUserQuery.Count(); _keyStore.Add(id, key); var user = new User(id); var stream = _eventStore.CreateEventStream(id); var registered = user.Register(message.Username, message.PasswordHash, message.RegisteredBy); if (count == 0) { stream.AddEvent(user.AddRole("administrator")); } stream.AddEvent(registered); _eventStore.Save(stream); } }
public void ProcessMessage(IHandlerContext <RegisterMatrixCommand> context) { var message = context.Message; using (_databaseContextFactory.Create()) { Matrix matrix; var key = Matrix.Key(message.Name); EventStream stream; if (message.Id.Equals(Guid.Empty)) { stream = _eventStore.CreateEventStream(); matrix = new Matrix(stream.Id); _keyStore.Add(matrix.Id, key); } else { stream = _eventStore.Get(message.Id); matrix = new Matrix(stream.Id); stream.Apply(matrix); if (!matrix.IsNamed(message.Name) && !_keyStore.Contains(key)) { _keyStore.Remove(Matrix.Key(message.Name)); _keyStore.Add(matrix.Id, key); } } stream.AddEvent(matrix.Register( message.Name, message.RowArgumentId, message.ColumnArgumentId, message.DataTypeName)); _eventStore.Save(stream); } }
public void ProcessMessage(IHandlerContext <RegisterTestCommand> context) { var message = context.Message; using (_databaseContextFactory.Create()) { var key = Test.Key(message.Name); if (_keyStore.Contains(key)) { return; } var test = new Test(Guid.NewGuid()); var stream = _eventStore.CreateEventStream(test.Id); stream.AddEvent(test.Register(message.Name, message.FormulaId, message.ExpectedResult, message.ExpectedResultDataTypeName, message.Comparison)); _eventStore.Save(stream); _keyStore.Add(test.Id, key); } }