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
        public void Visit(MakeDirectoryCommand command)
        {
            if (!TryGetPrefixedPathTo(command.ParentDirectoryId, out var pathToParent))
            {
                return;
            }

            var path = Path.Combine(pathToParent, command.Name);

            Directory.CreateDirectory(path);
        }