GetUniqueId() 공개 메소드

public GetUniqueId ( ) : string
리턴 string
예제 #1
0
        internal Result CreateResult(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();

            if (!String.IsNullOrWhiteSpace(uniqueId))
            {
                result.ToolFingerprint = uniqueId;
            }

            result.RuleId  = context.CheckId;
            result.Message = context.Message;
            var location = new Location();

            if (!String.IsNullOrEmpty(context.Target))
            {
                location.AnalysisTarget = new PhysicalLocation
                {
                    Uri = new Uri(context.Target, UriKind.RelativeOrAbsolute)
                };
            }

            string sourceFile = GetFilePath(context);

            if (!String.IsNullOrWhiteSpace(sourceFile))
            {
                location.ResultFile = new PhysicalLocation
                {
                    Uri    = new Uri(sourceFile, UriKind.RelativeOrAbsolute),
                    Region = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };
            }

            location.FullyQualifiedLogicalName = CreateSignature(context);

            IList <LogicalLocationComponent> logicalLocationComponents = CreateLogicalLocationComponents(context);

            if (logicalLocationComponents.Any())
            {
                AddLogicalLocation(location, logicalLocationComponents);
            }

            result.Locations = new HashSet <Location> {
                location
            };

            var properties = new Dictionary <string, string>();

            TryAddProperty(properties, context.Level, "Level");
            TryAddProperty(properties, context.Category, "Category");
            TryAddProperty(properties, context.FixCategory, "FixCategory");
            if (properties.Count != 0)
            {
                result.Properties = properties;
            }

            return(result);
        }
예제 #2
0
        internal Result CreateResult(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();

            if (!String.IsNullOrWhiteSpace(uniqueId))
            {
                if (result.PartialFingerprints == null)
                {
                    result.PartialFingerprints = new Dictionary <string, string>();
                }

                SarifUtilities.AddOrUpdateDictionaryEntry(result.PartialFingerprints, "UniqueId", uniqueId);
            }

            string status = context.Status;

            if ("ExcludedInSource".Equals(status))
            {
                result.SuppressionStates = SuppressionStates.SuppressedInSource;
            }
            else if ("ExcludedInProject".Equals(status))
            {
                result.BaselineState = BaselineState.Unchanged;
            }

            result.RuleId  = context.CheckId;
            result.Message = new Message {
                Arguments = context.Items, MessageId = context.ResolutionName, Text = context.Message
            };
            var location = new Location();

            string sourceFile = GetFilePath(context);
            string targetFile = context.Target;

            // If both source and target have values and they're different, set analysis target
            if (!string.IsNullOrWhiteSpace(sourceFile) &&
                !string.IsNullOrWhiteSpace(targetFile) &&
                !sourceFile.Equals(targetFile))
            {
                result.AnalysisTarget = BuildFileLocationFromFxCopReference(targetFile);
            }
            else
            {
                // One or the other or both is null, or they're different
                sourceFile = string.IsNullOrWhiteSpace(sourceFile) ? targetFile : sourceFile;
            }

            // If we have a value, set physical location
            if (!string.IsNullOrWhiteSpace(sourceFile))
            {
                location.PhysicalLocation = new PhysicalLocation
                {
                    ArtifactLocation = BuildFileLocationFromFxCopReference(sourceFile),
                    Region           = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };
            }

            location.FullyQualifiedLogicalName = CreateFullyQualifiedLogicalName(context, out int logicalLocationIndex);
            location.LogicalLocationIndex      = logicalLocationIndex;

            result.Locations = new List <Location> {
                location
            };

            bool mapsDirectlyToSarifName;

            result.Level = ConvertFxCopLevelToResultLevel(context.Level ?? "Warning", out mapsDirectlyToSarifName);

            if (!mapsDirectlyToSarifName)
            {
                // We will not recapitulate FxCop MessageLevel names (such as
                // "Error" and "Warning") as a property. For names that differ
                // (such as "CriticalWarning" and "Information"), we will also
                // include the FxCop-specific values in the property bag.
                AddProperty(result, context.Level, "Level");
            }

            AddProperty(result, context.Category, "Category");
            AddProperty(result, context.FixCategory, "FixCategory");

            return(result);
        }
