public void Visit(FileMoveCommand command)
        {
            Visit((ICommand)command);
            command.PreMoveTree = Root.Clone();

            if (Root.TryFindNode(command.FileId, out var file) &&
                file is File)
            {
                if (Root.TryFindParent(command.FileId, out var directoryNode) &&
                    directoryNode is Directory directory)
                {
                    if (Root.TryFindNode(command.DestinationDirectoryId, out var destinationDirectoryNode) &&
                        destinationDirectoryNode is Directory destinationDirectory)
                    {
                        directory.Children.Remove(file);
                        destinationDirectory.Children.Add(file);
                        _timestamp.Increment();
                    }
                    else
                    {
                        OnDirectoryDoesNotExist(command.DestinationDirectoryId);
                    }
                }
                else
                {
                    Message = $"Node with {command.FileId} has no parent.";
                }
            }
            else
            {
                OnFileDoesNotExist(command.FileId);
            }
        }
Example #2
0
        private async Task ExecuteConsoleCommandFileMove(Options options)
        {
            var fileMoveCommand = new FileMoveCommand(options);
            await _mediator.Send(fileMoveCommand);

            LogInformationMessage($"File \"{fileMoveCommand.OldFileName}\" has been moved to {fileMoveCommand.NewFileName}");
            _consolePrinter.PrintFileMovedSuccessful(fileMoveCommand.OldFileName, fileMoveCommand.NewFileName);
        }
Example #3
0
        public void Visit(FileMoveCommand command)
        {
            if (command.PreMoveTree == null)
            {
                return;
            }
            if (!TryGetPrefixedPathTo(command.PreMoveTree, command.FileId, out var filePath))
            {
                return;
            }
            if (!TryGetPrefixedPathTo(command.PreMoveTree, command.DestinationDirectoryId,
                                      out var destinationDirectoryPath))
            {
                return;
            }

            var fileName            = Path.GetFileName(filePath);
            var destinationFilePath = Path.Combine(destinationDirectoryPath, fileName);

            File.Move(filePath, destinationFilePath);
        }