protected bool IsRepeatedCommand(IWarehouseCommand command, IEventStoreAggregateId eventStoreAggregateId, IWarehouseState state) { bool repeated = false; if (((IWarehouseStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(IWarehouseEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(IWarehouseCommand c, Action <IWarehouseAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetWarehouseAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
protected virtual void Update(IWarehouseCommand c, Action <IWarehouseAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetWarehouseAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); EventStore.AppendEvents(eventStoreAggregateId, ((IWarehouseStateProperties)state).Version, aggregate.Changes, () => { StateRepository.Save(state); }); }
private static bool IsCommandCreate(IWarehouseCommand c) { return(c.Version == WarehouseState.VersionZero); }
public void SetCommand(IWarehouseCommand command) { warehouseCommand = command; }
public static void ExecuteCommand(WarehouseInvoker warehouseInvoker, IWarehouseCommand warehouseCommand) { warehouseInvoker.SetCommand(warehouseCommand); warehouseInvoker.Invoke(); }