Esempio n. 1
0
        /// <inheritdoc cref="IConsoleLogger.ReportProgress"/>
        public virtual void ReportProgress(int max, int current, string message)
        {
            if (ProgressBarDisplayMode == ConsoleProgressBarDisplayMode.Off)
            {
                return;
            }

            if (_console.IsOutputRedirected)
            {
                // cannot use the progress bar
                Debug(FormatLogMessageProgressAsText(max, current, message));
                return;
            }

            try {
                if (_progressBar == null)
                {
                    _progressBar = new ConsoleProgressBar(_console, max, message)
                    {
                        ClearProgressBarOnStop = ProgressBarDisplayMode == ConsoleProgressBarDisplayMode.On,
                        TextColor                        = ProgressTextColor,
                        BackgroundCharacter              = ProgressBackgroundCharacter,
                        ForegroundCharacter              = ProgressForegroundCharacter,
                        BackgroundColor                  = ProgressBackgroundColor,
                        ForegroundColor                  = ProgressForegroundColor,
                        ForegroundColorDone              = ProgressForegroundColorDone,
                        ForegroundColorUncomplete        = ProgressForegroundColorUncomplete,
                        MaximumRefreshRateInMilliseconds = ProgressMaximumRefreshRateInMilliseconds,
                        MinimumRefreshRateInMilliseconds = ProgressMinimumRefreshRateInMilliseconds,
                    };
                }
                if (!_progressBar.IsRunning)
                {
                    base.WriteResultOnNewLine(null);
                }
                if (max > 0 && max != _progressBar.MaxTicks)
                {
                    _progressBar.MaxTicks = max;
                }
                _progressBar.Tick(current, message);
                if (max == current)
                {
                    StopProgressBar();
                }
            } catch (Exception) {
                // ignored
            }
        }