Ejemplo n.º 1
0
        public KernelOutputSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddKernelOutputCommand>("添加内核输出组", 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;
                }
                KernelOutputData entity = new KernelOutputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new KernelOutputAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateKernelOutputCommand>("更新内核输出组", 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("KernelOutput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new KernelOutputUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole,
                                                                  action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray();
                if (outputUsers.Length != 0)
                {
                    throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.GetFullName()))}");
                }
                KernelOutputData entity               = _dicById[message.EntityId];
                List <Guid> kernelOutputFilterIds     = root.KernelOutputFilterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var kernelOutputFilterId in kernelOutputFilterIds)
                {
                    VirtualRoot.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId));
                }
                foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds)
                {
                    VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId));
                }
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(isUseJson);
                repository.Remove(message.EntityId);

                VirtualRoot.Happened(new KernelOutputRemovedEvent(entity));
            });
        }
Ejemplo n.º 2
0
        public KernelOutputSet(IServerContext context)
        {
            _context = context;
            #region 接线
            context.AddCmdPath <AddKernelOutputCommand>("添加内核输出组", 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;
                }
                KernelOutputData entity = new KernelOutputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = context.CreateServerRepository <KernelOutputData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new KernelOutputAddedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <UpdateKernelOutputCommand>("更新内核输出组", 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.TryGetValue(message.Input.GetId(), out KernelOutputData entity))
                {
                    return;
                }
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = context.CreateServerRepository <KernelOutputData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new KernelOutputUpdatedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole,
                                                           action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUses = context.KernelSet.AsEnumerable().Where(a => a.KernelOutputId == message.EntityId).ToArray();
                if (outputUses.Length != 0)
                {
                    throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUses.Select(a => a.GetFullName()))}");
                }
                KernelOutputData entity = _dicById[message.EntityId];
                List <Guid> kernelOutputTranslaterIds = context.KernelOutputTranslaterSet.AsEnumerable().Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds)
                {
                    VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId));
                }
                _dicById.Remove(entity.GetId());
                var repository = context.CreateServerRepository <KernelOutputData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new KernelOutputRemovedEvent(message.MessageId, entity));
            }, location: this.GetType());
            #endregion
        }
Ejemplo n.º 3
0
        public KernelOutputSet(INTMinerRoot root)
        {
            _root = root;
            Global.Access <AddKernelOutputCommand>(
                Guid.Parse("142AE86A-C264-40B2-A617-D65E33C7FEE2"),
                "添加内核输出组",
                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;
                }
                KernelOutputData entity = new KernelOutputData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Add(entity);

                Global.Happened(new KernelOutputAddedEvent(entity));
            });
            Global.Access <UpdateKernelOutputCommand>(
                Guid.Parse("2A3CAE7E-D0E2-4E4B-B75B-357EB0BE1AA1"),
                "更新内核输出组",
                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("KernelOutput name can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                KernelOutputData entity = _dicById[message.Input.GetId()];
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Update(entity);

                Global.Happened(new KernelOutputUpdatedEvent(entity));
            });
            Global.Access <RemoveKernelOutputCommand>(
                Guid.Parse("43B565B4-1509-4DC6-9FA4-55D49C79C60A"),
                "移除内核输出组",
                LogEnum.Log,
                action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray();
                if (outputUsers.Length != 0)
                {
                    throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.FullName))}");
                }
                KernelOutputData entity               = _dicById[message.EntityId];
                List <Guid> kernelOutputFilterIds     = root.KernelOutputFilterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList();
                foreach (var kernelOutputFilterId in kernelOutputFilterIds)
                {
                    Global.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId));
                }
                foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds)
                {
                    Global.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId));
                }
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>();
                repository.Remove(message.EntityId);

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