Esempio n. 1
0
 /// <summary>
 /// Check if the exception is a full disc exception an return a critical exception level, otherwise return the alternative exception level
 /// </summary>
 /// <param name="exception">Exception to check the exception code for full disc exception</param>
 /// <param name="alternativeLevel">Exceptionlevel to return if it is not an full disc exception</param>
 /// <returns>Critical exception level if exception is an full disc exception, otherweise return the alternative definded exception level</returns>
 public TaskException.ExceptionLevel GetFullDiscExceptionReturnCode(Exception exception, TaskException.ExceptionLevel alternativeLevel)
 {
     if (exception != null && System.Runtime.InteropServices.Marshal.GetHRForException(exception) == EXCEPTION_FULL_DISC)
     {
         return(TaskException.ExceptionLevel.Critical);
     }
     return(alternativeLevel);
 }
Esempio n. 2
0
        /// <summary>
        /// Copya file from target to source
        /// </summary>
        /// <param name="sourceFile">Source file to copy</param>
        /// <param name="targetDirectory">Target directroy for copy the files to</param>
        /// <param name="worker">BackgroundWorker for count</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 CopyFile(FileInfo sourceFile, DirectoryInfo targetDirectory, BackgroundWorker worker, DoWorkEventArgs e, out Exception exception)
        {
            this._progress.FileBytes.ActualValue = 0;
            this._progress.FileBytes.ElemenName  = sourceFile.FullName;
            this._progress.FileBytes.MaxValue    = sourceFile.Length;

            worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress));

            FileInfo TargetFile = new FileInfo(targetDirectory.FullName + @"\" + sourceFile.Name);

            try
            {
                if (TargetFile.Exists)
                {
                    HandleExistingFiles.CheckResult HandleFile = HandleExistingFiles.GetOverwriteByAction(sourceFile, TargetFile, Properties.Settings.Default.Copy_FileExisitngAddTextDateFormat, this._project.Settings.Common.ExisitingFiles.HandleExistingItem, this._project.Settings.Common.ExisitingFiles.AddTextToExistingFile, false, out exception, this._mainForm);
                    if (HandleFile.FormResult == DialogResult.Cancel)
                    {
                        worker.ReportProgress((int)TaskControle.TaskStep.Cancel, new ProgressState(true));
                        e.Cancel = true;
                        worker.CancelAsync();
                        return(TaskException.ExceptionLevel.NoException);
                    }
                    else if (HandleFile.RememberAction)
                    {
                        this._project.Settings.Common.ExisitingFiles.HandleExistingItem    = HandleFile.SelectedAction;
                        this._project.Settings.Common.ExisitingFiles.AddTextToExistingFile = HandleFile.AddText;
                    }

                    //Handle overwrite state
                    switch (HandleFile.OverwriteFile)
                    {
                    case HandleExistingFiles.ExistingFile.Exception:
                        worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress));
                        return(TaskException.ExceptionLevel.Medium);

                    case HandleExistingFiles.ExistingFile.Overwrite:
                    case HandleExistingFiles.ExistingFile.Rename:
                        //Nothing speceial to do
                        break;

                    case HandleExistingFiles.ExistingFile.Skip:
                        this._progress.TotalBytes.ActualValue += sourceFile.Length;
                        this._progress.TotalFiles.ActualValue++;
                        worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress));
                        return(TaskException.ExceptionLevel.NoException);
                    }
                }

                if (!this.CopyFileBufferd(sourceFile, TargetFile, worker, e, out exception))
                {
                    return(this.GetFullDiscExceptionReturnCode(exception, TaskException.ExceptionLevel.Medium));
                }
                else
                {
                    this._progress.TotalFiles.ActualValue++;
                }

                //Report Progress
                worker.ReportProgress((int)TaskControle.TaskStep.Copy_Busy, new ProgressState(this._progress));
                return(TaskException.ExceptionLevel.NoException);
            }
            catch (Exception ex)
            {
                exception = ex;
                TaskException.ExceptionLevel ReturnLevel = this.GetFullDiscExceptionReturnCode(exception, TaskException.ExceptionLevel.Medium);
                TaskException Exception = new TaskException
                {
                    Description = Properties.Stringtable._0x000E,
                    Exception   = ex,
                    Level       = ReturnLevel,
                    Source      = sourceFile.FullName,
                    Target      = TargetFile.FullName
                };
                this._progress.Exception = Exception;
                worker.ReportProgress((int)TaskControle.TaskStep.Exception, new ProgressState(this._progress, true));
                return(ReturnLevel);
            }
        }