private void LogIssue(IDictionary <string, object> issueData, IResultLogWriter output) { if (issueData != null) { string description = FindString(issueData, "description"); string category = FindString(issueData, "category"); string issueType = FindString(issueData, "type"); string issueContextKind = FindString(issueData, "issue_context_kind"); string issueContext = FindString(issueData, "issue_context"); string issueHash = FindString(issueData, "issue_hash"); int issueLine = 0; int issueColumn = 0; string fileName = null; IDictionary <string, object> location = FindDictionary(issueData, "location"); if (location != null) { issueLine = FindInt(location, "line"); issueColumn = FindInt(location, "col"); int fileNumber = FindInt(location, "file"); if (_files != null && fileNumber < _files.Count) { fileName = _files[fileNumber] as string; } } Result result = new Result { FullMessage = category + " : " + description, ShortMessage = issueType, Locations = new[] { new Location { AnalysisTarget = new[] { new PhysicalLocationComponent { Uri = new Uri(fileName, UriKind.RelativeOrAbsolute), MimeType = MimeType.DetermineFromFileExtension(fileName), Region = new Region() { StartLine = issueLine, StartColumn = issueColumn } } } } } }; output.WriteResult(result); } }
public void Artifact_PersistBinaryAndTextFileContents( string fileExtension, OptionallyEmittedData dataToInsert, bool shouldBePersisted) { string filePath = Path.GetTempFileName() + fileExtension; string fileContents = Guid.NewGuid().ToString(); Uri uri = new Uri(filePath); try { File.WriteAllText(filePath, fileContents); Artifact fileData = Artifact.Create(uri, dataToInsert); fileData.Location.Should().BeNull(); if (dataToInsert.HasFlag(OptionallyEmittedData.Hashes)) { fileData.Hashes.Should().NotBeNull(); } else { fileData.Hashes.Should().BeNull(); } string encodedFileContents = Convert.ToBase64String(File.ReadAllBytes(filePath)); if (shouldBePersisted) { string mimeType = MimeType.DetermineFromFileExtension(uri); if (MimeType.IsBinaryMimeType(mimeType)) { fileData.Contents.Binary.Should().Be(encodedFileContents); fileData.Contents.Text.Should().BeNull(); } else { fileData.Contents.Binary.Should().BeNull(); fileData.Contents.Text.Should().Be(fileContents); } } else { fileData.Contents.Should().BeNull(); } } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } }
private static List <PhysicalLocationComponent> ConvertFortifyLocationToPhysicalLocation(FortifyPathElement element) { return(new List <PhysicalLocationComponent> { new PhysicalLocationComponent { Uri = new Uri(element.FilePath, UriKind.RelativeOrAbsolute), MimeType = MimeType.DetermineFromFileExtension(element.FilePath), Region = Extensions.CreateRegion(element.LineStart) } }); }
private void ParseFile() { int length = 0; string sizeAttribute = _reader.GetAttribute(_strings.SizeAttribute); if (sizeAttribute != null) { int.TryParse(sizeAttribute, out length); } string encoding = _reader.GetAttribute(_strings.EncodingAttribute); string fileName = null; _reader.Read(); while (!AtEndOf(_strings.File)) { if (AtStartOfNonEmpty(_strings.Name)) { fileName = UriHelper.MakeValidUri(_reader.ReadElementContentAsString()); } else { _reader.Read(); } } if (!string.IsNullOrEmpty(fileName)) { Uri uri = new Uri(fileName, UriKind.RelativeOrAbsolute); var fileData = new Artifact { Encoding = encoding, MimeType = MimeType.DetermineFromFileExtension(fileName), Length = length, Location = new ArtifactLocation { Uri = uri, UriBaseId = uri.IsAbsoluteUri ? null : FileLocationUriBaseId } }; _files.Add(fileData); } }
private void ParseFile() { string fileType = _reader.GetAttribute(_strings.TypeAttribute); int length = 0; string sizeAttribute = _reader.GetAttribute(_strings.SizeAttribute); if (sizeAttribute != null) { int.TryParse(sizeAttribute, out length); } string fileName = null; _reader.Read(); while (!AtEndOf(_strings.File)) { if (AtStartOfNonEmpty(_strings.Name)) { fileName = _reader.ReadElementContentAsString(); } else { _reader.Read(); } } if (!String.IsNullOrEmpty(fileName)) { var fileData = new FileData { MimeType = MimeType.DetermineFromFileExtension(fileName), Length = length }; if (fileType != null) { fileData.SetProperty(FprFileTypePropertyName, fileType); } _fileDictionary.Add(fileName, fileData); } }
private void ParseFile() { int length = 0; string sizeAttribute = _reader.GetAttribute(_strings.SizeAttribute); if (sizeAttribute != null) { int.TryParse(sizeAttribute, out length); } string encoding = _reader.GetAttribute(_strings.EncodingAttribute); string fileName = null; _reader.Read(); while (!AtEndOf(_strings.File)) { if (AtStartOfNonEmpty(_strings.Name)) { fileName = UriHelper.MakeValidUri(_reader.ReadElementContentAsString()); } else { _reader.Read(); } } if (!string.IsNullOrEmpty(fileName)) { var fileData = new FileData { Encoding = encoding, MimeType = MimeType.DetermineFromFileExtension(fileName), Length = length }; _fileDictionary.Add(fileName, fileData); } }
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[] { new PhysicalLocationComponent { Uri = new Uri(context.Target, UriKind.RelativeOrAbsolute), MimeType = MimeType.Binary } }; } string sourceFile = GetFilePath(context); if (!String.IsNullOrWhiteSpace(sourceFile)) { loc.ResultFile = new[] { new PhysicalLocationComponent { Uri = new Uri(sourceFile, UriKind.RelativeOrAbsolute), MimeType = MimeType.DetermineFromFileExtension(sourceFile), 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); }