Example #1
0
 private void PART_ClearLog_Click(object sender, RoutedEventArgs e)
 {
     if (progressLog is StringBuilder)
     {
         PART_ProcessLog.Clear();
         progressLog.Clear();
     }
 }
Example #2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ParentWindow     = Window.GetWindow(this);
            BatchProcessTask = new BackgroundWorker()
            {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            BatchProcessTask.ProgressChanged    += BatchProcessTask_ProgressChanged;
            BatchProcessTask.RunWorkerCompleted += BatchProcessTask_RunWorkerCompleted;
            BatchProcessTask.DoWork             += BatchProcessTask_DoWork;
            progressLog.Clear();

            PART_TouchStart.IsEnabled  = false;
            PART_TouchCancel.IsEnabled = false;

            progress = new Progress <BatchProgressInfo>(info =>
            {
                try
                {
                    var index   = info.Current >= 0 ? info.Current : 0;
                    var total   = info.Total >= 0 ? info.Total : 0;
                    var total_s = total.ToString();
                    var index_s = index.ToString().PadLeft(total_s.Length, '0');

                    PART_FileName.Text = info.FileName;

                    #region Update ProgressBar & Progress Info Text
                    var percent               = total > 0 ? (double)index / total : 0;
                    var state                 = info.State == TaskStatus.Running && percent < 1 ? "Processed" : info.State == TaskStatus.RanToCompletion || percent == 1 ? "Finished" : "Idle";
                    PART_Progress.Value       = percent >= 1 ? 100 : percent * 100;
                    PART_ProgressPercent.Text = $"{state} [ {index} / {total} ]: {PART_Progress.Value:0.0}%";
                    #endregion

                    #region Update Progress Info Text Color Gradient
                    var factor = PART_Progress.ActualWidth / PART_ProgressPercent.ActualWidth;
                    var offset = Math.Abs((factor - 1) / 2);
                    PART_ProgressLinear.StartPoint  = new Point(0 - offset, 0);
                    PART_ProgressLinear.EndPoint    = new Point(1 + offset, 0);
                    PART_ProgressLinearLeft.Offset  = percent;
                    PART_ProgressLinearRight.Offset = percent;
                    #endregion

                    #region Update Logger
                    progressLog.AppendLine($"[{index_s} / {total_s}] {info.Result}");
                    PART_ProcessLog.Text = ProgressLog;
                    PART_ProcessLog.ScrollToEnd();
                    #endregion

                    if (info.State == TaskStatus.RanToCompletion || percent == 1)
                    {
                        PART_TouchStart.IsEnabled  = true;
                        PART_TouchCancel.IsEnabled = false;
                    }
                }
                catch (Exception ex) { ex.ERROR($"{this.Name ?? GetType().Name}_ReportProgress"); }
            });

            reportAction = (info) =>
            {
                if (progress is IProgress <BatchProgressInfo> )
                {
                    progress.Report(info);
                }
            };
        }