예제 #1
0
        public SarifResultTableEntry(SarifErrorListItem error)
        {
            this.Identity = error.GetHashCode();
            this.Error    = error;

            // Set the data that's fast to retrieve into the dictionary of values.
            this.columnKeyToContent[StandardTableKeyNames.DocumentName]  = this.Error.FileName;
            this.columnKeyToContent[StandardTableKeyNames.ErrorCategory] = this.Error.Category;

            // The error list assumes the line number provided will be zero based and adds one before displaying the value.
            // i.e. if we pass 5, the error list will display 6.
            // Subtract one from the line number so the error list displays the correct value.
            this.columnKeyToContent[StandardTableKeyNames.Line]   = this.Error.LineNumber - 1;
            this.columnKeyToContent[StandardTableKeyNames.Column] = this.Error.ColumnNumber - 1;

            this.columnKeyToContent[StandardTableKeyNames.ErrorSeverity] = GetSeverity(this.Error.Level);
            this.columnKeyToContent[StandardTableKeyNames.Priority]      = GetSeverity(this.Error.Level) == __VSERRORCATEGORY.EC_ERROR
                    ? vsTaskPriority.vsTaskPriorityHigh
                    : vsTaskPriority.vsTaskPriorityMedium;
            this.columnKeyToContent[StandardTableKeyNames.ErrorSource] = ErrorSource.Build;
            this.columnKeyToContent[StandardTableKeyNames.BuildTool]   = this.Error.Tool?.Name;

            if (this.Error.Rule != null)
            {
                this.columnKeyToContent[StandardTableKeyNames.ErrorCode]        = this.Error.Rule.Id;
                this.columnKeyToContent[StandardTableKeyNames.ErrorCodeToolTip] = string.IsNullOrEmpty(this.Error.Rule.Name)
                    ? this.Error.Rule.Id
                    : this.Error.Rule.Id + "." + this.Error.Rule.Name;
            }

            this.columnKeyToContent[StandardTableKeyNames.ProjectName] = this.Error.ProjectName;

            string supressionState = this.Error.VSSuppressionState.ToString();

            this.columnKeyToContent[SuppressionStateColumnName] = supressionState;

            // Anything that's a bit more complex, we will make a "lazy" value and evaluate
            // it when it's asked for.
            // In WPF all the content elements including Inlines can only have one parent element.
            // If the Inlines are binded to multiple elements, only 1 can show the Inlines.
            // Create duplicated message inline objects for ErrorList table entry since
            // Error.MessageInlines is already binded to an element in SARIF explorer.
            this.columnKeyToContent[StandardTableKeyNames2.TextInlines] = new Lazy <object>(() =>
                                                                                            this.Error.MessageInlines?.Any() == true
                ? SdkUIUtilities.GetMessageInlines(this.Error.ShortMessage, this.Error.MessageInlineLink_Click)
                : null);

            this.columnKeyToContent[FullTextInlinesColumnName] = new Lazy <object>(() =>
                                                                                   this.Error.MessageInlines?.Any() == true
                ? SdkUIUtilities.GetMessageInlines(this.Error.RawMessage, this.Error.MessageInlineLink_Click)
                : null);

            this.columnKeyToContent[StandardTableKeyNames.Text] = new Lazy <object>(() =>
                                                                                    SdkUIUtilities.UnescapeBrackets(this.Error.ShortMessage));

            this.columnKeyToContent[StandardTableKeyNames.FullText] = new Lazy <object>(() =>
                                                                                        this.Error.HasDetailsContent
                ? SdkUIUtilities.UnescapeBrackets(this.Error.Message)
                : null);

            this.columnKeyToContent[StandardTableKeyNames.HelpLink] = new Lazy <object>(() =>
                                                                                        !string.IsNullOrEmpty(this.Error.HelpLink)
                ? Uri.EscapeUriString(this.Error.HelpLink)
                : null);
        }
