Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }
Exemple #4
0
        /// <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;
        }