private void m_Worker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { if (m_Monitor.Canceled) { m_Worker.CancelAsync(); } else { m_Monitor.SetProgress(e.ProgressPercentage, e.UserState.ToString()); } }
private void DoExport(IProgressMonitor monitor, ExportData exportData, Action <Exception> finishedAction) { m_FinishedAction = finishedAction; m_Worker = new System.ComponentModel.BackgroundWorker(); m_Worker.WorkerReportsProgress = true; m_Worker.WorkerSupportsCancellation = true; m_Worker.DoWork += new System.ComponentModel.DoWorkEventHandler(m_Worker_DoWork); m_Worker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(m_Worker_ProgressChanged); m_Worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(m_Worker_RunWorkerCompleted); m_Monitor = monitor; m_Monitor.SetProgress(0, String.Empty); m_Worker.RunWorkerAsync(exportData); }
private void UpdateBaseMonitor() { ThrowIfCancellationRequested(); if (m_progress.HasValue) { m_baseMonitor.SetProgress((int)(100 * m_progress / m_taskSize), m_text); } else { m_baseMonitor.SetIndeterminate(m_text); } }
private void DoImport(IProgressMonitor monitor, String importFileName, String targetFileName, bool silent, IMessageBoxProvider messageBoxProvider, System.Action <Exception, bool> dataLoaded) { m_Monitor = monitor; m_DataLoadedFunc = dataLoaded; try { long overallSize = 0; bool overWrite = true; bool hasAskedForOverwrite = silent; bool hasInnerFile = false; using (ZipFile file = CreateZipFile(importFileName)) { for (int i = 0; i < file.Count; ++i) { ZipEntry entry = file[i]; if (entry.IsDirectory) { continue; } bool isTagsDbFile; String fileName = GetFileName(entry, out isTagsDbFile); if (fileName == String.Empty) { if (hasInnerFile) { throw new ArgumentException(StringResources.InvalidImportFile); } else { hasInnerFile = true; overallSize += entry.Size; } } else if (isTagsDbFile) { overallSize += entry.Size; } else if (FileHelpers.FileExists(fileName)) { if (!hasAskedForOverwrite) { switch (messageBoxProvider.ShowYesNoCancelBox(StringResources.ImportOverwrite)) { case MessageBoxResult.Yes: overWrite = true; hasAskedForOverwrite = true; break; case MessageBoxResult.No: overWrite = false; hasAskedForOverwrite = true; break; default: return; } } if (overWrite) { overallSize += entry.Size; } } else { overallSize += entry.Size; } } if (!hasInnerFile) { throw new ArgumentException(StringResources.InvalidImportFile); } } ImportData data = new ImportData(); data.Overwrite = overWrite; data.ImportFile = importFileName; data.TargetFile = targetFileName; data.OverallSize = overallSize; m_Worker = new System.ComponentModel.BackgroundWorker(); m_Worker.WorkerReportsProgress = true; m_Worker.WorkerSupportsCancellation = true; m_Worker.DoWork += new System.ComponentModel.DoWorkEventHandler(m_Worker_DoWork); m_Worker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(m_Worker_ProgressChanged); m_Worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(m_Worker_RunWorkerCompleted); m_Monitor.SetProgress(0, String.Empty); m_Worker.RunWorkerAsync(data); } catch (Exception ex) { if (dataLoaded != null) { dataLoaded(ex, false); } } }
private void DoCopyOrMove(FileOpData data) { m_Monitor.SetProgress(0, String.Empty); // determine amount to copy / move long allBytes = 0; foreach (String file in data.UniqueElements.Keys) { allBytes += GetBytes(file); } System.Collections.Generic.Dictionary <String, String> filesMoved = new Dictionary <String, String>(); long currentBytes = 0; int lastPercent = 0; foreach (String file in data.UniqueElements.Keys) { String nameOnly = System.IO.Path.GetFileName(file); String fileTargetPath = System.IO.Path.Combine(data.TargetPath, nameOnly); if (file.Equals(fileTargetPath, StringComparison.InvariantCultureIgnoreCase)) { currentBytes += GetBytes(fileTargetPath); ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath); continue; } if (System.IO.Directory.Exists(file)) { AddMovedFiles(file, fileTargetPath, filesMoved); if (data.Move) { System.IO.Directory.Move(file, fileTargetPath); currentBytes += GetBytes(fileTargetPath); ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath); } else { CopyDirectory(file, fileTargetPath, ref currentBytes, allBytes, ref lastPercent); } } else if (System.IO.File.Exists(file)) { filesMoved[file] = fileTargetPath; if (data.Move) { System.IO.File.Move(file, fileTargetPath); } else { System.IO.File.Copy(file, fileTargetPath, true); } currentBytes += GetBytes(fileTargetPath); ReportProgress(currentBytes, allBytes, ref lastPercent, fileTargetPath); } m_Token.ThrowIfCancellationRequested(); } if (data.Move) { AdaptElementPaths(filesMoved, data.MusicDirectory, data.SoundsDirectory, data.Project); } AdaptTags(filesMoved, data.MusicDirectory, data.Move); }