ControlData IViewControlHandler.GetCurrentData()
        {
            var outputs = postprocessorsManager.GetPostprocessorOutputsByPostprocessorId(postprocessorKind);

            if (outputs.Length == 0)
            {
                return(new ControlData()
                {
                    Disabled = true,
                    Content = postprocessorKind.ToDisplayString() + ": N/A"
                });
            }

            int    nrOfRunning               = 0;
            int    nrOfLoading               = 0;
            int    nrOfProcessed             = 0;
            int    nrOfUnprocessed           = 0;
            int    nrOfOutdated              = 0;
            int    nrOfProcessedWithWarnings = 0;
            int    nrOfProcessedWithErrors   = 0;
            double?progress = null;

            foreach (var output in outputs)
            {
                switch (output.OutputStatus)
                {
                case LogSourcePostprocessorOutput.Status.Finished:
                case LogSourcePostprocessorOutput.Status.Failed:
                    if (output.LastRunSummary != null)
                    {
                        if (output.LastRunSummary.HasWarnings)
                        {
                            ++nrOfProcessedWithWarnings;
                        }
                        if (output.LastRunSummary.HasErrors)
                        {
                            ++nrOfProcessedWithErrors;
                        }
                    }
                    ++nrOfProcessed;
                    break;

                case LogSourcePostprocessorOutput.Status.Outdated:
                    ++nrOfOutdated;
                    ++nrOfProcessed;
                    break;

                case LogSourcePostprocessorOutput.Status.InProgress:
                    ++nrOfRunning;
                    progress = output.Progress;
                    break;

                case LogSourcePostprocessorOutput.Status.Loading:
                    ++nrOfLoading;
                    progress = output.Progress;
                    break;

                case LogSourcePostprocessorOutput.Status.NeverRun:
                    ++nrOfUnprocessed;
                    break;
                }
            }

            var    ret = new ControlData();
            var    isClickableCaption = false;
            string action             = null;
            string statusText         = null;

            ret.Disabled = false;

            Action appendReportLinkIfRequired = () =>
            {
                if (nrOfProcessedWithErrors > 0)
                {
                    statusText += " *report with errors*";
                }
                else if (nrOfProcessedWithWarnings > 0)
                {
                    statusText += " *report with warnings*";
                }
            };

            if (nrOfLoading > 0 && nrOfRunning == 0)
            {
                statusText   = string.Format("loading... ({0} of {1} logs completed)", nrOfLoading, nrOfLoading + nrOfProcessed);
                ret.Progress = progress;
            }
            else if (nrOfRunning > 0)
            {
                statusText   = string.Format("running... ({0} of {1} logs completed)", nrOfProcessed, nrOfRunning + nrOfProcessed + nrOfLoading);
                ret.Progress = progress;
            }
            else if (nrOfUnprocessed > 0 || nrOfOutdated > 0)
            {
                statusText = string.Format("{0} of {1} logs processed", nrOfProcessed, nrOfProcessed + nrOfUnprocessed);
                appendReportLinkIfRequired();
                if (nrOfOutdated > 0)
                {
                    statusText += string.Format(", {0} outdated", nrOfOutdated);
                }
                if (lazyOutputForm != null && nrOfProcessed > 0)
                {
                    isClickableCaption = true;
                }
                action    = "run postprocessor";
                ret.Color = ControlData.StatusColor.Warning;
            }
            else
            {
                statusText = string.Format("all logs processed");
                if (lazyOutputForm != null && nrOfProcessed > 0)
                {
                    isClickableCaption = true;
                }
                appendReportLinkIfRequired();
                action = "re-process";
                if (nrOfProcessedWithErrors > 0)
                {
                    ret.Color = ControlData.StatusColor.Error;
                }
                else
                {
                    ret.Color = ControlData.StatusColor.Success;
                }
            }

            var contentBuilder = new StringBuilder();

            if (isClickableCaption)
            {
                contentBuilder.AppendFormat("*show {0}:*", outputs[0].PostprocessorMetadata.Kind.ToDisplayString());
            }
            else
            {
                contentBuilder.AppendFormat("{0}:", outputs[0].PostprocessorMetadata.Kind.ToDisplayString());
            }
            if (statusText != null)
            {
                contentBuilder.AppendFormat("  {0}", statusText);
            }
            if (action != null)
            {
                contentBuilder.AppendFormat("  *action {0}*", action);
            }
            ret.Content += contentBuilder.ToString();

            return(ret);
        }
