Esempio n. 1
0
        public async Task <SerializableConflictResolution> DehydrateAsync(CancellationToken cancellationToken)
        {
            if (ErrorMessage != null)
            {
                return new SerializableConflictResolution {
                           ErrorMessage = ErrorMessage
                }
            }
            ;

            var documentTextChanges = await RemoteUtilities.GetDocumentTextChangesAsync(OldSolution, _newSolutionWithoutRenamedDocument, cancellationToken).ConfigureAwait(false);

            return(new SerializableConflictResolution
            {
                ReplacementTextValid = ReplacementTextValid,
                RenamedDocument = _renamedDocument,
                DocumentIds = DocumentIds.ToArray(),
                RelatedLocations = RelatedLocations.Select(loc => SerializableRelatedLocation.Dehydrate(loc)).ToArray(),
                DocumentTextChanges = documentTextChanges,
                DocumentToModifiedSpansMap = _documentToModifiedSpansMap.Select(kvp => (kvp.Key, kvp.Value)).ToArray(),
                DocumentToComplexifiedSpansMap = _documentToComplexifiedSpansMap.Select(kvp => (kvp.Key, kvp.Value.SelectAsArray(s => SerializableComplexifiedSpan.Dehydrate(s)))).ToArray(),
                DocumentToRelatedLocationsMap = _documentToRelatedLocationsMap.Select(kvp => (kvp.Key, kvp.Value.SelectAsArray(s => SerializableRelatedLocation.Dehydrate(s)))).ToArray(),
            });
Esempio n. 2
0
        public SarifErrorListItem(Run run, Result result, string logFilePath, ProjectNameCache projectNameCache) : this()
        {
            if (!SarifViewerPackage.IsUnitTesting)
            {
#pragma warning disable VSTHRD108 // Assert thread affinity unconditionally
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD108 // Assert thread affinity unconditionally
            }
            _runId = CodeAnalysisResultManager.Instance.CurrentRunId;
            ReportingDescriptor rule = result.GetRule(run);
            Tool         = run.Tool.ToToolModel();
            Rule         = rule.ToRuleModel(result.RuleId);
            Invocation   = run.Invocations?[0]?.ToInvocationModel();
            Message      = result.GetMessageText(rule, concise: false).Trim();
            ShortMessage = result.GetMessageText(rule, concise: true).Trim();
            if (!Message.EndsWith("."))
            {
                ShortMessage = ShortMessage.TrimEnd('.');
            }
            FileName    = result.GetPrimaryTargetFile(run);
            ProjectName = projectNameCache.GetName(FileName);
            Category    = result.GetCategory();
            Region      = result.GetPrimaryTargetRegion();
            Level       = result.Level != FailureLevel.Warning ? result.Level : Rule.FailureLevel;

            if (result.Suppressions?.Count > 0)
            {
                VSSuppressionState = VSSuppressionState.Suppressed;
            }

            LogFilePath = logFilePath;

            if (Region != null)
            {
                LineNumber   = Region.StartLine;
                ColumnNumber = Region.StartColumn;
            }

            Tool             = run.Tool.ToToolModel();
            Rule             = rule.ToRuleModel(result.RuleId);
            Invocation       = run.Invocations?[0]?.ToInvocationModel();
            WorkingDirectory = Path.Combine(Path.GetTempPath(), _runId.ToString());

            if (result.Locations?.Any() == true)
            {
                // Adding in reverse order will make them display in the correct order in the UI.
                for (int i = result.Locations.Count - 1; i >= 0; --i)
                {
                    Locations.Add(result.Locations[i].ToLocationModel(run));
                }
            }

            if (result.RelatedLocations?.Any() == true)
            {
                for (int i = result.RelatedLocations.Count - 1; i >= 0; --i)
                {
                    RelatedLocations.Add(result.RelatedLocations[i].ToLocationModel(run));
                }
            }

            if (result.CodeFlows != null)
            {
                foreach (CodeFlow codeFlow in result.CodeFlows)
                {
                    CallTree callTree = codeFlow.ToCallTree(run);
                    if (callTree != null)
                    {
                        CallTrees.Add(callTree);
                    }
                }

                CallTrees.Verbosity = 100;
                CallTrees.IntelligentExpand();
            }

            if (result.Stacks != null)
            {
                foreach (Stack stack in result.Stacks)
                {
                    Stacks.Add(stack.ToStackCollection());
                }
            }

            if (result.Fixes != null)
            {
                foreach (Fix fix in result.Fixes)
                {
                    Fixes.Add(fix.ToFixModel());
                }
            }
        }
Esempio n. 3
0
        public SarifErrorListItem(Run run, Result result, string logFilePath, ProjectNameCache projectNameCache) : this()
        {
            IRule rule;

            run.TryGetRule(result.RuleId, result.RuleKey, out rule);
            Message           = result.GetMessageText(rule, concise: false);
            ShortMessage      = result.GetMessageText(rule, concise: true);
            FileName          = result.GetPrimaryTargetFile();
            ProjectName       = projectNameCache.GetName(FileName);
            Category          = result.GetCategory();
            Region            = result.GetPrimaryTargetRegion();
            Level             = result.Level;
            SuppressionStates = result.SuppressionStates;
            LogFilePath       = logFilePath;

            if (Region != null)
            {
                LineNumber   = Region.StartLine;
                ColumnNumber = Region.StartColumn;
            }

            Tool       = run.Tool.ToToolModel();
            Rule       = rule.ToRuleModel(result.RuleId);
            Invocation = run.Invocation.ToInvocationModel();

            if (string.IsNullOrWhiteSpace(run.Id))
            {
                WorkingDirectory = Path.Combine(Path.GetTempPath(), run.GetHashCode().ToString());
            }
            else
            {
                WorkingDirectory = Path.Combine(Path.GetTempPath(), run.Id);
            }

            if (result.Locations != null)
            {
                foreach (Location location in result.Locations)
                {
                    Locations.Add(location.ToAnnotatedCodeLocationModel());
                }
            }

            if (result.RelatedLocations != null)
            {
                foreach (AnnotatedCodeLocation annotatedCodeLocation in result.RelatedLocations)
                {
                    RelatedLocations.Add(annotatedCodeLocation.ToAnnotatedCodeLocationModel());
                }
            }

            if (result.CodeFlows != null)
            {
                foreach (CodeFlow codeFlow in result.CodeFlows)
                {
                    CallTrees.Add(codeFlow.ToCallTree());
                }

                CallTrees.Verbosity = 100;
                CallTrees.IntelligentExpand();
            }

            if (result.Stacks != null)
            {
                foreach (Stack stack in result.Stacks)
                {
                    Stacks.Add(stack.ToStackCollection());
                }
            }

            if (result.Fixes != null)
            {
                foreach (Fix fix in result.Fixes)
                {
                    Fixes.Add(fix.ToFixModel());
                }
            }
        }
Esempio n. 4
0
        public bool Equals(Result other)
        {
            if (other == null)
            {
                return(false);
            }

            if (RuleId != other.RuleId)
            {
                return(false);
            }

            if (Kind != other.Kind)
            {
                return(false);
            }

            if (Message != other.Message)
            {
                return(false);
            }

            if (!Object.Equals(FormattedRuleMessage, other.FormattedRuleMessage))
            {
                return(false);
            }

            if (!Object.ReferenceEquals(Locations, other.Locations))
            {
                if (Locations == null || other.Locations == null)
                {
                    return(false);
                }

                if (!Locations.SetEquals(other.Locations))
                {
                    return(false);
                }
            }

            if (CodeSnippet != other.CodeSnippet)
            {
                return(false);
            }

            if (ToolFingerprint != other.ToolFingerprint)
            {
                return(false);
            }

            if (!Object.ReferenceEquals(Stacks, other.Stacks))
            {
                if (Stacks == null || other.Stacks == null)
                {
                    return(false);
                }

                if (!Stacks.SetEquals(other.Stacks))
                {
                    return(false);
                }
            }

            if (!Object.ReferenceEquals(CodeFlows, other.CodeFlows))
            {
                if (CodeFlows == null || other.CodeFlows == null)
                {
                    return(false);
                }

                if (!CodeFlows.SetEquals(other.CodeFlows))
                {
                    return(false);
                }
            }

            if (!Object.ReferenceEquals(RelatedLocations, other.RelatedLocations))
            {
                if (RelatedLocations == null || other.RelatedLocations == null)
                {
                    return(false);
                }

                if (!RelatedLocations.SetEquals(other.RelatedLocations))
                {
                    return(false);
                }
            }

            if (IsSuppressedInSource != other.IsSuppressedInSource)
            {
                return(false);
            }

            if (!Object.ReferenceEquals(Fixes, other.Fixes))
            {
                if (Fixes == null || other.Fixes == null)
                {
                    return(false);
                }

                if (!Fixes.SetEquals(other.Fixes))
                {
                    return(false);
                }
            }

            if (!Object.ReferenceEquals(Properties, other.Properties))
            {
                if (Properties == null || other.Properties == null || Properties.Count != other.Properties.Count)
                {
                    return(false);
                }

                foreach (var value_0 in Properties)
                {
                    string value_1;
                    if (!other.Properties.TryGetValue(value_0.Key, out value_1))
                    {
                        return(false);
                    }

                    if (value_0.Value != value_1)
                    {
                        return(false);
                    }
                }
            }

            if (!Object.ReferenceEquals(Tags, other.Tags))
            {
                if (Tags == null || other.Tags == null)
                {
                    return(false);
                }

                if (!Tags.SetEquals(other.Tags))
                {
                    return(false);
                }
            }

            return(true);
        }