예제 #3
0
        internal static Result CreateIssue(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();

            if (!String.IsNullOrWhiteSpace(uniqueId))
            {
                result.ToolFingerprint = uniqueId;
            }

            result.RuleId       = context.CheckId;
            result.FullMessage  = context.Message;
            result.ShortMessage = context.Typename;
            Location loc = new Location();

            result.Locations = new[] { loc };

            if (!String.IsNullOrEmpty(context.Target))
            {
                loc.AnalysisTarget = new PhysicalLocation
                {
                    Uri = new Uri(context.Target, UriKind.RelativeOrAbsolute)
                };
            }

            string sourceFile = GetFilePath(context);

            if (!String.IsNullOrWhiteSpace(sourceFile))
            {
                loc.ResultFile = new PhysicalLocation
                {
                    Uri    = new Uri(sourceFile, UriKind.RelativeOrAbsolute),
                    Region = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };
            }

            loc.FullyQualifiedLogicalName = CreateSignature(context);
            var logicalLocation = new List <LogicalLocationComponent>();

            TryAddLogicalLocationComponent(logicalLocation, context.Module, LogicalLocationKind.ClrModule);
            TryAddLogicalLocationComponent(logicalLocation, context.Resource, LogicalLocationKind.ClrResource);
            TryAddLogicalLocationComponent(logicalLocation, context.Namespace, LogicalLocationKind.ClrNamespace);
            TryAddLogicalLocationComponent(logicalLocation, context.Type, LogicalLocationKind.ClrType);
            TryAddLogicalLocationComponent(logicalLocation, context.Member, LogicalLocationKind.ClrFunction);
            if (logicalLocation.Count != 0)
            {
                loc.LogicalLocation = logicalLocation;
            }

            var properties = new Dictionary <string, string>();

            TryAddProperty(properties, context.Level, "Level");
            TryAddProperty(properties, context.Category, "Category");
            TryAddProperty(properties, context.FixCategory, "FixCategory");
            if (properties.Count != 0)
            {
                result.Properties = properties;
            }

            return(result);
        }
예제 #4
0
        internal Result CreateResult(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();

            if (!String.IsNullOrWhiteSpace(uniqueId))
            {
                result.ToolFingerprintContribution = uniqueId;
            }

            string status = context.Status;

            if ("ExcludedInSource".Equals(status))
            {
                result.SuppressionStates = SuppressionStates.SuppressedInSource;
            }
            else if ("ExcludedInProject".Equals(status))
            {
                result.BaselineState = BaselineState.Existing;
            }

            result.RuleId  = context.CheckId;
            result.Message = context.Message;
            var location = new Location();

            if (!String.IsNullOrEmpty(context.Target))
            {
                location.AnalysisTarget = new PhysicalLocation
                {
                    Uri = new Uri(context.Target, UriKind.RelativeOrAbsolute)
                };
            }

            string sourceFile = GetFilePath(context);

            if (!String.IsNullOrWhiteSpace(sourceFile))
            {
                location.ResultFile = new PhysicalLocation
                {
                    Uri    = new Uri(sourceFile, UriKind.RelativeOrAbsolute),
                    Region = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };
            }

            location.FullyQualifiedLogicalName = CreateSignature(context);

            string logicalLocationKey = CreateLogicalLocation(context);

            if (logicalLocationKey != location.FullyQualifiedLogicalName)
            {
                location.LogicalLocationKey = logicalLocationKey;
            }

            result.Locations = new List <Location> {
                location
            };

            bool mapsDirectlyToSarifName;

            result.Level = ConvertFxCopLevelToResultLevel(context.Level, out mapsDirectlyToSarifName);

            if (!mapsDirectlyToSarifName)
            {
                // We will not recapitulate FxCop MessageLevel names (such as
                // "Error" and "Warning") as a property. For names that differ
                // (such as "CriticalWarning" and "Information"), we will also
                // include the FxCop-specific values in the property bag.
                TryAddProperty(result, context.Level, "Level");
            }

            TryAddProperty(result, context.Category, "Category");
            TryAddProperty(result, context.FixCategory, "FixCategory");

            return(result);
        }
