private DummyFixModel InitializeDummyFixModel() { var fileSystem = new DummyFileSystem(); fileSystem.WriteAllBytes("index.html", File.ReadAllBytes(@"TestData\FixModel\index.html")); var fixModel = new DummyFixModel("Test dummy", fileSystem); var replacements = new List <ReplacementModel>(); replacements.Add(new ReplacementModel() { Offset = 191, DeletedLength = 0, InsertedString = "\"" }); replacements.Add(new ReplacementModel() { Offset = 199, DeletedLength = 0, InsertedString = "\"" }); replacements.Add(new ReplacementModel() { Offset = 233, DeletedLength = 3, InsertedString = "img" }); replacements.ForEach(rm => rm.InsertedBytes = Encoding.UTF8.GetBytes(rm.InsertedString)); var changeModel = new FileChangeModel() { FilePath = @"C:\source\index.html" }; replacements.ForEach(r => changeModel.Replacements.Add(r)); fixModel.FileChanges.Add(changeModel); return(fixModel); }
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); }
public void FileChangeModel_FromFileChange_RelativePath() { FileChange fileChange = new FileChange { FileLocation = new FileLocation { Uri = new Uri(@"\src\tools\util.cs", UriKind.RelativeOrAbsolute) }, Replacements = new List <Replacement>() }; FileChangeModel model = fileChange.ToFileChangeModel(); model.FilePath.Should().Be(@"\src\tools\util.cs"); }
public static FileChangeReqs GetFileChangeReqs(string directory, string pattern) { int seconds = int.Parse(ConfigurationManager.AppSettings["NumSeconds"]); FileChangeReqs fcr = new FileChangeReqs(seconds, directory, pattern); string[] arrFiles = Directory.GetFiles(directory, pattern, SearchOption.TopDirectoryOnly); //no subdirectories. if (arrFiles != null) { Parallel.ForEach(arrFiles, (file) => { FileChangeModel fcm = new FileChangeModel(); fcm.FileName = file; fcm.NumLines = GetFileLinesCount(file); fcm.DateModified = GetFileDateModified(file); fcr.FileChanges.Add(fcm); }); } return(fcr); }
public static FileChangeModel ToFileChangeModel(this FileChange fileChange) { if (fileChange == null) { return(null); } FileChangeModel model = new FileChangeModel(); if (fileChange.Replacements != null) { model.FilePath = fileChange.Uri.IsAbsoluteUri ? fileChange.Uri.AbsoluteUri : fileChange.Uri.OriginalString; 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 } } } } }, SarifViewerPackage.SarifToolWindow)); 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); }