internal void OpenLogFile()

in src/Sarif.Viewer.VisualStudio.Core/Models/SarifErrorListItem.cs [370:420]


        internal void OpenLogFile()
        {
            // For now this is being done on the UI thread
            // and is only required due to the message box being shown below.
            // This will be addressed when https://github.com/microsoft/sarif-visualstudio-extension/issues/160
            // is fixed.
            ThreadHelper.ThrowIfNotOnUIThread();

            if (this.LogFilePath != null)
            {
                if (File.Exists(this.LogFilePath))
                {
                    var dte = AsyncPackage.GetGlobalService(typeof(DTE)) as DTE2;
                    dte.ExecuteCommand("File.OpenFile", $@"""{this.LogFilePath}"" /e:""JSON Editor""");
                }
                else if (CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.TryGetValue(this.RunIndex, out RunDataCache cache))
                {
                    // LogFilePath doesn't exist then its a background analyzer result in memeory
                    // load sarif log from memory cache
                    string sarifLogFilePath = Path.Combine(CodeAnalysisResultManager.Instance.TempDirectoryPath, $"{cache.SarifLog.GetHashCode()}");
                    if (!Directory.Exists(CodeAnalysisResultManager.Instance.TempDirectoryPath))
                    {
                        Directory.CreateDirectory(CodeAnalysisResultManager.Instance.TempDirectoryPath);
                    }

                    if (!File.Exists(sarifLogFilePath))
                    {
                        // serialize memory cached SarifLog into a temp file
                        var serializer = new JsonSerializer
                        {
                            Formatting = Formatting.Indented,
                        };
                        using var sw = new StreamWriter(sarifLogFilePath);
                        using JsonWriter writer = new JsonTextWriter(sw);
                        serializer.Serialize(writer, cache.SarifLog);
                    }

                    // open temp sarif log file
                    SdkUIUtilities.OpenDocument(ServiceProvider.GlobalProvider, sarifLogFilePath, usePreviewPane: false);
                }
                else
                {
                    VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider,
                                                    string.Format(Resources.OpenLogFileFail_DialogMessage, this.LogFilePath),
                                                    null, // title
                                                    OLEMSGICON.OLEMSGICON_CRITICAL,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }
        }