public void TestCopyValidFile() { files.Clear(); fileName = "D:\\Temp\\copyValid.txt"; files.Add(fileName); ModelProcessCopy model = new ModelProcessCopy(); model = CreateModel(model, files); CreateModel(model, files); string newFile = model.DestPath + "\\copyValid.txt"; if (!File.Exists(fileName)) { File.Create(fileName).Close(); } CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false); try { CommandManager.Execute(cmdCopy); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { Assert.True(!cmdCopy.HasError && File.Exists(newFile)); if (File.Exists(newFile)) { File.Delete(newFile); } } }
private void OnFilePaste(object sender, EventArgs e) { try { if (Clipboard.ContainsData(DataFormats.FileDrop)) { var paths = new StringCollection(); paths = Clipboard.GetFileDropList(); modelCopy = new ModelProcessCopy(); modelCopy.Source = paths.Cast <string>().ToList(); modelCopy.DestPath = CurrentPath; modelCopy.SourceCurrentPath = Directory.GetParent(modelCopy.Source[0]).FullName; var cmd = new CommandCopyFiles(modelCopy.Source.Count > 0 && !String.IsNullOrEmpty(modelCopy.DestPath), strings.noSelectedFiles, true, modelCopy, isMove); var presenterProgress = new PresenterProgress(); if (modelCopy != null) { presenterProgress.AddModel(modelCopy); } presenterProgress.AddCommand(cmd); presenterProgress.Show(); CommandManager.Execute(cmd); } if (isMove) { Clipboard.Clear(); } } catch (Exception ex) { MyLog.logger.Error(ex.StackTrace); view.MessageShow(ex.Message, strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CreateProgressForm(ModelProcessCopy model, CommandCopyFiles cmd) { _presenterProgress = new PresenterProgress(); if (model != null) { _presenterProgress.AddModel(model); } _presenterProgress.AddCommand(cmd); _presenterProgress.Show(); }
internal void AddCommand(CommandCopyFiles cmd) { command = cmd; if (command != null) { command.OnStarted += OnCopyStarted; command.OnPaused += OnPaused; command.OnCanceled += OnCancelChanged; command.OnFinished += OnFinishedChanged; command.OnResumed += OnCommandResume; } }
private void OnMovePerformed(object sender, EventArgs e) { var model = new ModelProcessCopy(); model = CreateNewModel(model); bool condition = model.Source.Count > 0; var cmd = new CommandCopyFiles(condition, strings.noSelectedFiles, true, model, true); if (condition) { CreateProgressForm(model, cmd); } CommandManager.Execute(cmd); }
private void OnDragDropped(object sender, EventArgs e) { var items = view.GetSelectedItems(); List <string> selectedItems = new List <string>(); ListViewItem itemDest = view.GetItemDest; foreach (ListViewItem item in items) { if (String.Equals(item.Text, prev, StringComparison.CurrentCultureIgnoreCase)) { selectedItems.Add(fromPath); } else if (fromPath.Length <= 3) { selectedItems.Add(Path.Combine(fromPath, item.Text + item.SubItems[1].Text)); } else { selectedItems.Add(Path.Combine(fromPath, item.Text + item.SubItems[1].Text)); } } modelCopy = new ModelProcessCopy(); modelCopy.Source = selectedItems; if (itemDest != null && !File.Exists(Path.Combine(CurrentPath, itemDest.Text + itemDest.SubItems[1].Text))) { modelCopy.DestPath = Path.Combine(CurrentPath, itemDest.Text); } else { modelCopy.DestPath = CurrentPath; } modelCopy.SourceCurrentPath = Directory.GetParent(modelCopy.Source[0]).FullName; var cmd = new CommandCopyFiles(modelCopy.Source.Count > 0 && !String.IsNullOrEmpty(modelCopy.DestPath), strings.noSelectedFiles, false, modelCopy, false); var presenterProgress = new PresenterProgress(); if (modelCopy != null) { presenterProgress.AddModel(modelCopy); } presenterProgress.AddCommand(cmd); presenterProgress.Show(); CommandManager.Execute(cmd); }
public void TestReplaceInvalidFile() { files.Clear(); fileName = "D:\\Temp\\invalidFile.txt"; files.Add(fileName); ModelProcessCopy model = new ModelProcessCopy(); model = CreateModel(model, files); CreateModel(model, files); try { CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false); CommandManager.Execute(cmdCopy); Assert.True(!cmdCopy.HasError); } catch (Exception ex) { Assert.Fail(ex.Message + " " + ex.StackTrace); } }
public void TestCopyInValidFile() { string fileName = "D:\\Test\\testInValid.txt"; List <string> files = new List <string>(); files.Add(fileName); ModelProcessCopy model = new ModelProcessCopy(); model = CreateModel(model, files); try { CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false); CommandManager.Execute(cmdCopy); Assert.True(!cmdCopy.HasError); } catch (Exception ex) { Assert.Fail(ex.Message + " " + ex.StackTrace); } }