Beispiel #1
0
        protected void ThrowOnWrongEvent(IUserPermissionStateEvent stateEvent)
        {
            var stateEntityIdUserId = (this as IGlobalIdentity <UserPermissionId>).GlobalId.UserId;
            var eventEntityIdUserId = stateEvent.StateEventId.UserId;

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

            var stateEntityIdPermissionId = (this as IGlobalIdentity <UserPermissionId>).GlobalId.PermissionId;
            var eventEntityIdPermissionId = stateEvent.StateEventId.PermissionId;

            if (stateEntityIdPermissionId != eventEntityIdPermissionId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id PermissionId {0} in state but entity id PermissionId {1} in event", stateEntityIdPermissionId, eventEntityIdPermissionId);
            }

            var stateVersion = this.Version;
            var eventVersion = stateEvent.Version;

            if (UserPermissionState.VersionZero == eventVersion)
            {
                eventVersion = stateEvent.Version = stateVersion;
            }
            if (stateVersion != eventVersion)
            {
                throw DomainError.Named("concurrencyConflict", "Conflict between state version {0} and event version {1}", stateVersion, eventVersion);
            }
        }
Beispiel #2
0
 public static void ThrowOnInconsistentEventIds(IUserStateEvent oe, IUserPermissionStateEvent e)
 {
     if (!oe.StateEventId.UserId.Equals(e.StateEventId.UserId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id UserId {0} but inner id UserId {1}",
                                 oe.StateEventId.UserId, e.StateEventId.UserId);
     }
 }
        public void Save(IUserPermissionStateEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
Beispiel #4
0
        protected void ThrowOnWrongEvent(IUserPermissionStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityIdUserId = (this as IGlobalIdentity <UserPermissionId>).GlobalId.UserId;
            var eventEntityIdUserId = stateEvent.StateEventId.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 stateEntityIdPermissionId = (this as IGlobalIdentity <UserPermissionId>).GlobalId.PermissionId;
            var eventEntityIdPermissionId = stateEvent.StateEventId.PermissionId;

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

            id.Append("]");

            if (ForReapplying)
            {
                return;
            }
            var stateVersion = this.Version;
            var eventVersion = stateEvent.Version;

            if (UserPermissionState.VersionZero == eventVersion)
            {
                eventVersion = stateEvent.Version = stateVersion;
            }
            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Beispiel #5
0
 public virtual void AddUserPermissionEvent(IUserPermissionStateEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._userPermissionEvents[e.StateEventId] = e;
 }
Beispiel #6
0
 protected void ThrowOnInconsistentEventIds(IUserPermissionStateEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
Beispiel #7
0
 void IUserStateMergePatched.AddUserPermissionEvent(IUserPermissionStateEvent e)
 {
     this._userPermissionEvents.AddUserPermissionEvent(e);
 }
Beispiel #8
0
        protected virtual IUserStateMergePatched Map(IMergePatchUser c)
        {
            var stateEventId         = new UserStateEventId(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;

            ReflectUtils.CopyPropertyValue("CommandId", c, e);


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = DateTime.Now;

            var version = c.Version;

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

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

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

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

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

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

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

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


            return(e);
        }
Beispiel #9
0
        public virtual UserPermissionStateCreatedOrMergePatchedOrRemovedDto ToUserPermissionStateEventDto(IUserPermissionStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (IUserPermissionStateCreated)stateEvent;
                return(ToUserPermissionStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (IUserPermissionStateMergePatched)stateEvent;
                return(ToUserPermissionStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Removed)
            {
                var e = (IUserPermissionStateRemoved)stateEvent;
                return(ToUserPermissionStateRemovedDto(e));
            }

            throw DomainError.Named("invalidStateEventType", String.Format("Invalid state event type: {0}", stateEvent.StateEventType));
        }
 public void AddUserPermissionEvent(IUserPermissionStateEvent e)
 {
     _innerStateEvents.Add((UserPermissionStateCreatedOrMergePatchedOrRemovedDto)e);
 }