Exemple #2
0
        static ControlData GetCurrentData(ImmutableList <LogSourcePostprocessorState> outputs, PostprocessorKind postprocessorKind)
        {
            if (outputs.Count == 0)
            {
                return(new ControlData(true, postprocessorKind.ToDisplayString() + ": N/A"));
            }

            int    nrOfRunning               = 0;
            int    nrOfLoading               = 0;
            int    nrOfProcessed             = 0;
            int    nrOfUnprocessed           = 0;
            int    nrOfOutdated              = 0;
            int    nrOfProcessedWithWarnings = 0;
            int    nrOfProcessedWithErrors   = 0;
            double?progress = null;

            foreach (var output in outputs)
            {
                switch (output.OutputStatus)
                {
                case LogSourcePostprocessorState.Status.Finished:
                case LogSourcePostprocessorState.Status.Failed:
                    if (output.LastRunSummary != null)
                    {
                        if (output.LastRunSummary.HasWarnings)
                        {
                            ++nrOfProcessedWithWarnings;
                        }
                        if (output.LastRunSummary.HasErrors)
                        {
                            ++nrOfProcessedWithErrors;
                        }
                    }
                    ++nrOfProcessed;
                    break;

                case LogSourcePostprocessorState.Status.Outdated:
                    ++nrOfOutdated;
                    ++nrOfProcessed;
                    break;

                case LogSourcePostprocessorState.Status.InProgress:
                    ++nrOfRunning;
                    progress = output.Progress;
                    break;

                case LogSourcePostprocessorState.Status.Loading:
                    ++nrOfLoading;
                    progress = output.Progress;
                    break;

                case LogSourcePostprocessorState.Status.NeverRun:
                    ++nrOfUnprocessed;
                    break;
                }
            }

            var    isClickableCaption = false;
            string action             = null;
            string statusText         = null;

            string controlContent = "";

            ControlData.StatusColor controlColor = ControlData.StatusColor.Neutral;
            double?controlProgress = null;

            Action appendReportLinkIfRequired = () =>
            {
                if (nrOfProcessedWithErrors > 0)
                {
                    statusText += " *report with errors*";
                }
                else if (nrOfProcessedWithWarnings > 0)
                {
                    statusText += " *report with warnings*";
                }
            };

            if (nrOfLoading > 0 && nrOfRunning == 0)
            {
                statusText      = string.Format("loading... ({0} of {1} logs completed)", nrOfLoading, nrOfLoading + nrOfProcessed);
                controlProgress = progress;
            }
            else if (nrOfRunning > 0)
            {
                statusText      = string.Format("running... ({0} of {1} logs completed)", nrOfProcessed, nrOfRunning + nrOfProcessed + nrOfLoading);
                controlProgress = progress;
            }
            else if (nrOfUnprocessed > 0 || nrOfOutdated > 0)
            {
                statusText = string.Format("{0} of {1} logs processed", nrOfProcessed, nrOfProcessed + nrOfUnprocessed);
                appendReportLinkIfRequired();
                if (nrOfOutdated > 0)
                {
                    statusText += string.Format(", {0} outdated", nrOfOutdated);
                }
                if (nrOfProcessed > 0)
                {
                    isClickableCaption = true;
                }
                action       = "run postprocessor";
                controlColor = ControlData.StatusColor.Warning;
            }
            else
            {
                statusText = string.Format("all logs processed");
                if (nrOfProcessed > 0)
                {
                    isClickableCaption = true;
                }
                appendReportLinkIfRequired();
                action = "re-process";
                if (nrOfProcessedWithErrors > 0)
                {
                    controlColor = ControlData.StatusColor.Error;
                }
                else
                {
                    controlColor = ControlData.StatusColor.Success;
                }
            }

            var contentBuilder = new StringBuilder();

            if (isClickableCaption)
            {
                contentBuilder.AppendFormat("*{1} {0}:*", outputs[0].Postprocessor.Kind.ToDisplayString(), Constants.ShowVisualizerActionId);
            }
            else
            {
                contentBuilder.AppendFormat("{0}:", outputs[0].Postprocessor.Kind.ToDisplayString());
            }
            if (statusText != null)
            {
                contentBuilder.AppendFormat("  {0}", statusText);
            }
            if (action != null)
            {
                contentBuilder.AppendFormat("  *{1} {0}*", action, Constants.RunActionId);
            }
            controlContent += contentBuilder.ToString();

            return(new ControlData(false, controlContent, controlColor, controlProgress));
        }