/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { OpenLogFileCommands.Initialize(this); base.Initialize(); string path = Assembly.GetExecutingAssembly().Location; var configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = Path.Combine(Path.GetDirectoryName(path), "App.config"); AppConfig = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); #if DEBUG string telemetryKey = SarifViewerPackage.AppConfig.AppSettings.Settings["TelemetryInstrumentationKey_Debug"].Value; #else string telemetryKey = SarifViewerPackage.AppConfig.AppSettings.Settings["TelemetryInstrumentationKey_Release"].Value; #endif TelemetryConfiguration configuration = new TelemetryConfiguration() { InstrumentationKey = telemetryKey }; TelemetryProvider.Initialize(configuration); TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded); _sarifEditorFactory = new SarifEditorFactory(); RegisterEditorFactory(_sarifEditorFactory); CodeAnalysisResultManager.Instance.Register(); Microsoft.Sarif.Viewer.SarifToolWindowCommand.Initialize(this); }
internal static IVsWindowFrame OpenDocument(IServiceProvider provider, string file, bool usePreviewPane) { ThreadHelper.ThrowIfNotOnUIThread(); if (string.IsNullOrEmpty(file)) { // No place to go return(null); } // We should not throw exceptions if we cannot find the file if (!File.Exists(file)) { return(null); } TelemetryProvider.WriteEvent(TelemetryEvent.TaskItemDocumentOpened); try { if (usePreviewPane) { // The scope below ensures that if a document is not yet open, it is opened in the preview pane. // For documents that are already open, they will remain in their current pane, which may be the preview // pane or the full editor pane. using (new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional | __VSNEWDOCUMENTSTATE.NDS_NoActivate, Microsoft.VisualStudio.VSConstants.NewDocumentStateReason.Navigation)) { return(OpenDocumentInCurrentScope(provider, file)); } } else { return(OpenDocumentInCurrentScope(provider, file)); } } catch (COMException) { string fname = Path.GetFileName(file); if (System.Windows.Forms.MessageBox.Show(string.Format(Resources.FileOpenFail_DialogMessage, fname), Resources.FileOpenFail_DialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { System.Diagnostics.Process.Start(Path.GetDirectoryName(file)); } return(null); } }
public int CreateEditorInstance( uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW) { ppunkDocView = IntPtr.Zero; ppunkDocData = IntPtr.Zero; pguidCmdUI = Guids.GuidSarifEditorFactory; pgrfCDW = 0; pbstrEditorCaption = null; // Validate inputs if ((grfCreateDoc & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0) { return(VSConstants.E_INVALIDARG); } if (punkDocDataExisting != IntPtr.Zero) { return(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } if ((grfCreateDoc & VSConstants.CEF_OPENFILE) == VSConstants.CEF_OPENFILE) { TelemetryProvider.WriteEvent(TelemetryEvent.LogFileOpenedByEditor, TelemetryProvider.CreateKeyValuePair("Format", "SARIF")); ErrorListService.ProcessLogFile(pszMkDocument, SarifViewerPackage.Dte.Solution); } return(VSConstants.S_OK); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { OpenLogFileCommands.Initialize(this); base.Initialize(); ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); ((IServiceContainer)this).AddService(typeof(SLoadSarifLogService), callback, true); string path = Assembly.GetExecutingAssembly().Location; var configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = Path.Combine(Path.GetDirectoryName(path), "App.config"); AppConfig = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); #if DEBUG string telemetryKey = SarifViewerPackage.AppConfig.AppSettings.Settings["TelemetryInstrumentationKey_Debug"].Value; #else string telemetryKey = SarifViewerPackage.AppConfig.AppSettings.Settings["TelemetryInstrumentationKey_Release"].Value; #endif TelemetryConfiguration configuration = new TelemetryConfiguration() { InstrumentationKey = telemetryKey }; TelemetryProvider.Initialize(configuration); TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded); _sarifEditorFactory = new SarifEditorFactory(); RegisterEditorFactory(_sarifEditorFactory); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); CodeAnalysisResultManager.Instance.Register(); SarifToolWindowCommand.Initialize(this); ErrorList.ErrorListCommand.Initialize(this); return; }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { OleMenuCommand menuCommand = (OleMenuCommand)sender; OleMenuCmdEventArgs menuCmdEventArgs = (OleMenuCmdEventArgs)e; string inputFile = menuCmdEventArgs.InValue as String; string logFile = null; if (!String.IsNullOrWhiteSpace(inputFile)) { // If the input file is a URL, download the file. if (Uri.IsWellFormedUriString(inputFile, UriKind.Absolute)) { TryDownloadFile(inputFile, out logFile); } else { // Verify if the input file is valid. i.e. it exists and has a valid file extension. string logFileExtension = Path.GetExtension(inputFile); // Since we don't have a tool format, only accept *.sarif and *.json files as command input files. if (logFileExtension.Equals(".sarif", StringComparison.OrdinalIgnoreCase) || logFileExtension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { if (File.Exists(inputFile)) { logFile = inputFile; } } } } string toolFormat = ToolFormat.None; if (logFile == null) { string title = "Open Static Analysis Results Interchange Format (SARIF) file"; string filter = "SARIF files (*.sarif)|*.sarif"; switch (menuCommand.CommandID.ID) { // These constants expressed in our VSCT case OpenSarifFileCommandId: { // Native SARIF. All our defaults above are fine break; } case OpenPREfastFileCommandId: { toolFormat = ToolFormat.PREfast; title = "Open PREfast XML log file"; filter = "PREfast log files (*.xml)|*.xml"; break; } case OpenStaticDriverVerifierFileCommandId: { toolFormat = ToolFormat.StaticDriverVerifier; title = "Open Static Driver Verifier trace log file"; filter = "Static Driver Verifier log files (*.tt)|*.tt"; break; } case OpenFxCopFileCommandId: { // FxCop. TODO. We need project file support. FxCop // fullMessages look broken. toolFormat = ToolFormat.FxCop; title = "Open FxCop XML log file"; filter = "FxCop report and project files (*.xml)|*.xml"; break; } case OpenCppCheckFileCommandId: { toolFormat = ToolFormat.CppCheck; title = "Open CppCheck XML log file"; filter = "CppCheck log files (*.xml)|*.xml"; break; } case OpenClangFileCommandId: { toolFormat = ToolFormat.ClangAnalyzer; title = "Open Clang XML log file"; filter = "Clang log files (*.xml)|*.xml"; break; } case OpenAndroidStudioFileCommandId: { toolFormat = ToolFormat.AndroidStudio; title = "Open Android Studio XML log file"; filter = "Android Studio log files (*.xml)|*.xml"; break; } case OpenSemmleFileCommandId: { toolFormat = ToolFormat.SemmleQL; title = "Open Semmle QL CSV log file"; filter = "Semmle QL log files (*.csv)|*.csv"; break; } case OpenPylintFileCommand: { toolFormat = ToolFormat.Pylint; title = "Open Pylint JSON log file"; filter = "Pylint log files (*.json)|*.json"; break; } case OpenTSLintFileCommand: { toolFormat = ToolFormat.TSLint; title = "Open TSLint JSON log file"; filter = "TSLint log files (*.json)|*.json"; break; } } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = title; openFileDialog.Filter = filter; openFileDialog.RestoreDirectory = true; if (!String.IsNullOrWhiteSpace(inputFile)) { openFileDialog.FileName = Path.GetFileName(inputFile); openFileDialog.InitialDirectory = Path.GetDirectoryName(inputFile); } if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } logFile = openFileDialog.FileName; } TelemetryProvider.WriteMenuCommandEvent(toolFormat); try { ErrorListService.ProcessLogFile(logFile, SarifViewerPackage.Dte.Solution, toolFormat); } catch (InvalidOperationException) { VsShellUtilities.ShowMessageBox(SarifViewerPackage.ServiceProvider, string.Format(Resources.LogOpenFail_InvalidFormat_DialogMessage, Path.GetFileName(logFile)), null, // title OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } }