示例#1
0
        private void Init()
        {
            if (_initialized)
            {
                return;
            }
            lock (Locker)
            {
                if (_initialized)
                {
                    return;
                }
                _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitingEvent(this));
                _infoDicDicById.Clear();
                _infoDicDicByCode.Clear();
                _infoDicItemByDic.Clear();
                _infoDicItemDic.Clear();
                var allInfoDics = _acDomain.RetrieveRequiredService <INodeHostBootstrap>().GetInfoDics();
                foreach (var infoDic in allInfoDics)
                {
                    var infoDicState = InfoDicState.Create(_acDomain, infoDic);
                    _infoDicDicById.Add(infoDic.Id, infoDicState);
                    _infoDicDicByCode.Add(infoDic.Code, infoDicState);
                    _infoDicItemByDic.Add(infoDicState, new Dictionary <string, InfoDicItemState>(StringComparer.OrdinalIgnoreCase));
                }
                var allDicItems = _acDomain.RetrieveRequiredService <INodeHostBootstrap>().GetInfoDicItems();

                foreach (var infoDicItem in allDicItems)
                {
                    var infoDicItemState = InfoDicItemState.Create(infoDicItem);
                    var infoDic          = _infoDicDicById[infoDicItem.InfoDicId];
                    _infoDicItemByDic[infoDic].Add(infoDicItem.Code, infoDicItemState);
                    _infoDicItemDic.Add(infoDicItem.Id, infoDicItemState);
                }
                _initialized = true;
                _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitializedEvent(this));
            }
        }
示例#2
0
            private void HandleItem(IAcSession acSession, Guid infoDicItemId, bool isCommand)
            {
                var acDomain              = _set._acDomain;
                var infoDicItemDic        = _set._infoDicItemDic;
                var infoDicItemByDic      = _set._infoDicItemByDic;
                var infoDicItemRepository = acDomain.RetrieveRequiredService <IRepository <InfoDicItem, Guid> >();
                InfoDicItemState infoDicItem;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDicItem(infoDicItemId, out infoDicItem))
                {
                    return;
                }
                InfoDicState infoDic;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDic(infoDicItem.InfoDicId, out infoDic))
                {
                    throw new GeneralException("意外的信息字典项字典标识");
                }
                InfoDicItem entity = infoDicItemRepository.GetByKey(infoDicItemId);

                if (entity == null)
                {
                    return;
                }
                var bkState = InfoDicItemState.Create(entity);

                lock (Locker)
                {
                    if (infoDicItemDic.ContainsKey(entity.Id))
                    {
                        infoDicItemDic.Remove(entity.Id);
                    }
                    if (infoDicItemByDic.ContainsKey(infoDic) && infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                    {
                        infoDicItemByDic[infoDic].Remove(entity.Code);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            infoDicItemRepository.Remove(entity);
                            infoDicItemRepository.Context.Commit();
                        }
                        catch
                        {
                            if (!infoDicItemDic.ContainsKey(entity.Id))
                            {
                                infoDicItemDic.Add(entity.Id, bkState);
                            }
                            if (!infoDicItemByDic.ContainsKey(infoDic))
                            {
                                infoDicItemByDic.Add(infoDic, new Dictionary <dicItemCode, InfoDicItemState>(StringComparer.OrdinalIgnoreCase));
                            }
                            if (!infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                            {
                                infoDicItemByDic[infoDic].Add(entity.Code, bkState);
                            }
                            infoDicItemRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new InfoDicItemRemovedEvent(acSession, entity, isPrivate: true));
                }
            }
示例#3
0
            private void Handle(IAcSession acSession, IInfoDicItemUpdateIo input, bool isCommand)
            {
                var acDomain = _set._acDomain;
                var infoDicItemRepository = acDomain.RetrieveRequiredService <IRepository <InfoDicItem, Guid> >();

                if (string.IsNullOrEmpty(input.Code))
                {
                    throw new ValidationException("编码不能为空");
                }
                InfoDicState infoDic;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDic(input.InfoDicId, out infoDic))
                {
                    throw new ValidationException("意外的信息字典项字典标识");
                }
                InfoDicItemState infoDicItem;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDicItem(input.Id, out infoDicItem))
                {
                    throw new NotExistException();
                }
                if (acDomain.NodeHost.InfoDics.TryGetInfoDicItem(infoDic, input.Code, out infoDicItem) && infoDicItem.Id != input.Id)
                {
                    throw new ValidationException("重复的编码");
                }
                var entity = infoDicItemRepository.GetByKey(input.Id);

                if (entity == null)
                {
                    throw new NotExistException();
                }
                var bkState = InfoDicItemState.Create(entity);

                entity.Update(input);

                var  newState     = InfoDicItemState.Create(entity);
                bool stateChanged = newState != bkState;

                lock (Locker)
                {
                    if (stateChanged)
                    {
                        Update(newState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            infoDicItemRepository.Update(entity);
                            infoDicItemRepository.Context.Commit();
                        }
                        catch
                        {
                            if (stateChanged)
                            {
                                Update(bkState);
                            }
                            infoDicItemRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand && stateChanged)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new InfoDicItemUpdatedEvent(acSession, entity, input, isPrivate: true));
                }
            }
示例#4
0
            private void Handle(IAcSession acSession, IInfoDicItemCreateIo input, bool isCommand)
            {
                var acDomain              = _set._acDomain;
                var infoDicItemDic        = _set._infoDicItemDic;
                var infoDicItemByDic      = _set._infoDicItemByDic;
                var infoDicItemRepository = acDomain.RetrieveRequiredService <IRepository <InfoDicItem, Guid> >();

                if (string.IsNullOrEmpty(input.Code))
                {
                    throw new ValidationException("编码不能为空");
                }
                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                InfoDicState infoDic;

                if (!acDomain.NodeHost.InfoDics.TryGetInfoDic(input.InfoDicId, out infoDic))
                {
                    throw new ValidationException("意外的信息字典标识");
                }
                InfoDicItemState infoDicItem;

                if (acDomain.NodeHost.InfoDics.TryGetInfoDicItem(input.Id.Value, out infoDicItem))
                {
                    throw new ValidationException("给定的标识标识的记录已经存在");
                }
                if (acDomain.NodeHost.InfoDics.TryGetInfoDicItem(infoDic, input.Code, out infoDicItem))
                {
                    throw new ValidationException("重复的编码");
                }

                var entity = InfoDicItem.Create(input);

                lock (Locker)
                {
                    var state = InfoDicItemState.Create(entity);
                    if (!infoDicItemDic.ContainsKey(entity.Id))
                    {
                        infoDicItemDic.Add(entity.Id, state);
                    }
                    if (!infoDicItemByDic.ContainsKey(infoDic))
                    {
                        infoDicItemByDic.Add(infoDic, new Dictionary <dicItemCode, InfoDicItemState>(StringComparer.OrdinalIgnoreCase));
                    }
                    if (!infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                    {
                        infoDicItemByDic[infoDic].Add(entity.Code, state);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            infoDicItemRepository.Add(entity);
                            infoDicItemRepository.Context.Commit();
                        }
                        catch
                        {
                            if (infoDicItemDic.ContainsKey(entity.Id))
                            {
                                infoDicItemDic.Remove(entity.Id);
                            }
                            if (infoDicItemByDic.ContainsKey(infoDic) && infoDicItemByDic[infoDic].ContainsKey(entity.Code))
                            {
                                infoDicItemByDic[infoDic].Remove(entity.Code);
                            }
                            infoDicItemRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new InfoDicItemAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }