Esempio n. 1
0
        public SysDicSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddSysDicCommand>(
                Guid.Parse("9353be1f-707f-455f-ade5-07e081141d47"),
                "添加系统字典",
                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("dic code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (_dicByCode.ContainsKey(message.Input.Code))
                {
                    throw new DuplicateCodeException();
                }
                SysDicData entity = new SysDicData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByCode.Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Add(entity);

                Global.Happened(new SysDicAddedEvent(entity));
            });
            Global.Access <UpdateSysDicCommand>(
                Guid.Parse("b37df2da-ab45-416e-ba58-d703667f300b"),
                "更新系统字典",
                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("sysDic code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Update(entity);

                Global.Happened(new SysDicUpdatedEvent(entity));
            });
            Global.Access <RemoveSysDicCommand>(
                Guid.Parse("ac6af880-89a1-47a4-9596-55e33714db45"),
                "移除系统字典",
                LogEnum.Log,
                action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicData entity     = _dicById[message.EntityId];
                List <Guid> toRemoves = root.SysDicItemSet.GetSysDicItems(entity.Code).Select(a => a.GetId()).ToList();
                foreach (var id in toRemoves)
                {
                    Global.Execute(new RemoveSysDicItemCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>();
                repository.Remove(entity.Id);

                Global.Happened(new SysDicRemovedEvent(entity));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }
Esempio n. 2
0
        public SysDicSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddSysDicCommand>("添加系统字典", 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("dic code can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                if (_dicByCode.ContainsKey(message.Input.Code))
                {
                    throw new DuplicateCodeException();
                }
                SysDicData entity = new SysDicData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                _dicByCode.Add(entity.Code, entity);
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new SysDicAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateSysDicCommand>("更新系统字典", 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("sysDic code can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                SysDicData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new SysDicUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveSysDicCommand>("移除系统字典", LogEnum.DevConsole,
                                                            action: message => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                SysDicData entity     = _dicById[message.EntityId];
                List <Guid> toRemoves = root.SysDicItemSet.GetSysDicItems(entity.Code).Select(a => a.GetId()).ToList();
                foreach (var id in toRemoves)
                {
                    VirtualRoot.Execute(new RemoveSysDicItemCommand(id));
                }
                _dicById.Remove(entity.Id);
                if (_dicByCode.ContainsKey(entity.Code))
                {
                    _dicByCode.Remove(entity.Code);
                }
                var repository = NTMinerRoot.CreateServerRepository <SysDicData>(isUseJson);
                repository.Remove(entity.Id);

                VirtualRoot.Happened(new SysDicRemovedEvent(entity));
            });
        }