コード例 #1
0
        public KernelOutputTranslaterSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddKernelOutputTranslaterCommand>("添加内核输出翻译器", LogEnum.DevConsole,
                                                                         action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId))
                {
                    _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputTranslaterData>());
                }
                _dicByKernelOutputId[entity.KernelOutputId].Add(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new KernelOutputTranslaterAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole,
                                                                            action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                string regexPattern = entity.RegexPattern;
                string color        = entity.Color;
                entity.Update(message.Input);
                if (entity.RegexPattern != regexPattern)
                {
                    _regexDic.Remove(entity);
                }
                if (entity.Color != color)
                {
                    _colorDic.Remove(entity);
                }
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new KernelOutputTranslaterUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole,
                                                                            action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                _dicByKernelOutputId[entity.KernelOutputId].Remove(entity);
                _colorDic.Remove(entity);
                _regexDic.Remove(entity);
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson);
                repository.Remove(entity.Id);

                VirtualRoot.Happened(new KernelOutputTranslaterRemovedEvent(entity));
            });
            _root.ServerContextOn <SysDicItemUpdatedEvent>($"{Consts.LogColorDicKey}字典项更新后刷新翻译器内存", LogEnum.DevConsole,
                                                           action: message => {
                if (!_root.SysDicSet.TryGetSysDic(Consts.LogColorDicKey, out ISysDic dic))
                {
                    return;
                }
                if (message.Source.DicId != dic.GetId())
                {
                    return;
                }
                foreach (var entity in _dicById.Values)
                {
                    if (entity.Color == message.Source.Code)
                    {
                        _colorDic.Remove(entity);
                    }
                }
            });
        }
コード例 #2
0
        public KernelOutputTranslaterSet(IServerContext context)
        {
            _context = context;
            context.AddCmdPath <AddKernelOutputTranslaterCommand>("添加内核输出翻译器", LogEnum.DevConsole,
                                                                  action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId))
                {
                    _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputTranslaterData>());
                }
                _dicByKernelOutputId[entity.KernelOutputId].Add(entity);
                var repository = context.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterAddedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole,
                                                                     action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty");
                }
                if (!_dicById.TryGetValue(message.Input.GetId(), out KernelOutputTranslaterData entity))
                {
                    return;
                }
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                string regexPattern = entity.RegexPattern;
                entity.Update(message.Input);
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = context.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterUpdatedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole,
                                                                     action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                _dicByKernelOutputId[entity.KernelOutputId].Remove(entity);
                _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer());
                var repository = context.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Remove(entity.Id);

                VirtualRoot.RaiseEvent(new KernelOutputTranslaterRemovedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }
コード例 #3
0
        public KernelOutputTranslaterSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelOutputTranslaterCommand>(
                Guid.Parse("d9da43ad-8fb7-4d6b-a8c7-ac0c1bbc4dd3"),
                "添加内核输出翻译器",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty");
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                if (!_dicByKernelId.ContainsKey(entity.KernelId))
                {
                    _dicByKernelId.Add(entity.KernelId, new List <KernelOutputTranslaterData>());
                }
                _dicByKernelId[entity.KernelId].Add(entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Add(entity);

                Global.Happened(new KernelOutputTranslaterAddedEvent(entity));
            });
            Global.Access <UpdateKernelOutputTranslaterCommand>(
                Guid.Parse("9e22fc7d-41da-4291-8dde-d8282f81d188"),
                "更新内核输出翻译器",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.RegexPattern))
                {
                    throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.Input.GetId()];
                string regexPattern = entity.RegexPattern;
                string color        = entity.Color;
                entity.Update(message.Input);
                if (entity.RegexPattern != regexPattern)
                {
                    _regexDic.Remove(entity);
                }
                if (entity.Color != color)
                {
                    _colorDic.Remove(entity);
                }
                _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Update(entity);

                Global.Happened(new KernelOutputTranslaterUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelOutputTranslaterCommand>(
                Guid.Parse("7e76b569-aa52-492a-ae41-f2e0a22ffa9b"),
                "移除内核输出翻译器",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelOutputTranslaterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.Id);
                _dicByKernelId[entity.KernelId].Remove(entity);
                _colorDic.Remove(entity);
                _regexDic.Remove(entity);
                _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>();
                repository.Remove(entity.Id);

                Global.Happened(new KernelOutputTranslaterRemovedEvent(entity));
            });
            Global.Access <SysDicItemUpdatedEvent>(
                Guid.Parse("de662262-bd05-4cae-ba6e-843f18541966"),
                "LogColor字典项更新后刷新翻译器内存",
                LogEnum.None,
                action: message => {
                ISysDic dic;
                if (!_root.SysDicSet.TryGetSysDic("LogColor", out dic))
                {
                    return;
                }
                if (message.Source.DicId != dic.GetId())
                {
                    return;
                }
                foreach (var entity in _dicById.Values)
                {
                    if (entity.Color == message.Source.Code)
                    {
                        _colorDic.Remove(entity);
                    }
                }
            });
            BootLog.Log(this.GetType().FullName + "接入总线");
        }