/// <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> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> that can be used to cancel the initialization of the package. /// </param> /// <param name="progress"> /// A provider to update progress. /// </param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(continueOnCapturedContext: true); var callback = new ServiceCreatorCallback(this.CreateService); foreach (KeyValuePair <Type, ServiceInformation> serviceInformationKVP in ServiceTypeToServiceInformation) { ((IServiceContainer)this).AddService(serviceInformationKVP.Key, callback, promote: serviceInformationKVP.Value.Promote); } await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // initialize Option first since other componments may depends on options. await SarifViewerOption.InitializeAsync(this).ConfigureAwait(false); OpenLogFileCommands.Initialize(this); CodeAnalysisResultManager.Instance.Register(); SarifToolWindowCommand.Initialize(this); ErrorList.ErrorListCommand.Initialize(this); this.sarifFolderMonitor = new SarifFolderMonitor(); if (await this.IsSolutionLoadedAsync()) { // Async package initilized after solution is fully loaded according to // [ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)] // SolutionEvents.OnAfterBackgroundSolutionLoadComplete will not by triggered until the user opens another solution. // Need to manually start monitor in this case. this.sarifFolderMonitor?.StartWatch(); } SolutionEvents.OnBeforeCloseSolution += this.SolutionEvents_OnBeforeCloseSolution; SolutionEvents.OnAfterBackgroundSolutionLoadComplete += this.SolutionEvents_OnAfterBackgroundSolutionLoadComplete; return; }
public SarifViewerPackageUnitTests() { SarifViewerPackage.IsUnitTesting = true; SarifViewerOption.InitializeForUnitTests(); }