private void ExecuteNewFolderCommand() { var items = SourcePane.Items.Select(item => item.Name).ToList(); var wkDirs = DirectoryStructure.WellKnownDirectoriesOf(SourcePane.CurrentFolder.Path); var suggestion = wkDirs.Where(d => !items.Contains(d)).Select(d => new InputDialogOptionViewModel { Value = d, DisplayName = TitleRecognizer.GetTitle(d) }).ToList(); var name = WindowManager.ShowTextInputDialog(Resx.AddNewFolder, Resx.FolderName + Strings.Colon, string.Empty, suggestion); if (name == null) { return; } name = name.Trim(); if (name == string.Empty) { WindowManager.ShowMessage(Resx.AddNewFolder, Resx.CannotCreateFolderWithNoName); return; } //var invalidChars = Path.GetInvalidFileNameChars(); //if (invalidChars.Any(name.Contains)) //{ // WindowManager.ShowMessage(Resx.AddNewFolder, Resx.CannotCreateFolderWithInvalidCharacters); // return; //} var path = string.Format("{0}{1}", SourcePane.CurrentFolder.Path, name); WorkHandler.Run(() => SourcePane.CreateFolder(path), result => NewFolderSuccess(result, name), NewFolderError); }
public void AbortTransfer() { if (SourcePane == null) { return; } _isAborted = true; if (_remoteCopy == RemoteCopyMode.Disabled) { SourcePane.Abort(); if (TargetPane != null) { TargetPane.Abort(); } } lock (_queue) { var actualItem = _queue.Peek(); _queue.Clear(); _queue.Enqueue(actualItem); } if (_isPaused) { UIThread.BeginRun(FinishTransfer); } }
private void ExecutePauseCommand() { IsPaused = true; SourcePane.Abort(); if (TargetPane != null) { TargetPane.Abort(); } }
private void FinishTransfer() { _queue = null; _statistics.TimeSpentWithTransfer += _elapsedTimeMeter.Elapsed; if (_remoteCopy != RemoteCopyMode.Disabled) { CloseTelnetSession(); } _elapsedTimeMeter.Stop(); ProgressState = TaskbarItemProgressState.None; var args = new TransferFinishedEventArgs(this, SourcePane, TargetPane); if (_shutdown != Shutdown.Disabled && (UserAction == FileOperation.Copy || UserAction == FileOperation.Move)) { ShutdownDialogViewModel vm; if (_shutdown.HasFlag(Shutdown.Xbox)) { var ftp = Pane <FtpContentViewModel>(); if (ftp == SourcePane) { _sourceChanged = false; } if (ftp == TargetPane) { _targetChanged = false; } vm = new ShutdownDialogViewModel(WindowManager, _shutdown, ftp); } else { vm = new ShutdownDialogViewModel(WindowManager, _shutdown); } WindowManager.ShowModelessWindow <ShutdownDialog, ShutdownDialogViewModel>(vm); } if (_sourceChanged) { SourcePane.Refresh(false); } if (_targetChanged && TargetPane != null) { TargetPane.Refresh(false); } EventAggregator.GetEvent <TransferFinishedEvent>().Publish(args); SourcePane = null; TargetPane = null; }
private void NewFolderSuccess(TransferResult result, string name) { if (result != TransferResult.Ok) { WindowManager.ShowMessage(Resx.AddNewFolder, string.Format(Resx.FolderAlreadyExists, name)); return; } SourcePane.Refresh(false, () => { var newFolder = SourcePane.Items.SingleOrDefault(item => item.Name == name); if (newFolder != null) { SourcePane.CurrentRow = newFolder; } }); }
private void DoTransform() { try { if (_preferences.SaveOnTransform) { SourcePane.SaveFile("Sources"); TransformPane.SaveFile("Transforms"); DocumentsPane.SaveFile("Documents"); IncludesPane.SaveFile("Includes"); } var source = SourcePane.JsonContent; var transform = TransformPane.JsonContent; if (string.IsNullOrWhiteSpace(source)) { MessageBox.Show("Load or enter in a source document", "JTranEdit", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (string.IsNullOrWhiteSpace(transform)) { MessageBox.Show("Load or enter in a transform", "JTranEdit", MessageBoxButton.OK, MessageBoxImage.Error); return; } var transformer = new Transformer(_preferences); var result = transformer.Transform(source, transform); OutputPane.JsonContent = result; } catch (Exception ex) { MessageBox.Show(ex.Message, "JTranEdit", MessageBoxButton.OK, MessageBoxImage.Error); } }
internal TransferErrorDialogResult ShowCorrespondingErrorDialog(Exception exception, bool feedbackNeeded = true) { var transferException = exception as TransferException; var exceptionType = transferException != null ? transferException.Type : TransferErrorType.NotSpecified; _elapsedTimeMeter.Stop(); var result = new TransferErrorDialogResult(ErrorResolutionBehavior.Cancel); switch (exceptionType) { case TransferErrorType.NotSpecified: { if (feedbackNeeded) { result = _skipAll ?? WindowManager.ShowIoErrorDialog(exception); } else { WindowManager.ShowMessage(Resx.IOError, exception.Message); } } break; case TransferErrorType.WriteAccessError: case TransferErrorType.NotSupporterCharactersInPath: case TransferErrorType.NameIsTooLong: case TransferErrorType.PathIsTooLong: { if (_skipAll != null) { result = _skipAll; } else { if (_queue == null) { WindowManager.ShowMessage(Resx.IOError, exception.Message); } else { var sourceFile = _queue.Peek().FileSystemItem; var viewModel = WindowManager.GetWriteErrorDialogViewModel(transferException); if (exceptionType == TransferErrorType.WriteAccessError) { if (IsResumeSupported && sourceFile.Size > transferException.TargetFileSize) { viewModel.IsResumeEnabled = true; viewModel.IsResumeAllEnabled = true; } if (transferException.TargetFile != null) { TargetPane.GetItemViewModel(transferException.TargetFile); } } SourcePane.GetItemViewModel(sourceFile.Path); result = WindowManager.ShowWriteErrorDialog(viewModel); } } } break; case TransferErrorType.LostConnection: var ftp = (FtpContentViewModel)transferException.Pane; if (WindowManager.ShowReconnectionDialog(exception) == true) { try { ftp.RestoreConnection(); ftp.Refresh(false); } catch (Exception ex) { WindowManager.ShowMessage(Resx.ConnectionFailed, string.Format(Resx.CannotReestablishConnection, ex.Message)); ftp.CloseCommand.Execute(); } } else { ftp.CloseCommand.Execute(); } break; default: throw new NotSupportedException("Invalid transfer error type: " + exceptionType); } //TODO: refactor scoping if (result.Scope == CopyActionScope.All) { if (result.Action.HasValue) { _rememberedCopyAction = result.Action.Value; } if (result.Behavior == ErrorResolutionBehavior.Skip) { _skipAll = result; } } _elapsedTimeMeter.Start(); return(result); }
private OperationResult ExecuteDelete(QueueItem item) { return(new OperationResult(SourcePane.Delete(item.FileSystemItem))); }
private OperationResult ExecuteCopy(QueueItem queueitem, CopyAction?action, string rename) { var item = queueitem.FileSystemItem; var sourcePath = item.GetRelativePath(SourcePane.CurrentFolder.Path); var targetPath = TargetPane.GetTargetPath(sourcePath); TransferResult result; switch (item.Type) { case ItemType.Directory: case ItemType.Link: if (TargetPane.CreateFolder(targetPath) == TransferResult.Ok) { var i = 1; QueueItem qi; while (i < _queue.Count && (qi = _queue.ElementAt(i)) != null && qi.FileSystemItem.Path.StartsWith(item.Path)) { qi.CopyAction = CopyAction.Overwrite; i++; } } result = TransferResult.Ok; break; case ItemType.File: if (action == CopyAction.Rename && !string.IsNullOrEmpty(rename)) { var r = new Regex(string.Format(RenameFromPattern, item.Name), RegexOptions.IgnoreCase); targetPath = r.Replace(targetPath, string.Format(RenameToPattern, rename)); action = CopyAction.CreateNew; } var a = action ?? _rememberedCopyAction; FileMode mode; FileExistenceInfo exists; long startPosition = 0; switch (a) { case CopyAction.CreateNew: //TODO: check what happens if targetPath contains spec.char exists = TargetPane.FileExists(targetPath); if (exists) { throw new TransferException(TransferErrorType.WriteAccessError, Resx.TargetAlreadyExists) { SourceFile = item.Path, TargetFile = targetPath, TargetFileSize = exists.Size } } ; mode = FileMode.CreateNew; break; case CopyAction.Overwrite: mode = FileMode.Create; break; case CopyAction.OverwriteSmaller: var target = TargetPane.FileExists(targetPath); if (target.Exists && target.Size >= item.Size) { return(new OperationResult(TransferResult.Skipped, targetPath)); } mode = FileMode.Create; break; case CopyAction.Resume: mode = FileMode.Append; exists = TargetPane.FileExists(targetPath); if (exists) { startPosition = exists.Size; } break; default: throw new ArgumentException("Invalid Copy action: " + action); } UIThread.Run(() => { TransferAction = GetCopyActionText(); }); switch (_remoteCopy) { case RemoteCopyMode.Disabled: using (var targetStream = TargetPane.GetStream(targetPath, mode, FileAccess.Write, startPosition)) { result = SourcePane.CopyStream(item, targetStream, startPosition) ? TransferResult.Ok : TransferResult.Aborted; } break; case RemoteCopyMode.Download: var sourceName = RemoteChangeDirectory(item.Path); Telnet.Download(sourceName, targetPath, item.Size ?? 0, startPosition, (p, t, total, sp) => OnTransferProgressChanged(new TransferProgressChangedEventArgs(p, t, total, sp))); result = TransferResult.Ok; break; case RemoteCopyMode.Upload: var targetName = RemoteChangeDirectory(targetPath); Telnet.Upload(targetName, item.Path, item.Size ?? 0, startPosition, (p, t, total, sp) => OnTransferProgressChanged(new TransferProgressChangedEventArgs(p, t, total, sp))); result = TransferResult.Ok; break; default: throw new NotSupportedException(); } break; default: throw new NotSupportedException(); } return(new OperationResult(result, targetPath)); }