/// <summary> /// Copy items in backup mode /// </summary> /// <param name="worker">BackgroundWorker for copy</param> /// <param name="e">Provides data for the BackgroundWorker</param> internal void Backup(BackgroundWorker worker, DoWorkEventArgs e, ProgressStore progressStore) { //Initial progress this._progress = progressStore; DirectoryInfo Target = new DirectoryInfo(this._project.Settings.ControleBackup.Directory.Path); int PathStartIndex = OLKI.Toolbox.DirectoryAndFile.Path.Repair(Target.FullName + DUMMY_DRIVE_PATH).Length; foreach (DirectoryInfo DriveDirectory in Target.GetDirectories().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } this._progress.DirectroyFiles.ElemenName = DriveDirectory.FullName; worker.ReportProgress((int)TaskControle.TaskStep.DeleteOldItems_Busy, new ProgressState(this._progress, true)); if (this.DeleteRecursive(DriveDirectory.Name, DriveDirectory, PathStartIndex, worker, e, out Exception ex) == TaskException.ExceptionLevel.Critical) { e.Cancel = true; worker.CancelAsync(); return; } } worker.ReportProgress((int)TaskControle.TaskStep.DeleteOldItems_Busy, new ProgressState(this._progress, true)); }
/// <summary> /// Copy items in backup mode /// </summary> /// <param name="worker">BackgroundWorker for copy</param> /// <param name="e">Provides data for the BackgroundWorker</param> /// <param name="progressStore">Progress data storage</param> internal void Backup(BackgroundWorker worker, DoWorkEventArgs e, ProgressStore progressStore) { //Initial progress this._progress = progressStore; this._progress.TotalBytes.ActualValue = 0; this._progress.TotalDirectories.ActualValue = 0; this._progress.TotalFiles.ActualValue = 0; // Create main target directory if (!this.CreateRootDirectory(this._project.Settings.ControleBackup.Directory.Path, worker, e)) { return; } // Copy content of selected directories foreach (KeyValuePair <string, Project.DirectoryScope> item in this._project.ToBackupDirectorys.OrderBy(o => o.Key)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } // Copy Recursive item.Key => sourceDirectory item.Value = scope if (this.CopyRecursive(CopyMode.Backup, item.Key, item.Value, worker, e, out Exception ex) == TaskException.ExceptionLevel.Critical) { e.Cancel = true; worker.CancelAsync(); return; } worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress, true)); } worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress, true)); }
/// <summary> /// Copy items in restore mode /// </summary> /// <param name="worker">BackgroundWorker for copy</param> /// <param name="e">Provides data for the BackgroundWorker</param> /// <param name="progressStore">Progress data storage</param> internal void Restore(BackgroundWorker worker, DoWorkEventArgs e, ProgressStore progressStore) { //Initial progress this._progress = progressStore; this._progress.TotalBytes.ActualValue = 0; this._progress.TotalDirectories.ActualValue = 0; this._progress.TotalFiles.ActualValue = 0; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); if (this._project.Settings.ControleRestore.Directory.CreateDriveDirectroy) { DirectoryInfo Source = new DirectoryInfo(this._project.Settings.ControleRestore.Directory.Path); DirectoryInfo Target = new DirectoryInfo(this._project.Settings.ControleBackup.Directory.Path); int PathStartIndex = OLKI.Toolbox.DirectoryAndFile.Path.Repair(Target.FullName + DUMMY_DRIVE_PATH).Length; foreach (DirectoryInfo DriveDirectory in Source.GetDirectories().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } if (this.CopyRecursive(CopyMode.Restore, DriveDirectory, Project.DirectoryScope.All, worker, e, out Exception ex) == TaskException.ExceptionLevel.Critical) { e.Cancel = true; worker.CancelAsync(); return; } worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress, true)); } } else { if (this.CopyRecursive(CopyMode.Restore, this._project.Settings.ControleRestore.Directory.Path, Project.DirectoryScope.All, worker, e, out Exception ex) == TaskException.ExceptionLevel.Critical) { e.Cancel = true; worker.CancelAsync(); return; } worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress, true)); } worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress, true)); }
/// <summary> /// Count items in restore mode /// </summary> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> internal void Restore(BackgroundWorker worker, DoWorkEventArgs e, ProgressStore progressStore) { // Initial Progress Store this._progress = progressStore; this._progress.TotalDirectories.MaxValue = 0; this._progress.TotalFiles.MaxValue = 0; this._progress.TotalBytes.MaxValue = 0; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); if (this._project.Settings.ControleRestore.Directory.CreateDriveDirectroy) { DirectoryInfo Source = new DirectoryInfo(this._project.Settings.ControleRestore.Directory.Path); foreach (DirectoryInfo DriveDirectory in Source.GetDirectories().OrderBy(o => o.Name)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; return; } //Report Directory this._progress.DirectroyFiles.ElemenName = DriveDirectory.FullName; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); // Search Recursive this.CountRecursive(DriveDirectory.FullName, Project.DirectoryScope.All, worker, e); //Report Progress if (worker.CancellationPending) { e.Cancel = true; break; } this._progress.DirectroyFiles.ActualValue++; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); } } else { this.CountRecursive(this._project.Settings.ControleRestore.Directory.Path, Project.DirectoryScope.All, worker, e); } worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); }
/// <summary> /// Count items in backup mode /// </summary> /// <param name="worker">BackgroundWorker for count</param> /// <param name="e">Provides data for the BackgroundWorker</param> internal void Backup(BackgroundWorker worker, DoWorkEventArgs e, ProgressStore progressStore) { // Initial Progress Store this._progress = progressStore; this._progress.DirectroyFiles.ActualValue = 0; this._progress.DirectroyFiles.MaxValue = this._project.ToBackupDirectorys.Count; this._progress.TotalDirectories.MaxValue = 0; this._progress.TotalFiles.MaxValue = 0; this._progress.TotalBytes.MaxValue = 0; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); // Count content of selected directories foreach (KeyValuePair <string, Project.DirectoryScope> item in this._project.ToBackupDirectorys.OrderBy(o => o.Key)) { // Check for abbort if (worker.CancellationPending) { e.Cancel = true; break; } //Report Directory this._progress.DirectroyFiles.ElemenName = item.Key; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); // Search Recursive this.CountRecursive(item.Key, item.Value, worker, e); //Report Progress if (worker.CancellationPending) { e.Cancel = true; break; } this._progress.DirectroyFiles.ActualValue++; worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); } worker.ReportProgress((int)TaskControle.TaskStep.Count_Busy, new ProgressState(this._progress, true)); }
/// <summary> /// Create the target dirextroy for an backup or to restpore /// </summary> /// <param name="sourceDirectory">Source directroy to copy</param> /// <param name="targetDirectory">Target directroy to create</param> /// <param name="worker">BackgroundWorker for count</param> /// <param name="progress">Progress element for the process</param> /// <param name="exception">Exception of the process</param> /// <param name="copyItemClass">CcopyItem to use the GetFullDiscExceptionReturnCode function</param> /// <returns>Exception level of the copy process</returns> public TaskException.ExceptionLevel TargetDirectory(DirectoryInfo sourceDirectory, DirectoryInfo targetDirectory, BackgroundWorker worker, ProgressStore progress, out Exception exception, CopyItems copyItemClass) { exception = null; try { if (!targetDirectory.Exists && !OLKI.Toolbox.DirectoryAndFile.Path.IsDrive(targetDirectory)) { targetDirectory.Create(); HandleAttributes.Direcotry.Remove(targetDirectory); } return(TaskException.ExceptionLevel.NoException); } catch (Exception ex) { exception = ex; TaskException Exception = new TaskException { Description = Properties.Stringtable._0x001D, Exception = ex, Level = copyItemClass.GetFullDiscExceptionReturnCode(exception, TaskException.ExceptionLevel.Medium), Source = sourceDirectory.FullName, Target = targetDirectory.FullName }; progress.Exception = Exception; worker.ReportProgress((int)TaskControle.TaskStep.Exception, new ProgressState(progress, true)); return(Exception.Level); } }