示例#1
0
            private void Update(SsdSetState state)
            {
                var acDomain  = _set._acDomain;
                var ssdSetDic = _set._ssdSetDic;

                ssdSetDic[state.Id] = state;
            }
示例#2
0
        public bool TryGetSsdSet(Guid ssdSetId, out SsdSetState ssdSet)
        {
            if (!_initialized)
            {
                Init();
            }
            Debug.Assert(ssdSetId != Guid.Empty);

            return(_ssdSetDic.TryGetValue(ssdSetId, out ssdSet));
        }
示例#3
0
            private void Handle(IAcSession acSession, ISsdSetCreateIo input, bool isCommand)
            {
                var acDomain         = _set._acDomain;
                var ssdSetDic        = _set._ssdSetDic;
                var ssdSetRepository = acDomain.RetrieveRequiredService <IRepository <SsdSet, Guid> >();

                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                if (acDomain.SsdSetSet.Any(a => a.Id == input.Id.Value))
                {
                    throw new GeneralException("重复的SsdSet标识" + input.Id);
                }
                if (acDomain.SsdSetSet.Any(a => a.Name.Equals(input.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ValidationException("重复的静态责任分离角色集名称");
                }

                var entity = SsdSet.Create(input);

                lock (Locker)
                {
                    SsdSetState ssdSet;
                    if (acDomain.SsdSetSet.TryGetSsdSet(entity.Id, out ssdSet))
                    {
                        throw new GeneralException("意外的重复标识");
                    }
                    if (!ssdSetDic.ContainsKey(entity.Id))
                    {
                        ssdSetDic.Add(entity.Id, SsdSetState.Create(entity));
                    }
                    if (isCommand)
                    {
                        try
                        {
                            ssdSetRepository.Add(entity);
                            ssdSetRepository.Context.Commit();
                        }
                        catch
                        {
                            if (ssdSetDic.ContainsKey(entity.Id))
                            {
                                ssdSetDic.Remove(entity.Id);
                            }
                            ssdSetRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new SsdSetAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }
示例#4
0
        public IReadOnlyCollection <SsdRoleState> GetSsdRoles(SsdSetState ssdSet)
        {
            if (!_initialized)
            {
                Init();
            }
            if (ssdSet == null)
            {
                throw new ArgumentNullException("ssdSet");
            }

            return(!_ssdRoleBySet.ContainsKey(ssdSet) ? new List <SsdRoleState>() : _ssdRoleBySet[ssdSet]);
        }
示例#5
0
 private void Init()
 {
     if (_initialized)
     {
         return;
     }
     lock (Locker)
     {
         if (_initialized)
         {
             return;
         }
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitingEvent(this));
         _ssdSetDic.Clear();
         _ssdRoleBySet.Clear();
         _ssdRoleById.Clear();
         var stateReder = _acDomain.RetrieveRequiredService <IOriginalHostStateReader>();
         var ssdSets    = stateReder.GetAllSsdSets();
         foreach (var ssdSet in ssdSets)
         {
             if (!_ssdSetDic.ContainsKey(ssdSet.Id))
             {
                 _ssdSetDic.Add(ssdSet.Id, SsdSetState.Create(ssdSet));
             }
         }
         var ssdRoles = stateReder.GetAllSsdRoles();
         foreach (var ssdRole in ssdRoles)
         {
             SsdSetState ssdSetState;
             if (_ssdSetDic.TryGetValue(ssdRole.SsdSetId, out ssdSetState))
             {
                 var state = SsdRoleState.Create(ssdRole);
                 if (!_ssdRoleById.ContainsKey(ssdRole.Id))
                 {
                     _ssdRoleById.Add(ssdRole.Id, state);
                 }
                 if (!_ssdRoleBySet.ContainsKey(ssdSetState))
                 {
                     _ssdRoleBySet.Add(ssdSetState, new List <SsdRoleState>());
                 }
                 _ssdRoleBySet[ssdSetState].Add(state);
             }
             else
             {
                 // TODO:删除非法的记录
             }
         }
         _initialized = true;
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitializedEvent(this));
     }
 }
示例#6
0
            private void Handle(IAcSession acSession, ISsdSetUpdateIo input, bool isCommand)
            {
                var         acDomain         = _set._acDomain;
                var         ssdSetDic        = _set._ssdSetDic;
                var         ssdSetRepository = acDomain.RetrieveRequiredService <IRepository <SsdSet, Guid> >();
                SsdSetState bkState;

                if (!acDomain.SsdSetSet.TryGetSsdSet(input.Id, out bkState))
                {
                    throw new NotExistException();
                }
                SsdSet entity;
                var    stateChanged = false;

                lock (Locker)
                {
                    SsdSetState oldState;
                    if (!acDomain.SsdSetSet.TryGetSsdSet(input.Id, out oldState))
                    {
                        throw new NotExistException();
                    }
                    if (acDomain.SsdSetSet.Any(a => a.Name.Equals(input.Name, StringComparison.OrdinalIgnoreCase) && a.Id != input.Id))
                    {
                        throw new ValidationException("重复的静态责任分离角色组名");
                    }
                    entity = ssdSetRepository.GetByKey(input.Id);
                    if (entity == null)
                    {
                        throw new NotExistException();
                    }

                    entity.Update(input);

                    var newState = SsdSetState.Create(entity);
                    stateChanged = newState != bkState;
                    if (stateChanged)
                    {
                        Update(newState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            ssdSetRepository.Update(entity);
                            ssdSetRepository.Context.Commit();
                        }
                        catch
                        {
                            if (stateChanged)
                            {
                                Update(bkState);
                            }
                            ssdSetRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand && stateChanged)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new SsdSetUpdatedEvent(acSession, entity, input, isPrivate: true));
                }
            }