예제 #1
0
파일: UserEvent.cs 프로젝트: uwitec/wms-8
 public static void ThrowOnInconsistentEventIds(IUserEvent oe, IUserRoleEvent e)
 {
     if (!oe.UserEventId.UserId.Equals(e.UserRoleEventId.UserId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id UserId {0} but inner id UserId {1}",
                                 oe.UserEventId.UserId, e.UserRoleEventId.UserId);
     }
 }
예제 #2
0
        public void Save(IUserRoleEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
예제 #3
0
        protected void ThrowOnWrongEvent(IUserRoleEvent e)
        {
            var id = new System.Text.StringBuilder();

            id.Append("[").Append("UserRole|");

            var stateEntityIdUserId = (this as IGlobalIdentity <UserRoleId>).GlobalId.UserId;
            var eventEntityIdUserId = e.UserRoleEventId.UserId;

            if (stateEntityIdUserId != eventEntityIdUserId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id UserId {0} in state but entity id UserId {1} in event", stateEntityIdUserId, eventEntityIdUserId);
            }
            id.Append(stateEntityIdUserId).Append(",");

            var stateEntityIdRoleId = (this as IGlobalIdentity <UserRoleId>).GlobalId.RoleId;
            var eventEntityIdRoleId = e.UserRoleEventId.RoleId;

            if (stateEntityIdRoleId != eventEntityIdRoleId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id RoleId {0} in state but entity id RoleId {1} in event", stateEntityIdRoleId, eventEntityIdRoleId);
            }
            id.Append(stateEntityIdRoleId).Append(",");

            id.Append("]");

            if (ForReapplying)
            {
                return;
            }
            var stateVersion = this.Version;
            var stateEvent   = e is IUserRoleStateEvent ? (IUserRoleStateEvent)e : null;

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (UserRoleState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
예제 #4
0
        protected virtual IUserStateMergePatched Map(IMergePatchUser c)
        {
            var stateEventId         = new UserEventId(c.UserId, c.Version);
            IUserStateMergePatched e = NewUserStateMergePatched(stateEventId);

            e.UserName                              = c.UserName;
            e.AccessFailedCount                     = c.AccessFailedCount;
            e.Email                                 = c.Email;
            e.EmailConfirmed                        = c.EmailConfirmed;
            e.LockoutEnabled                        = c.LockoutEnabled;
            e.LockoutEndDateUtc                     = c.LockoutEndDateUtc;
            e.PasswordHash                          = c.PasswordHash;
            e.PhoneNumber                           = c.PhoneNumber;
            e.PhoneNumberConfirmed                  = c.PhoneNumberConfirmed;
            e.TwoFactorEnabled                      = c.TwoFactorEnabled;
            e.SecurityStamp                         = c.SecurityStamp;
            e.Active                                = c.Active;
            e.IsPropertyUserNameRemoved             = c.IsPropertyUserNameRemoved;
            e.IsPropertyAccessFailedCountRemoved    = c.IsPropertyAccessFailedCountRemoved;
            e.IsPropertyEmailRemoved                = c.IsPropertyEmailRemoved;
            e.IsPropertyEmailConfirmedRemoved       = c.IsPropertyEmailConfirmedRemoved;
            e.IsPropertyLockoutEnabledRemoved       = c.IsPropertyLockoutEnabledRemoved;
            e.IsPropertyLockoutEndDateUtcRemoved    = c.IsPropertyLockoutEndDateUtcRemoved;
            e.IsPropertyPasswordHashRemoved         = c.IsPropertyPasswordHashRemoved;
            e.IsPropertyPhoneNumberRemoved          = c.IsPropertyPhoneNumberRemoved;
            e.IsPropertyPhoneNumberConfirmedRemoved = c.IsPropertyPhoneNumberConfirmedRemoved;
            e.IsPropertyTwoFactorEnabledRemoved     = c.IsPropertyTwoFactorEnabledRemoved;
            e.IsPropertySecurityStampRemoved        = c.IsPropertySecurityStampRemoved;
            e.IsPropertyActiveRemoved               = c.IsPropertyActiveRemoved;

            e.CommandId = c.CommandId;


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();

            var version = c.Version;

            foreach (IUserRoleCommand innerCommand in c.UserRoleCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IUserRoleEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddUserRoleEvent(innerEvent);
            }

            foreach (IUserClaimCommand innerCommand in c.UserClaimCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IUserClaimEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddUserClaimEvent(innerEvent);
            }

            foreach (IUserPermissionCommand innerCommand in c.UserPermissionCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IUserPermissionEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddUserPermissionEvent(innerEvent);
            }

            foreach (IUserLoginCommand innerCommand in c.UserLoginCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IUserLoginEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddUserLoginEvent(innerEvent);
            }


            return(e);
        }
예제 #5
0
 void IUserStateMergePatched.AddUserRoleEvent(IUserRoleEvent e)
 {
     this._userRoleEvents.AddUserRoleEvent(e);
 }
예제 #6
0
 public void AddUserRoleEvent(IUserRoleEvent e)
 {
     _innerStateEvents.Add((UserRoleStateCreatedOrMergePatchedOrRemovedDto)e);
 }
 public virtual UserRoleStateCreatedOrMergePatchedOrRemovedDto ToUserRoleStateEventDto(IUserRoleEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IUserRoleStateCreated)stateEvent;
         return(ToUserRoleStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IUserRoleStateMergePatched)stateEvent;
         return(ToUserRoleStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Removed)
     {
         var e = (IUserRoleStateRemoved)stateEvent;
         return(ToUserRoleStateRemovedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
예제 #8
0
파일: UserEvent.cs 프로젝트: uwitec/wms-8
 public virtual void AddUserRoleEvent(IUserRoleEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._userRoleEvents[e.UserRoleEventId] = e;
 }
예제 #9
0
파일: UserEvent.cs 프로젝트: uwitec/wms-8
 protected void ThrowOnInconsistentEventIds(IUserRoleEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }