public static FileChangeModel ToFileChangeModel(this FileChange fileChange) { if (fileChange == null) { return null; } FileChangeModel model = new FileChangeModel(); if (fileChange.Replacements != null) { model.FilePath = fileChange.Uri.LocalPath; if (!Path.IsPathRooted(model.FilePath)) { model.FilePath = fileChange.Uri.AbsoluteUri; } foreach (Replacement replacement in fileChange.Replacements) { model.Replacements.Add(replacement.ToReplacementModel()); } } return model; }
private static SarifErrorListItem GetDesignTimeViewModel1() { SarifErrorListItem viewModel = new SarifErrorListItem(); viewModel.Message = "Potential mismatch between sizeof and countof quantities. Use sizeof() to scale byte sizes."; viewModel.Tool = new ToolModel() { Name = "FxCop", Version = "1.0.0.0", }; viewModel.Rule = new RuleModel() { Id = "CA1823", Name = "Avoid unused private fields", HelpUri = "http://aka.ms/analysis/ca1823", DefaultLevel = "Unknown" }; viewModel.Invocation = new InvocationModel() { CommandLine = @"""C:\Temp\Foo.exe"" target.file /o out.sarif", FileName = @"C:\Temp\Foo.exe", }; viewModel.Locations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(11, 1, 11, 2, 0, 0), }); viewModel.Locations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(12, 1, 12, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(21, 1, 21, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(22, 1, 22, 2, 0, 0), }); viewModel.RelatedLocations.Add(new Models.AnnotatedCodeLocationModel() { FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Region = new CodeAnalysis.Sarif.Region(23, 1, 23, 2, 0, 0), }); viewModel.CallTrees.Add(new CallTree( new List<CallTreeNode> { new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Assignment } }, new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.Call, Target = "my_func" }, Children = new List<CallTreeNode> { new CallTreeNode { Location = new AnnotatedCodeLocation { Kind = AnnotatedCodeLocationKind.CallReturn } } } } })); StackCollection stack1 = new StackCollection("Stack A1"); stack1.Add(new StackFrameModel() { Message = "Message A1.1", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 11, Column = 1, FullyQualifiedLogicalName ="My.Assembly.Main(string[] args)", Module = "My.Module.dll", }); stack1.Add(new StackFrameModel() { Message = "Message A1.2", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 12, Column = 1, FullyQualifiedLogicalName = "Our.Shared.Library.Method(int param)", Module = "My.Module.dll", }); stack1.Add(new StackFrameModel() { Message = "Message A1.3", FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs", Line = 1, Column = 1, FullyQualifiedLogicalName = "Your.PIA.External()", }); viewModel.Stacks.Add(stack1); FixModel fix1 = new FixModel("Replace *.Close() with *.Dispose()."); FileChangeModel fileChange11 = new FileChangeModel(); fileChange11.FilePath = @"D:\GitHub\NuGet.Services.Metadata\src\Ng\Catalog2Dnx.cs"; fileChange11.Replacements.Add(new ReplacementModel() { Offset = 1234, DeletedLength = ".Close()".Length, InsertedString = ".Dispose()", }); fix1.FileChanges.Add(fileChange11); viewModel.Fixes.Add(fix1); return viewModel; }