示例#1
0
        public FragmentWriterSet(IServerContext context)
        {
            _context = context;
            context.AddCmdPath <AddFragmentWriterCommand>("添加命令行片段书写器", 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;
                }
                if (string.IsNullOrEmpty(message.Input.Body))
                {
                    throw new ValidationException("FragmentWriter body can't be null or empty");
                }
                FragmentWriterData entity = new FragmentWriterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = context.CreateServerRepository <FragmentWriterData>();
                repository.Add(entity);

                VirtualRoot.RaiseEvent(new FragmentWriterAddedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <UpdateFragmentWriterCommand>("更新命令行片段书写器", LogEnum.DevConsole,
                                                             action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Body))
                {
                    throw new ValidationException("FragmentWriter body can't be null or empty");
                }
                if (!_dicById.TryGetValue(message.Input.GetId(), out FragmentWriterData entity))
                {
                    return;
                }
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = context.CreateServerRepository <FragmentWriterData>();
                repository.Update(entity);

                VirtualRoot.RaiseEvent(new FragmentWriterUpdatedEvent(message.MessageId, entity));
            }, location: this.GetType());
            context.AddCmdPath <RemoveFragmentWriterCommand>("移除组", LogEnum.DevConsole,
                                                             action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                FragmentWriterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = context.CreateServerRepository <FragmentWriterData>();
                repository.Remove(message.EntityId);

                VirtualRoot.RaiseEvent(new FragmentWriterRemovedEvent(message.MessageId, entity));
            }, location: this.GetType());
        }
示例#2
0
        public FragmentWriterSet(INTMinerRoot root)
        {
            _root = root;
            _root.ServerContextWindow <AddFragmentWriterCommand>("添加命令行片段书写器", 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;
                }
                if (string.IsNullOrEmpty(message.Input.Body))
                {
                    throw new ValidationException("FragmentWriter body can't be null or empty");
                }
                FragmentWriterData entity = new FragmentWriterData().Update(message.Input);
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Add(entity);

                VirtualRoot.Happened(new FragmentWriterAddedEvent(entity));
            });
            _root.ServerContextWindow <UpdateFragmentWriterCommand>("更新命令行片段书写器", LogEnum.DevConsole,
                                                                    action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (string.IsNullOrEmpty(message.Input.Body))
                {
                    throw new ValidationException("FragmentWriter body can't be null or empty");
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                FragmentWriterData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Update(entity);

                VirtualRoot.Happened(new FragmentWriterUpdatedEvent(entity));
            });
            _root.ServerContextWindow <RemoveFragmentWriterCommand>("移除组", LogEnum.DevConsole,
                                                                    action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                FragmentWriterData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>();
                repository.Remove(message.EntityId);

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