public void ErrorListService_ProcessSarifLogAsync_InvalidJson()
        {
            // unhook original event handler and hook test event
            ErrorListService.LogProcessed -= ErrorListService.ErrorListService_LogProcessed;
            ErrorListService.LogProcessed += ErrorListServiceTest_LogProcessed;

            // invalid Json syntax, a separate comma in line 4
            // {"Invalid property identifier character: ,. Path '$schema', line 4, position 2."}
            string invalidJson =
                @"
{
  ""$schema"": ""https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json"",
  ,
  ""version"": ""2.1.0"",
  ""runs"": [
    {
      ""tool"": {
        ""name"": ""CodeScanner""
      },
      ""results"": [
      ]
    }
  ]
}
";
            int numberOfException = numberOfExceptionLogged;

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(invalidJson));
            ErrorListService.ProcessSarifLogAsync(stream, "logId", false, false).ConfigureAwait(false);
            // 1 exception logged
            numberOfExceptionLogged.Should().Be(numberOfException + 1);
        }
        public void ErrorListService_MatchesVersionProperty()
        {
            var failedTestCases = new List <TestCase>();

            foreach (TestCase testCase in s_testCases)
            {
                Match match = ErrorListService.MatchVersionProperty(testCase.Input);

                bool failed = false;
                if (match.Success != testCase.ExpectedMatchSuccess)
                {
                    failed = true;
                }

                if (!failed && testCase.ExpectedMatchSuccess)
                {
                    if (match.Groups["version"].Value != testCase.ExpectedVersion)
                    {
                        failed = true;
                    }
                }

                if (failed)
                {
                    failedTestCases.Add(testCase);
                }
            }

            failedTestCases.Should().BeEmpty();
        }
        public static void InitializeTestEnvironment(SarifLog sarifLog)
        {
            InitializeTestEnvironment();
            CodeAnalysisResultManager.Instance.CurrentRunId = 0;

            ErrorListService.ProcessSarifLog(sarifLog, "", null, showMessageOnNoResults: true);
        }
 public async Task LoadSarifLogAsync(IEnumerable <Stream> streams)
 {
     foreach (Stream stream in streams)
     {
         await ErrorListService.ProcessSarifLogAsync(stream, logId : null, cleanErrors : false, openInEditor : false).ConfigureAwait(continueOnCapturedContext: false);
     }
 }
 private void RefreshSarifErrors(string filePath)
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ErrorListService.CloseSarifLogItemsAsync(new string[] { filePath });
         await ErrorListService.ProcessLogFileAsync(filePath, ToolFormat.None, promptOnLogConversions: true, cleanErrors: false, openInEditor: false);
     });
 }
        /// <inheritdoc/>
        public void LoadSarifLog(string path, bool promptOnLogConversions = true, bool cleanErrors = true, bool openInEditor = false)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            ErrorListService.ProcessLogFile(path, ToolFormat.None, promptOnLogConversions, cleanErrors, openInEditor);
        }
        private async Task LoadSarifLogAsync(IEnumerable <string> paths)
        {
            var validPaths = paths.Where(path => !string.IsNullOrEmpty(path)).ToList();

            if (validPaths.Count == 0)
            {
                return;
            }

            var taskStatusCenterService = (IVsTaskStatusCenterService)Package.GetGlobalService(typeof(SVsTaskStatusCenterService));
            var taskProgressData        = new TaskProgressData
            {
                CanBeCanceled = true,
                ProgressText  = null,
            };

            var taskHandlerOptions = new TaskHandlerOptions
            {
                ActionsAfterCompletion = CompletionActions.None,
                TaskSuccessMessage     = Resources.ProcessLogFilesComplete,
                Title = Resources.ProcessLogFiles,
            };

            var          taskCompletionSource = new TaskCompletionSource <bool>();
            ITaskHandler taskHandler          = taskStatusCenterService.PreRegister(taskHandlerOptions, taskProgressData);

            taskHandler.RegisterTask(taskCompletionSource.Task);

            try
            {
                for (int validPathIndex = 0; validPathIndex < validPaths.Count; validPathIndex++)
                {
                    taskHandler.UserCancellation.ThrowIfCancellationRequested();

                    taskHandler.Progress.Report(new TaskProgressData
                    {
                        PercentComplete = validPathIndex * 100 / validPaths.Count,
                        ProgressText    = string.Format(CultureInfo.CurrentCulture, Resources.ProcessingLogFileFormat, validPaths[validPathIndex]),
                    });

                    // We should not clean errors here. If the user wants to clear errors, they can call ICloseSarifLogService.CloseAllSarifLogs.
                    await ErrorListService.ProcessLogFileAsync(validPaths[validPathIndex], ToolFormat.None, promptOnLogConversions : false, cleanErrors : false, openInEditor : false).ConfigureAwait(continueOnCapturedContext: false);

                    taskHandler.Progress.Report(new TaskProgressData
                    {
                        PercentComplete = (validPathIndex + 1) * 100 / validPaths.Count,
                    });
                }
            }
            finally
            {
                taskCompletionSource.SetResult(true);
            }
        }
        public async Task ErrorList_IsSarifLogOpened()
        {
            TestUtilities.InitializeTestEnvironment();

            string logFileName1   = @"C:\git\repo\sarif-sdk\test_data\testresult1.sarif";
            string logFileName2   = @"C:\git\repo\sarif-sdk\test_data\testtool2.sarif";
            bool   sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);

            sarifLogOpened.Should().BeFalse();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeFalse();

            // load sarif log 1
            await TestUtilities.InitializeTestEnvironmentAsync(this.testLog, logFileName1);

            bool hasFirstError  = SarifTableDataSource.Instance.HasErrors("/item1.cpp");
            bool hasSecondError = SarifTableDataSource.Instance.HasErrors("/item2.cpp");
            bool hasThirdError  = SarifTableDataSource.Instance.HasErrors("/item3.cpp");

            bool hasBothErrors = hasFirstError && hasSecondError && hasThirdError;

            hasBothErrors.Should().BeTrue();

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeTrue();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeFalse();

            // load sarif log 2
            await TestUtilities.InitializeTestEnvironmentAsync(this.testLog, logFileName2, cleanErrors : false);

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeTrue();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeTrue();

            // close sairf log 1
            await ErrorListService.CloseSarifLogItemsAsync(new string[] { logFileName1 });

            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName1);
            sarifLogOpened.Should().BeFalse();
            sarifLogOpened = ErrorListService.IsSarifLogOpened(logFileName2);
            sarifLogOpened.Should().BeTrue();
        }
        public void ErrorListService_ProcessSarifLogAsync_JsonNotCompatibleWithSarifShema()
        {
            // unhook original event handler and hook test event
            ErrorListService.LogProcessed -= ErrorListService.ErrorListService_LogProcessed;
            ErrorListService.LogProcessed += ErrorListServiceTest_LogProcessed;

            // valid Json syntax, but not satisfy schema, missing required property driver
            // {"Required property 'text' not found in JSON. Path 'runs[0].tool.driver.rules[0].fullDescription', line 14, position 36."}
            string jsonNotCompatible =
                @"
{
  ""$schema"": ""https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json"",
  ""version"": ""2.1.0"",
  ""runs"": [
    {
      ""tool"": {
        ""driver"": {
          ""name"": ""CodeScanner"",
          ""rules"": [
            {
              ""id"": ""Intrafile1001"",
              ""name"": ""IntrafileRule"",
              ""fullDescription"": { },
              ""helpUri"": ""https://github.com/microsoft/sarif-pattern-matcher""
            }
          ]
        },
      ""results"": [
      ]
    }
  ]
}
";
            int numberOfException = this.numberOfExceptionLogged;

            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonNotCompatible));
            ErrorListService.ProcessSarifLogAsync(stream, "logId", false, false).ConfigureAwait(false);
            // 1 exception logged
            this.numberOfExceptionLogged.Should().Be(numberOfException + 1);
        }
