}// END Map(IMergePatch... //////////////////////////// protected virtual IAttributeUseStateRemoved MapRemove(IRemoveAttributeUse c, IAttributeSetCommand outerCommand, long version) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new AttributeUseEventId(c.AttributeSetId, c.AttributeId, version); IAttributeUseStateRemoved e = NewAttributeUseStateRemoved(stateEventId); e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(IRemove... ////////////////////////////
}// END Map(IMergePatch... //////////////////////////// protected virtual IAttributeUseStateRemoved MapRemove(IRemoveAttributeUse c, IAttributeSetCommand outerCommand, long version) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new AttributeUseStateEventId(c.AttributeSetId, c.AttributeId, version); IAttributeUseStateRemoved e = NewAttributeUseStateRemoved(stateEventId); e.CreatedBy = (string)c.RequesterId; e.CreatedAt = DateTime.Now; return(e); }// END Map(IRemove... ////////////////////////////
protected virtual IAttributeUseStateCreated MapCreate(ICreateAttributeUse c, IAttributeSetCommand outerCommand, long version, IAttributeSetState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new AttributeUseStateEventId(c.AttributeSetId, c.AttributeId, version); IAttributeUseStateCreated e = NewAttributeUseStateCreated(stateEventId); var s = outerState.AttributeUses.Get(c.AttributeId, true); e.SequenceNumber = c.SequenceNumber; e.Active = c.Active; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = DateTime.Now; return(e); }// END Map(ICreate... ////////////////////////////
protected bool IsRepeatedCommand(IAttributeSetCommand command, IEventStoreAggregateId eventStoreAggregateId, IAttributeSetState state) { bool repeated = false; if (((IAttributeSetStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.FindLastEvent(typeof(IAttributeSetStateEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected void ThrowOnInconsistentCommands(IAttributeSetCommand command, IAttributeUseCommand innerCommand) { var properties = command as ICreateOrMergePatchOrDeleteAttributeSet; var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveAttributeUse; if (properties == null || innerProperties == null) { return; } var outerAttributeSetIdName = "AttributeSetId"; var outerAttributeSetIdValue = properties.AttributeSetId; var innerAttributeSetIdName = "AttributeSetId"; var innerAttributeSetIdValue = innerProperties.AttributeSetId; SetNullInnerIdOrThrowOnInconsistentIds(innerProperties, innerAttributeSetIdName, innerAttributeSetIdValue, outerAttributeSetIdName, outerAttributeSetIdValue); }// END ThrowOnInconsistentCommands /////////////////////
protected virtual void Update(IAttributeSetCommand c, Action <IAttributeSetAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetAttributeSetAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); EventStore.AppendEvents(eventStoreAggregateId, ((IAttributeSetStateProperties)state).Version, aggregate.Changes, () => { StateRepository.Save(state); }); }
protected virtual void Update(IAttributeSetCommand c, Action <IAttributeSetAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetAttributeSetAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
}// END ThrowOnInconsistentCommands ///////////////////// protected virtual IAttributeUseStateEvent Map(IAttributeUseCommand c, IAttributeSetCommand outerCommand, long version, IAttributeSetState outerState) { var create = (c.CommandType == CommandType.Create) ? (c as ICreateAttributeUse) : null; if (create != null) { return(MapCreate(create, outerCommand, version, outerState)); } var merge = (c.CommandType == CommandType.MergePatch) ? (c as IMergePatchAttributeUse) : null; if (merge != null) { return(MapMergePatch(merge, outerCommand, version, outerState)); } var remove = (c.CommandType == CommandType.Remove) ? (c as IRemoveAttributeUse) : null; if (remove != null) { return(MapRemove(remove, outerCommand, version)); } throw new NotSupportedException(); }
private static bool IsCommandCreate(IAttributeSetCommand c) { return(c.Version == AttributeSetState.VersionZero); }
}// END Map(ICreate... //////////////////////////// protected virtual IAttributeUseStateMergePatched MapMergePatch(IMergePatchAttributeUse c, IAttributeSetCommand outerCommand, long version, IAttributeSetState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new AttributeUseStateEventId(c.AttributeSetId, c.AttributeId, version); IAttributeUseStateMergePatched e = NewAttributeUseStateMergePatched(stateEventId); var s = outerState.AttributeUses.Get(c.AttributeId); e.SequenceNumber = c.SequenceNumber; e.Active = c.Active; e.IsPropertySequenceNumberRemoved = c.IsPropertySequenceNumberRemoved; e.IsPropertyActiveRemoved = c.IsPropertyActiveRemoved; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = DateTime.Now; return(e); }// END Map(IMergePatch... ////////////////////////////