Exemplo n.º 1
0
        public void Visit(MakeDirectoryCommand command)
        {
            Visit((ICommand)command);

            if (Root.TryFindNode(command.ParentDirectoryId, out var parent) &&
                parent is Directory parentDirectory)
            {
                var existingDirectory = parentDirectory.Children.FirstOrDefault(c => c.Name == command.Name);
                if (existingDirectory == null)
                {
                    var directory = _factory.CreateDirectory(command.Name);
                    parentDirectory.Children.Add(directory);
                    _timestamp.Increment();
                    Message = $"ID={directory.Id}";
                }
                else
                {
                    OnNodeAlreadyExists(command.Name, command.ParentDirectoryId);
                }
            }
            else
            {
                OnDirectoryDoesNotExist(command.ParentDirectoryId);
            }
        }
Exemplo n.º 2
0
 private static void Initialize()
 {
     Factory.Reset();
     Timestamp.Reset();
     _root = Factory.CreateDirectory("root");
 }