Exemplo n.º 10
0
        // This handles adding and removing things from the error list
        private void OnXamlDocParsed(object sender, RapidXamlParsingEventArgs e)
        {
            var visibleErrors = RapidXamlDocumentCache.ErrorListTags(this.file);

            var projectName = this.GetProjectName(this.file);

            var result = new FileErrorCollection {
                Project = projectName, FilePath = this.file
            };

            foreach (var viewTag in visibleErrors)
            {
                result.Errors.Add(viewTag.AsErrorRow());
            }

            ErrorListService.Process(result);

            // As the tags that are shown in the error list might have changed, trigger that to be updated too.
            if (e != null)
            {
                var span = new SnapshotSpan(e.Snapshot, 0, e.Snapshot.Length);
                this.TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
            }
        }
        public static async Task InitializeTestEnvironmentAsync(SarifLog sarifLog, string logFile = "", bool cleanErrors = true)
        {
            InitializeTestEnvironment();

            await ErrorListService.ProcessSarifLogAsync(sarifLog, logFile, cleanErrors : cleanErrors, openInEditor : false);
        }
 /// <inheritdoc/>
 public void CloseSarifLogs(IEnumerable <string> paths)
 {
     ErrorListService.CloseSarifLogs(paths);
 }
 /// <inheritdoc/>
 public void CloseAllSarifLogs()
 {
     ErrorListService.CloseAllSarifLogs();
 }
        public static void InitializeTestEnvironment(SarifLog sarifLog)
        {
            InitializeTestEnvironment();

            ErrorListService.ProcessSarifLog(sarifLog, "", null);
        }
 private async Task LoadSarifLogAsync(Stream stream, string logId)
 {
     await ErrorListService.ProcessSarifLogAsync(stream, logId : logId, cleanErrors : false, openInEditor : false).ConfigureAwait(continueOnCapturedContext: false);
 }
        public static async Task InitializeTestEnvironmentAsync(SarifLog sarifLog)
        {
            InitializeTestEnvironment();

            await ErrorListService.ProcessSarifLogAsync(sarifLog, string.Empty, cleanErrors : true, openInEditor : false);
        }