/// <summary> /// Count all selected files in directroy /// </summary> /// <param name="directory">Directory to count</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> private void CountRecursive_Selected(DirectoryInfo directory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e) { _ = scope; //Leafe if the key didn't exists or if no files are selected if (!this._project.ToBackupFiles.ContainsKey(directory.FullName) || this._project.ToBackupFiles[directory.FullName].Count == 0) { return; } // Search for files in selected directory foreach (System.IO.FileInfo FileItem in directory.GetFiles().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } //Count up Files an Bytes if file is selected if (this._project.ToBackupFiles[directory.FullName].Contains(FileItem.FullName)) { this._progress.TotalFiles.MaxValue++; this._progress.TotalBytes.MaxValue += FileItem.Length; } //Report Progress worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress)); } }
/// <summary> /// Count no directroy, subdirectory and files /// </summary> /// <param name="directory">Directory to count</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> private void CountRecursive_Nothing(DirectoryInfo directory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e) { _ = directory; _ = scope; _ = worker; _ = e; //Absolutly nothing to do return; }
/// <summary> /// Count recursive all elements in directory an subdirectory, sepending of the scope /// </summary> /// <param name="directory">Directory to count</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> private void CountRecursive(DirectoryInfo directory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e) { try { //Check for existing directory if (!directory.Exists) { return; } // Report Progress this._progress.TotalDirectories.MaxValue++; this._progress.DirectroyFiles.ElemenName = directory.FullName; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress)); //Count Elements switch (scope) { case Project.DirectoryScope.All: this.CountRecursive_All(directory, scope, worker, e); // Search for files in sub directorys foreach (DirectoryInfo DirectoryItem in directory.GetDirectories().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } this.CountRecursive(DirectoryItem, scope, worker, e); } break; case Project.DirectoryScope.Nothing: this.CountRecursive_Nothing(directory, scope, worker, e); break; case Project.DirectoryScope.Selected: this.CountRecursive_Selected(directory, scope, worker, e); break; default: break; } } catch (Exception ex) { _ = ex.Message; } }
/// <summary> /// Count all directroy, subdirectory and files /// </summary> /// <param name="directory">Directory to count</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> private void CountRecursive_All(DirectoryInfo directory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e) { _ = scope; // Search for files in selected directory foreach (FileInfo FileItem in directory.GetFiles().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } //Count up Files an Bytes this._progress.TotalFiles.MaxValue++; this._progress.TotalBytes.MaxValue += FileItem.Length; //Report Progress worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress)); } }
/// <summary> /// Count recursive all elements in directory an subdirectory, sepending of the scope /// </summary> /// <param name="directory">A string that specifice the directory to count</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> private void CountRecursive(string directory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e) { this.CountRecursive(new DirectoryInfo(directory), scope, worker, e); }
/// <summary> /// Copy recursive all elements in directory an subdirectory, sepending of the scope /// </summary> /// <param name="copyMode">The copy mode</param> /// <param name="sourceDirectory">Source directroy to copy</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for copy</param> /// <param name="e">Provides data for the BackgroundWorker</param> /// <param name="exception">Exception of the process</param> /// <returns>Exception level of the copy process</returns> private TaskException.ExceptionLevel CopyRecursive(CopyItems.CopyMode copyMode, DirectoryInfo sourceDirectory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e, out Exception exception) { exception = null; DirectoryCreator CreateDirectory = new DirectoryCreator(); DirectoryInfo TargetDirectory = null;; try { // Get Target Directory TargetDirectory = new DirectoryInfo(CreateDirectory.GetTargetFullName(copyMode, sourceDirectory, this._project.Settings)); // Exit if cancelation pending if (worker.CancellationPending) { e.Cancel = true; return(TaskException.ExceptionLevel.NoException); } //Check for existing directory if (!sourceDirectory.Exists) { this._progress.Exception.Exception = new Exception(Properties.Stringtable._0x000C, null); this._progress.Exception.Level = TaskException.ExceptionLevel.Slight; this._progress.Exception.Source = sourceDirectory.FullName; this._progress.Exception.Target = TargetDirectory.FullName; worker.ReportProgress((int)TaskControle.TaskStep.Exception, new ProgressState(this._progress, true)); return(TaskException.ExceptionLevel.Slight); } // Create target directory, stop creating directory if directory can't created withoud excpetion switch (CreateDirectory.TargetDirectory(sourceDirectory, TargetDirectory, worker, this._progress, out exception, this)) { case TaskException.ExceptionLevel.Critical: return(TaskException.ExceptionLevel.Critical); case TaskException.ExceptionLevel.Medium: return(TaskException.ExceptionLevel.Medium); case TaskException.ExceptionLevel.Slight: return(TaskException.ExceptionLevel.Slight); default: //No exception, nothing to do break; } // Report Progress this._progress.DirectroyFiles.ElemenName = sourceDirectory.FullName; worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress)); //Copy Files switch (scope) { case Project.DirectoryScope.All: if (this.CopyAllFiles(sourceDirectory, TargetDirectory, worker, e, out exception) == TaskException.ExceptionLevel.Critical) { return(TaskException.ExceptionLevel.Critical); } // Copy files in sub directorys if there is access to the directory if (OLKI.Toolbox.DirectoryAndFile.Directory.CheckAccess(sourceDirectory)) { foreach (DirectoryInfo NextSourceDirectory in sourceDirectory.GetDirectories().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return(TaskException.ExceptionLevel.NoException); } if (this.CopyRecursive(copyMode, NextSourceDirectory, scope, worker, e, out exception) == TaskException.ExceptionLevel.Critical) { return(TaskException.ExceptionLevel.Critical); } } } break; case Project.DirectoryScope.Nothing: if (this.CopyNoFiles(sourceDirectory, TargetDirectory, worker, e, out exception) == TaskException.ExceptionLevel.Critical) { return(TaskException.ExceptionLevel.Critical); } break; case Project.DirectoryScope.Selected: if (this.CopySelectedFiles(sourceDirectory, TargetDirectory, worker, e, out exception) == TaskException.ExceptionLevel.Critical) { return(TaskException.ExceptionLevel.Critical); } break; default: throw new ArgumentException("CopyItems->CopyRecursive->Invalid value", nameof(scope)); } //Copy attributes from source to target if (Properties.Settings.Default.Copy_DirectoryAttributes && !OLKI.Toolbox.DirectoryAndFile.Path.IsDrive(sourceDirectory) && !OLKI.Toolbox.DirectoryAndFile.Path.IsDrive(TargetDirectory)) { HandleAttributes.Direcotry.Set(TargetDirectory, sourceDirectory.Attributes); } // Report Progress this._progress.TotalDirectories.ActualValue++; worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress)); return(TaskException.ExceptionLevel.NoException); } catch (Exception ex) { exception = ex; this._progress.Exception = new TaskException { Description = Properties.Stringtable._0x000D, Exception = ex, Level = TaskException.ExceptionLevel.Critical, Source = sourceDirectory.FullName, Target = (TargetDirectory != null ? TargetDirectory.FullName : "") }; worker.ReportProgress((int)TaskControle.TaskStep.Exception, new ProgressState(this._progress, true)); return(TaskException.ExceptionLevel.Critical); } }
/// <summary> /// Copy recursive all elements in directory an subdirectory, sepending of the scope /// </summary> /// <param name="copyMode">The copy mode</param> /// <param name="sourceDirectory">Source directroy to copy</param> /// <param name="scope">Scope of the directory</param> /// <param name="worker">BackgroundWorker for copy</param> /// <param name="e">Provides data for the BackgroundWorker</param> /// <param name="exception">Exception of the process</param> /// <returns>Exception level of the copy process</returns> private TaskException.ExceptionLevel CopyRecursive(CopyItems.CopyMode copyMode, string sourceDirectory, Project.DirectoryScope scope, BackgroundWorker worker, DoWorkEventArgs e, out Exception exception) { return(this.CopyRecursive(copyMode, new DirectoryInfo(sourceDirectory), scope, worker, e, out exception)); }