Exemple #1
0
        public async Task ExecuteRename()
        {
            var    fvm     = Files.Where(x => x.IsSelected).Single();
            string newName = _dialogService.Prompt(ViewModelStrings.GetRenameCaption(), ViewModelStrings.GetRenameQuestion(), fvm.Name);

            if (newName.Contains("/"))
            {
                _dialogService.Show(ViewModelStrings.GetNameSlashError());
                return;
            }
            if (string.IsNullOrWhiteSpace(newName))
            {
                return;
            }
            if (Files.Any(x => string.Equals(newName, x.Name, StringComparison.InvariantCultureIgnoreCase) && fvm.Type == x.Type))
            {
                _dialogService.Show(ViewModelStrings.GetFileExists());
                return;
            }
            string newPath = fvm.FullName.Substring(0, fvm.FullName.LastIndexOf('/')) + newName;

            _cancellationTokenSource = new CancellationTokenSource();
            ServiceResult renameResult;

            if (fvm.Type == FtpFileSystemObjectType.File)
            {
                renameResult = await _wFtpClient.MoveFileAsync(fvm.FullName, newPath, _cancellationTokenSource.Token);
            }
            else
            {
                renameResult = await _wFtpClient.MoveDirectoryAsync(fvm.FullName, newPath, _cancellationTokenSource.Token);
            }
            if (!renameResult.Success)
            {
                _dialogService.Show(renameResult.ErrorMessage);
            }
            await ExecuteRefresh();
        }
Exemple #2
0
        public async Task ExecuteDelete()
        {
            if (!_dialogService.YesNo(ViewModelStrings.GetConfirmDelete()) == true)
            {
                return;
            }
            foreach (var fvm in Files.Where(x => x.IsSelected))
            {
                ServiceResult result;
                if (fvm.Type == FtpFileSystemObjectType.Directory)
                {
                    _cancellationTokenSource = new CancellationTokenSource();
                    result = await _wFtpClient.DeleteDirectoryAsync(fvm.FullName, _cancellationTokenSource.Token);

                    _cancellationTokenSource.Dispose();
                }
                else if (fvm.Type == FtpFileSystemObjectType.File)
                {
                    _cancellationTokenSource = new CancellationTokenSource();
                    result = await _wFtpClient.DeleteFileAsync(fvm.FullName, _cancellationTokenSource.Token);

                    _cancellationTokenSource.Dispose();
                }
                else
                {
                    continue;
                }
                if (!result.Success)
                {
                    _dialogService.Show(ViewModelStrings.CouldNotDelete(fvm.FullName, result.ErrorMessage));
                    await ExecuteRefresh();

                    break;
                }
            }
            await ExecuteRefresh();
        }
Exemple #3
0
        public async Task ExecuteUp()
        {
            int length = Directory.LastIndexOf('/');

            // to account for URLs of the form "/Hello/"
            if (length != 0 && length == Directory.Length - 1)
            {
                Directory = Directory.Substring(0, Directory.Length - 1);
                length    = Directory.LastIndexOf('/');
            }
            // to account for root folder "/"
            if (length == 0)
            {
                length = 1;
            }
            // to account for errors
            else if (length < 0)
            {
                _dialogService.Show(ViewModelStrings.GetCouldNotParseURL());
                return;
            }
            Directory = Directory.Substring(0, length);
            await ExecuteRefresh();
        }