Esempio n. 1
0
 /// <summary>
 /// Reset the progress object if not null
 /// </summary>
 /// <param name="source"></param>
 public static void ResetProgress(this IProgressReportSource source)
 {
     if (ReferenceEquals(source.Progress, null) == false)
     {
         source.Progress.Reset();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Check if the progress object's status is RunningRequestStop and raise an exception to interrupt
        /// running process if so.
        /// </summary>
        /// <param name="source"></param>
        public static void CheckProgressRequestStop(this IProgressReportSource source)
        {
            if (ReferenceEquals(source.Progress, null))
            {
                return;
            }

            source.Progress.CheckRequestStop();
        }
Esempio n. 3
0
 internal ProgressEventArgs(int progressId, DateTime startTime, IProgressReportSource source, string title, string details, ProgressEventArgsKind kind, ProgressEventArgsResult result)
 {
     ProgressId = progressId;
     StartTime  = startTime;
     FinishTime = startTime;
     Source     = source;
     Title      = title;
     Details    = details;
     Kind       = kind;
     Result     = result;
 }
Esempio n. 4
0
        /// <summary>
        /// Set the progress object's status to NotRunning if possible and return true if successful.
        /// If the progress object is null or has status NotRunning this method returns false
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool SetProgressNotRunning(this IProgressReportSource source)
        {
            if (ReferenceEquals(source.Progress, null))
            {
                return(false);
            }

            source.Progress.Status = ProgressComposerStatus.NotRunning;

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Try change the status of the progress object into RunningRequestStop if possible and return true
        /// if successful
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool RequestProgressStop(this IProgressReportSource source)
        {
            if (ReferenceEquals(source.Progress, null))
            {
                return(false);
            }

            source.Progress.RequestStop();

            return(source.Progress.Status == ProgressComposerStatus.RunningRequestStop);
        }
Esempio n. 6
0
        /// <summary>
        /// Reports an error
        /// </summary>
        /// <param name="source"></param>
        /// <param name="error"></param>
        /// <returns>An ID of the progress event</returns>
        public static int ReportError(this IProgressReportSource source, Exception error)
        {
            if (ReferenceEquals(source.Progress, null) || source.Progress.Enabled == false)
            {
                return(-1);
            }

            var eventArgs =
                new ErrorEventArgs(
                    source.Progress.NextProgressId++,
                    DateTime.Now,
                    error,
                    source
                    );

            return(source.Progress.OnErrorEvent(eventArgs));
        }
Esempio n. 7
0
        /// <summary>
        /// Reports the end of a process
        /// </summary>
        /// <param name="progressStartId"></param>
        /// <param name="source"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static int ReportFinish(this IProgressReportSource source, int progressStartId, ProgressEventArgsResult result = ProgressEventArgsResult.Normal)
        {
            if (ReferenceEquals(source.Progress, null) || source.Progress.Enabled == false)
            {
                return(-1);
            }

            var eventArgs =
                new ProgressEventArgs(
                    source.Progress.NextProgressId++,
                    DateTime.Now,
                    source,
                    "",
                    "",
                    ProgressEventArgsKind.Finish, result
                    );

            return(source.Progress.OnProgressEvent(eventArgs, progressStartId));
        }
Esempio n. 8
0
        /// <summary>
        /// Reports a warning
        /// </summary>
        /// <param name="source"></param>
        /// <param name="title"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static int ReportWarning(this IProgressReportSource source, string title, ProgressEventArgsResult result = ProgressEventArgsResult.Normal)
        {
            if (ReferenceEquals(source.Progress, null) || source.Progress.Enabled == false)
            {
                return(-1);
            }

            var eventArgs =
                new ProgressEventArgs(
                    source.Progress.NextProgressId++,
                    DateTime.Now,
                    source,
                    title,
                    "",
                    ProgressEventArgsKind.Warning,
                    result
                    );

            return(source.Progress.OnProgressEvent(eventArgs));
        }
Esempio n. 9
0
        public static int ReportStart(this IProgressReportSource source, string title, Func <string> details)
        {
            if (ReferenceEquals(source.Progress, null) || source.Progress.Enabled == false)
            {
                return(-1);
            }

            var eventArgs =
                new ProgressEventArgs(
                    source.Progress.NextProgressId++,
                    DateTime.Now,
                    source,
                    title,
                    details(),
                    ProgressEventArgsKind.Start,
                    ProgressEventArgsResult.Normal
                    );

            return(source.Progress.OnProgressEvent(eventArgs));
        }
Esempio n. 10
0
 internal ErrorEventArgs(int progressId, DateTime startTime, Exception error, IProgressReportSource source, string title, string details)
     : base(progressId, startTime, source, title, details, ProgressEventArgsKind.Error, ProgressEventArgsResult.Normal)
 {
     Error = error;
 }
Esempio n. 11
0
 internal ErrorEventArgs(int progressId, DateTime startTime, Exception error, IProgressReportSource source)
     : base(progressId, startTime, source, "Error", error.ToString(), ProgressEventArgsKind.Error, ProgressEventArgsResult.Normal)
 {
     Error = error;
 }
Esempio n. 12
0
 /// <summary>
 /// True if the progress object is not null and has a status of RunningRequestStop
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static bool IsProgressStatusRunningRequestStop(this IProgressReportSource source)
 {
     return
         (ReferenceEquals(source.Progress, null) == false &&
          source.Progress.Status == ProgressComposerStatus.RunningRequestStop);
 }
Esempio n. 13
0
 public static int ReportNormal(this IProgressReportSource source, string title, Func <string> details, bool isSuccess)
 {
     return(ReportNormal(source, title, details, isSuccess ? ProgressEventArgsResult.Success : ProgressEventArgsResult.Failure));
 }