コード例 #1
0
        static void ReportProgress(NgVodPosterProgress value)
        {
            if (value.StopProgress)
            {
                return;
            }

            //Total all processed images and calculate the percentage
            int     total    = value.Success + value.Failed + value.Skipped;
            decimal progPerc = (decimal)total / (decimal)value.Total;

            //if cancellation is requested, clear the console line and write that the task was canceled
            if (value.IsCanceled)
            {
                value.StopProgress = true;
                Console.Write("\n--------Task Canceled--------\n");
                Console.WriteLine("Please wait while the application closes all running processes.");
            }
            //If the progress is 100%, then the task is considered complete
            else if (total == value.Total)
            {
                ClearCurrentConsoleLine();
                Console.Write("-----Task Complete----");
                Console.WriteLine("\n OK: {0} | F:{1} | Sk: {2} | T: {3}", value.Success, value.Failed, value.Skipped, (int)value.Time.Elapsed.TotalMinutes + (value.Time.Elapsed.Seconds > 30 ? 1 : 0));
                Console.WriteLine(Environment.NewLine);
                value.StopProgress = true;
            }
            //If the progress is divisible by the provided value, then report progress
            else if (Math.Ceiling((progPerc * 100)) % 1 == 0)
            {
                double minRemaining = (value.Time.Elapsed.TotalMinutes / (total - value.Skipped)) * (value.Total - total);

                string rem = minRemaining > 60 ? minRemaining > 1440 ? (minRemaining / 60 / 24).ToString("N1") + " days" : (minRemaining / 60).ToString("N1") + " hrs" :
                             minRemaining < 1 ? (minRemaining * 60).ToString("N0") + "s" : minRemaining.ToString("N0") + " min";

#if DEBUG
                Trace.TraceInformation("MinRem: {0} | ElapsedMin: {1} | Total: {2} | Skipped: {3} | Val Total: {4}   ", rem, (int)value.Time.Elapsed.TotalMinutes, total, value.Skipped, value.Total);
#endif

                //Write progress to the same console line
                Console.Write(string.Format("\rP: {0:P1} | OK: {1} | F: {2} | Sk: {3} | T: {4} | R: {5} | {6}   ",
                                            progPerc, value.Success, value.Failed, value.Skipped, (int)value.Time.Elapsed.TotalMinutes + (value.Time.Elapsed.Seconds > 30 ? 1 : 0), value.Total - total, rem));

                //Report to trace every 5 minutes
                if ((int)value.Time.Elapsed.TotalMinutes % 5 == 0 && value.Time.Elapsed.Seconds <= 15)
                {
                    Trace.TraceInformation("P: {0:P1} | R: {1} | {2}", progPerc, value.Total - total, rem);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Timer handle to report progress
 /// </summary>
 /// <returns></returns>
 private Task HandleTimer(NgVodPosterProgress progress, IProgress <NgVodPosterProgress> iProgress)
 {
     iProgress.Report(progress);
     return(Task.FromResult(0));
 }