Ejemplo n.º 1
0
        public KernelInputSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            VirtualRoot.Window <AddKernelInputCommand>("添加内核输入组", LogEnum.DevConsole,
                                                       action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = new KernelInputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new KernelInputAddedEvent(entity));
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <UpdateKernelInputCommand>("更新内核输入组", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("KernelInput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new KernelInputUpdatedEvent(entity));
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <RemoveKernelInputCommand>("移除内核输入组", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>(isUseJson);
                repository.Remove(message.EntityId);

                VirtualRoot.Happened(new KernelInputRemovedEvent(entity));
            }).AddToCollection(root.ContextHandlers);
        }
Ejemplo n.º 2
0
        public KernelInputSet(IServerContext context)
        {
            context.AddCmdPath <AddKernelInputCommand>("添加内核输入组", LogEnum.DevConsole,
                                                       action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = new KernelInputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelInputAddedEvent(message.Id, entity));
            }, location: this.GetType());
            context.AddCmdPath <UpdateKernelInputCommand>("更新内核输入组", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException($"{nameof(message.Input.Name)} can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelInputUpdatedEvent(message.Id, entity));
            }, location: this.GetType());
            context.AddCmdPath <RemoveKernelInputCommand>("移除内核输入组", LogEnum.DevConsole,
                                                          action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new KernelInputRemovedEvent(message.Id, entity));
            }, location: this.GetType());
        }
Ejemplo n.º 3
0
        public KernelInputSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelInputCommand>(
                Guid.Parse("62D0B345-26F8-42BA-B7CD-E547C2B298C9"),
                "添加内核输入组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = new KernelInputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Add(entity);

                Global.Happened(new KernelInputAddedEvent(entity));
            });
            Global.Access <UpdateKernelInputCommand>(
                Guid.Parse("FED12C08-7BD7-4A8E-BD0B-A19075F4E8C4"),
                "更新内核输入组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Name))
                {
                    throw new ValidationException("KernelInput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Update(entity);

                Global.Happened(new KernelInputUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelInputCommand>(
                Guid.Parse("2227F6B9-5A2A-42AB-8147-05E245E2872F"),
                "移除内核输入组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                KernelInputData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelInputData>();
                repository.Remove(message.EntityId);

                Global.Happened(new KernelInputRemovedEvent(entity));
            });
            Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线");
        }