示例#1
0
        /// <summary>
        /// Get the corresponding target path for target directroy, depending of the given source directroy and mode
        /// </summary>
        /// <param name="copyMode">Mode to get the target path</param>
        /// <param name="sourceDirectory">Source directroy to get the target forc</param>
        /// <param name="projectSettings">Settings of the project</param>
        /// <returns>Full target name for the directroy to create</returns>
        public string GetTargetFullName(CopyItems.CopyMode copyMode, DirectoryInfo sourceDirectory, Settings.Settings projectSettings)
        {
            string RootSegment;
            string DriveNameSegment;
            string SourceSegment;

            switch (copyMode)
            {
            case CopyItems.CopyMode.Backup:
                RootSegment      = projectSettings.ControleBackup.Directory.Path;
                DriveNameSegment = projectSettings.ControleBackup.Directory.CreateDriveDirectroy ? sourceDirectory.Root.FullName.Remove(1, 2) : "";
                SourceSegment    = sourceDirectory.FullName.Remove(0, sourceDirectory.Root.FullName.Length);
                return(this.BuildTargetFullName(RootSegment, DriveNameSegment, SourceSegment));

            case CopyItems.CopyMode.Restore:
                DirectoryInfo Source = new DirectoryInfo(projectSettings.ControleRestore.Directory.Path);
                if (projectSettings.ControleRestore.Directory.CreateDriveDirectroy)
                {
                    RootSegment = sourceDirectory.FullName.Substring(Source.FullName.Length + 1);
                    return(OLKI.Toolbox.DirectoryAndFile.Path.Repair(RootSegment.Insert(1, @":\")));
                }
                else
                {
                    SourceSegment = "";
                    if (sourceDirectory.FullName.Length > Source.FullName.Length + 1)
                    {
                        SourceSegment = sourceDirectory.FullName.Substring(Source.FullName.Length + 1);
                    }
                    RootSegment  = projectSettings.ControleRestore.Directory.RestoreTargetPath;
                    RootSegment += @"\" + SourceSegment;
                    return(OLKI.Toolbox.DirectoryAndFile.Path.Repair(RootSegment));
                }

            default:
                break;
            }
            return(string.Empty);
        }
示例#2
0
        /// <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);
            }
        }
示例#3
0
 /// <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));
 }