예제 #2
0
        public override bool TryGetValue(int index, string columnName, out object content)
        {
            content = null;

            if ((index >= 0) && (index < _errors.Count))
            {
                SarifErrorListItem error = _errors[index];

                if (columnName == StandardTableKeyNames2.TextInlines)
                {
                    string        message = error.Message;
                    List <Inline> inlines = SdkUIUtilities.GetMessageInlines(message, index, ErrorListInlineLink_Click);

                    if (inlines.Count > 0)
                    {
                        content = inlines;
                    }
                }
                else if (columnName == StandardTableKeyNames.DocumentName)
                {
                    content = FilePath;
                }
                else if (columnName == StandardTableKeyNames.ErrorCategory)
                {
                    content = error.Category;
                }
                else if (columnName == StandardTableKeyNames.Line)
                {
                    // The error list assumes the line number provided will be zero based and adds one before displaying the value.
                    // i.e. if we pass 5, the error list will display 6.
                    // Subtract one from the line number so the error list displays the correct value.
                    int lineNumber = error.LineNumber - 1;
                    content = lineNumber;
                }
                else if (columnName == StandardTableKeyNames.Column)
                {
                    content = error.ColumnNumber;
                }
                else if (columnName == StandardTableKeyNames.Text)
                {
                    content = SdkUIUtilities.UnescapeBrackets(error.ShortMessage);
                }
                else if (columnName == StandardTableKeyNames.FullText)
                {
                    if (error.HasDetailsContent)
                    {
                        content = SdkUIUtilities.UnescapeBrackets(error.Message);
                    }
                }
                else if (columnName == StandardTableKeyNames.ErrorSeverity)
                {
                    content = GetSeverity(error.Level);
                }
                else if (columnName == StandardTableKeyNames.Priority)
                {
                    content = GetSeverity(error.Level) == __VSERRORCATEGORY.EC_ERROR
                        ? vsTaskPriority.vsTaskPriorityHigh
                        : vsTaskPriority.vsTaskPriorityMedium;
                }
                else if (columnName == StandardTableKeyNames.ErrorSource)
                {
                    content = ErrorSource.Build;
                }
                else if (columnName == StandardTableKeyNames.BuildTool)
                {
                    content = error.Tool.Name;
                }
                else if (columnName == StandardTableKeyNames.ErrorCode)
                {
                    if (error.Rule != null)
                    {
                        content = error.Rule.Id;
                    }
                }
                else if (columnName == StandardTableKeyNames.ProjectName)
                {
                    content = error.ProjectName;
                }
                else if (columnName == StandardTableKeyNames.HelpLink)
                {
                    string url = null;
                    if (!string.IsNullOrEmpty(error.HelpLink))
                    {
                        url = error.HelpLink;
                    }

                    if (url != null)
                    {
                        content = Uri.EscapeUriString(url);
                    }
                }
                else if (columnName == StandardTableKeyNames.ErrorCodeToolTip)
                {
                    if (error.Rule != null)
                    {
                        content = error.Rule.Id + ":" + error.Rule.Name;
                    }
                }
                else if (columnName == "suppressionstatus" ||
                         columnName == "suppressionstate" ||
                         columnName == "suppression")
                {
                    content = error.VSSuppressionState.ToString();
                }
            }

            return(content != null);
        }
        public SarifResultTableEntry(SarifErrorListItem error)
        {
            this.Identity = error.GetHashCode();
            this.Error    = error;

            // Set the data that's fast to retrieve into the dictionary of values.
            this.columnKeyToContent[StandardTableKeyNames.DocumentName]  = this.Error.FileName;
            this.columnKeyToContent[StandardTableKeyNames.ErrorCategory] = this.Error.Category;

            // The error list assumes the line number provided will be zero based and adds one before displaying the value.
            // i.e. if we pass 5, the error list will display 6.
            // Subtract one from the line number so the error list displays the correct value.
            this.columnKeyToContent[StandardTableKeyNames.Line] = this.Error.LineNumber - 1;

            this.columnKeyToContent[StandardTableKeyNames.Column]        = this.Error.ColumnNumber;
            this.columnKeyToContent[StandardTableKeyNames.ErrorSeverity] = GetSeverity(this.Error.Level);
            this.columnKeyToContent[StandardTableKeyNames.Priority]      = GetSeverity(this.Error.Level) == __VSERRORCATEGORY.EC_ERROR
                    ? vsTaskPriority.vsTaskPriorityHigh
                    : vsTaskPriority.vsTaskPriorityMedium;
            this.columnKeyToContent[StandardTableKeyNames.ErrorSource] = ErrorSource.Build;
            this.columnKeyToContent[StandardTableKeyNames.BuildTool]   = this.Error.Tool?.Name;

            if (this.Error.Rule != null)
            {
                this.columnKeyToContent[StandardTableKeyNames.ErrorCode]        = this.Error.Rule.Id;
                this.columnKeyToContent[StandardTableKeyNames.ErrorCodeToolTip] = string.IsNullOrEmpty(this.Error.Rule.Name) ?
                                                                                  this.Error.Rule.Id : this.Error.Rule.Id + "." + this.Error.Rule.Name;
            }

            this.columnKeyToContent[StandardTableKeyNames.ProjectName] = this.Error.ProjectName;

            string supressionState = this.Error.VSSuppressionState.ToString();

            this.columnKeyToContent[SuppressionStateColumnName] = supressionState;

            // Anything that's a bit more complex, we will make a "lazy" value and evaluate
            // it when it's asked for.
            this.columnKeyToContent[StandardTableKeyNames2.TextInlines] = new Lazy <object>(() =>
            {
                string message        = this.Error.Message;
                List <Inline> inlines = SdkUIUtilities.GetMessageInlines(message, this.ErrorListInlineLink_Click);

                if (inlines.Count > 0)
                {
                    return(inlines);
                }

                return(null);
            });

            this.columnKeyToContent[StandardTableKeyNames.Text] = new Lazy <object>(() =>
            {
                return(SdkUIUtilities.UnescapeBrackets(this.Error.ShortMessage));
            });

            this.columnKeyToContent[StandardTableKeyNames.FullText] = new Lazy <object>(() =>
            {
                if (this.Error.HasDetailsContent)
                {
                    return(SdkUIUtilities.UnescapeBrackets(this.Error.Message));
                }

                return(null);
            });

            this.columnKeyToContent[StandardTableKeyNames.HelpLink] = new Lazy <object>(() =>
            {
                return(!string.IsNullOrEmpty(this.Error.HelpLink) ? Uri.EscapeUriString(this.Error.HelpLink) : null);
            });
        }