}// END Map(IMergePatch... //////////////////////////// protected virtual IPicklistRoleStateRemoved MapRemove(IRemovePicklistRole c, IPicklistCommand outerCommand, long version) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new PicklistRoleEventId(c.PicklistId, c.PartyRoleId, version); IPicklistRoleStateRemoved e = NewPicklistRoleStateRemoved(stateEventId); e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(IRemove... ////////////////////////////
protected virtual IPicklistRoleStateCreated MapCreate(ICreatePicklistRole c, IPicklistCommand outerCommand, long version, IPicklistState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new PicklistRoleEventId(c.PicklistId, c.PartyRoleId, version); IPicklistRoleStateCreated e = NewPicklistRoleStateCreated(stateEventId); var s = outerState.PicklistRoles.Get(c.PartyRoleId, true); e.Active = c.Active; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(ICreate... ////////////////////////////
protected bool IsRepeatedCommand(IPicklistCommand command, IEventStoreAggregateId eventStoreAggregateId, IPicklistState state) { bool repeated = false; if (((IPicklistStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(IPicklistEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(IPicklistCommand c, Action <IPicklistAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetPicklistAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
protected void ThrowOnInconsistentCommands(IPicklistCommand command, IPicklistRoleCommand innerCommand) { var properties = command as ICreateOrMergePatchOrDeletePicklist; var innerProperties = innerCommand as ICreateOrMergePatchOrRemovePicklistRole; if (properties == null || innerProperties == null) { return; } if (innerProperties.PicklistId == default(string)) { innerProperties.PicklistId = properties.PicklistId; } else { var outerPicklistIdName = "PicklistId"; var outerPicklistIdValue = properties.PicklistId; var innerPicklistIdName = "PicklistId"; var innerPicklistIdValue = innerProperties.PicklistId; ThrowOnInconsistentIds(innerProperties, innerPicklistIdName, innerPicklistIdValue, outerPicklistIdName, outerPicklistIdValue); } }// END ThrowOnInconsistentCommands /////////////////////
}// END ThrowOnInconsistentCommands ///////////////////// protected virtual IPicklistRoleEvent Map(IPicklistRoleCommand c, IPicklistCommand outerCommand, long version, IPicklistState outerState) { var create = (c.CommandType == CommandType.Create) ? (c as ICreatePicklistRole) : null; if (create != null) { return(MapCreate(create, outerCommand, version, outerState)); } var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchPicklistRole) : null; if (merge != null) { return(MapMergePatch(merge, outerCommand, version, outerState)); } var remove = (c.CommandType == CommandType.Remove) ? (c as IRemovePicklistRole) : null; if (remove != null) { return(MapRemove(remove, outerCommand, version)); } throw new NotSupportedException(); }
private static bool IsCommandCreate(IPicklistCommand c) { return(c.Version == PicklistState.VersionZero); }