private void FileIOProgress_Load(object sender, EventArgs e) { txtPath1.Text = fileCopyInfo.SourcePath; txtPath2.Text = fileCopyInfo.DestinationPath; Cursor = Cursors.WaitCursor; CopyWorker.RunWorkerAsync(fileCopyInfo); }
private void CopyWorker_DoWork(object sender, DoWorkEventArgs e) { FileCopyInfo finfo = (FileCopyInfo)e.Argument; CopyDirectory(finfo.SourcePath, finfo.DestinationPath); CopyWorker.ReportProgress(100); }
private int CopyDirectory(string Src, string Dst) { int progress = 0; if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar) { Dst += Path.DirectorySeparatorChar; } if (!Directory.Exists(Dst)) { Directory.CreateDirectory(Dst); } if (progress < 100) { progress++; CopyWorker.ReportProgress(progress); } String[] Files = Directory.GetFileSystemEntries(Src); foreach (string Element in Files) { // Sub directories if (Directory.Exists(Element)) { progress += CopyDirectory(Element, Dst + Path.GetFileName(Element)); if (progress > 100) { progress = 100; } CopyWorker.ReportProgress(progress); } // Files in directory else { File.Copy(Element, Dst + Path.GetFileName(Element), true); if (progress < 100) { progress++; CopyWorker.ReportProgress(progress); } } } return(progress); }
public void SetUp() { fileSystemMock = new Mock <IFileSystem>(); fileHelperMock = new Mock <IFileHelper>(); generatorMock = new Mock <IUniqueCharsGenerator>(); settingsMock = new Mock <CopyWorkerSettings>(); _uiContextStub = new ContextStub(); _backgroundWorkerMock = new Mock <IBackgroundWorker>(); _worker = new CopyWorker(fileSystemMock.Object, fileHelperMock.Object, _uiContextStub, _backgroundWorkerMock.Object, generatorMock.Object); _parameters = new CopyWorkerParameters { Settings = settingsMock.Object, OnStarted = () => { }, OnFileChanged = (f) => { }, OnProgressChanged = (i) => { }, OnFinished = () => { }, OnFailed = (s) => { }, OnCancelled = () => { } }; }
private void btnStop_Click(object sender, EventArgs e) { CopyWorker.CancelAsync(); CloseForm(); }