예제 #5
0
        internal Result CreateResult(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();

            if (!string.IsNullOrWhiteSpace(uniqueId))
            {
                if (result.PartialFingerprints == null)
                {
                    result.PartialFingerprints = new Dictionary <string, string>();
                }

                SarifUtilities.AddOrUpdateDictionaryEntry(result.PartialFingerprints, "UniqueId", uniqueId);
            }

            string status = context.Status;

            if ("ExcludedInSource".Equals(status))
            {
                result.Suppressions = new List <Suppression>
                {
                    new Suppression
                    {
                        Kind = SuppressionKind.InSource
                    }
                };
            }
            else if ("ExcludedInProject".Equals(status))
            {
                result.BaselineState = BaselineState.Unchanged;
            }

            result.RuleId = context.CheckId;
            string messageText = context.Message ?? ConverterResources.FxCopNoMessage;

            result.Message = new Message {
                Arguments = context.Items, Id = context.ResolutionName, Text = messageText
            };
            var location = new Location();

            string sourceFile = GetFilePath(context);
            string targetFile = context.Target;

            // If both source and target have values and they're different, set analysis target
            if (!string.IsNullOrWhiteSpace(sourceFile) &&
                !string.IsNullOrWhiteSpace(targetFile) &&
                !sourceFile.Equals(targetFile))
            {
                result.AnalysisTarget = BuildFileLocationFromFxCopReference(targetFile);
            }
            else
            {
                // One or the other or both is null, or they're different
                sourceFile = string.IsNullOrWhiteSpace(sourceFile) ? targetFile : sourceFile;
            }

            // Don't emit a location if neither physical location nor logical location information
            // is present. This is the case for CA0001 (unexpected error in analysis tool).
            // https://docs.microsoft.com/en-us/visualstudio/code-quality/ca0001?view=vs-2019
            bool emitLocation = false;

            // If we have a value, set physical location
            if (!string.IsNullOrWhiteSpace(sourceFile))
            {
                location.PhysicalLocation = new PhysicalLocation
                {
                    ArtifactLocation = BuildFileLocationFromFxCopReference(sourceFile),
                    Region           = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };

                emitLocation = true;
            }

            string fullyQualifiedLogicalName = CreateFullyQualifiedLogicalName(context, out int logicalLocationIndex);

            if (!string.IsNullOrWhiteSpace(fullyQualifiedLogicalName) || logicalLocationIndex > -1)
            {
                location.LogicalLocation = new LogicalLocation
                {
                    FullyQualifiedName = fullyQualifiedLogicalName,
                    Index = logicalLocationIndex
                };

                emitLocation = true;
            }

            if (emitLocation)
            {
                result.Locations = new List <Location> {
                    location
                };
            }

            bool mapsDirectlyToSarifName;

            result.Level = ConvertFxCopLevelToResultLevel(context.Level ?? "Warning", out mapsDirectlyToSarifName);

            if (!mapsDirectlyToSarifName)
            {
                // We will not recapitulate FxCop MessageLevel names (such as
                // "Error" and "Warning") as a property. For names that differ
                // (such as "CriticalWarning" and "Information"), we will also
                // include the FxCop-specific values in the property bag.
                AddProperty(result, context.Level, "Level");
            }

            AddProperty(result, context.Category, "Category");
            AddProperty(result, context.FixCategory, "FixCategory");

            return(result);
        }