示例#1
0
        public SysDicItemSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddSysDicItemCommand>("添加系统字典项", LogEnum.DevConsole,
                                                             action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("dicitem code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (!_dicByDicId.ContainsKey(message.Input.DicId))
                {
                    _dicByDicId.Add(message.Input.DicId, new Dictionary <string, SysDicItemData>(StringComparer.OrdinalIgnoreCase));
                }
                if (_dicByDicId[message.Input.DicId].ContainsKey(message.Input.Code))
                {
                    throw new DuplicateCodeException();
                }
                SysDicItemData entity = new SysDicItemData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByDicId[message.Input.DicId].Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new SysDicItemAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateSysDicItemCommand>("更新系统字典项", LogEnum.DevConsole,
                                                                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("sysDicItem code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                string oldCode = entity.Code;
                entity.Update(message.Input);
                // 如果编码变更了
                if (oldCode != entity.Code)
                {
                    _dicByDicId[entity.DicId].Remove(oldCode);
                    _dicByDicId[entity.DicId].Add(entity.Code, entity);
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new SysDicItemUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveSysDicItemCommand>("移除系统字典项", LogEnum.DevConsole,
                                                                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                if (_dicByDicId.ContainsKey(entity.DicId))
                {
                    if (_dicByDicId[entity.DicId].ContainsKey(entity.Code))
                    {
                        _dicByDicId[entity.DicId].Remove(entity.Code);
                    }
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>(isUseJson);
                repository.Remove(entity.Id);

                VirtualRoot.Happened(new SysDicItemRemovedEvent(entity));
            });
        }
示例#2
0
        public SysDicItemSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddSysDicItemCommand>(
                Guid.Parse("485407c5-ffe0-462d-b05f-a13418307be0"),
                "添加系统字典项",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("dicitem code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (!_dicByDicId.ContainsKey(message.Input.DicId))
                {
                    _dicByDicId.Add(message.Input.DicId, new Dictionary <string, SysDicItemData>(StringComparer.OrdinalIgnoreCase));
                }
                if (_dicByDicId[message.Input.DicId].ContainsKey(message.Input.Code))
                {
                    throw new DuplicateCodeException();
                }
                SysDicItemData entity = new SysDicItemData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByDicId[message.Input.DicId].Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>();
                repository.Add(entity);

                Global.Happened(new SysDicItemAddedEvent(entity));
            });
            Global.Access <UpdateSysDicItemCommand>(
                Guid.Parse("0379df7f-9f34-449a-91b2-4bd32e0c287f"),
                "更新系统字典项",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Code))
                {
                    throw new ValidationException("sysDicItem code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>();
                repository.Update(entity);

                Global.Happened(new SysDicItemUpdatedEvent(entity));
            });
            Global.Access <RemoveSysDicItemCommand>(
                Guid.Parse("d0b7b706-2a57-492c-842d-03a4281ecfdf"),
                "移除系统字典项",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicItemData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                if (_dicByDicId.ContainsKey(entity.DicId))
                {
                    if (_dicByDicId[entity.DicId].ContainsKey(entity.Code))
                    {
                        _dicByDicId[entity.DicId].Remove(entity.Code);
                    }
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicItemData>();
                repository.Remove(entity.Id);

                Global.Happened(new SysDicItemRemovedEvent(entity));
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }