private async System.Threading.Tasks.Task InitializeCommandsAsync(IProgress <ServiceProgressData> progress)
        {
            // if the package is zombied, we don't want to add commands
            if (Zombied)
            {
                return;
            }

            var progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitCommands,
                                                       currentStep: 2, TotalLoadSteps);

            progress?.Report(progressData);

            OleMenuCommandService oleCommandService = await this.GetServiceAsync <IMenuCommandService, OleMenuCommandService>();

            if (oleCommandService == null)
            {
                InvalidOperationException loadCommandServiceException = new InvalidOperationException("Failed to load OLE command service");
                AcuminatorLogger.LogException(loadCommandServiceException, logOnlyFromAcuminatorAssemblies: false, LogMode.Error);
                return;
            }

            FormatBqlCommand.Initialize(this, oleCommandService);
            GoToDeclarationOrHandlerCommand.Initialize(this, oleCommandService);
            BqlFixer.FixBqlCommand.Initialize(this, oleCommandService);

            OpenCodeMapWindowCommand.Initialize(this, oleCommandService);
        }
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread
            await base.InitializeAsync(cancellationToken, progress);

            if (Zombied)
            {
                return;
            }

            await JoinableTaskFactory.SwitchToMainThreadAsync();

            InitializeLogger(progress);
            await InitializeCommandsAsync(progress);

            // Extra suppression manager initilization - in theory it should be enough to do this on solution opening but sometimes the reace condition occurs
            // The solution is opened before the project loads and subscribes on its opening. So we add one extra call to initialize suppression manager
            // which is a little overhead but ensures that if we have an opened solution with loaded Acuminator then the suppression manager is initialized
            await SetupSuppressionManagerAsync();

            await SubscribeOnSolutionEventsAsync();

            cancellationToken.ThrowIfCancellationRequested();

            InitializeCodeAnalysisSettings(progress);
            cancellationToken.ThrowIfCancellationRequested();

            var progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_Done,
                                                       currentStep: 5, TotalLoadSteps);

            progress?.Report(progressData);
        }
        private void InitializeCodeAnalysisSettings(IProgress <ServiceProgressData> progress)
        {
            var progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitCodeAnalysisSettings,
                                                       currentStep: 4, TotalLoadSteps);

            progress?.Report(progressData);
            var codeAnalysisSettings = new CodeAnalysisSettingsFromOptionsPage(GeneralOptionsPage);

            GlobalCodeAnalysisSettings.InitializeGlobalSettingsOnce(codeAnalysisSettings);
        }
Esempio n. 4
0
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread
            await base.InitializeAsync(cancellationToken, progress);

            if (Zombied)
            {
                return;
            }

            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitCodeAnalysisSettings,
                                                       currentStep: 1, TotalLoadSteps);

            progress?.Report(progressData);

            _vsWorkspace = await this.GetVSWorkspaceAsync();
            await InitializeCodeAnalysisSettingsAsync();

            progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitLogger,
                                                   currentStep: 2, TotalLoadSteps);
            progress?.Report(progressData);
            InitializeLogger();

            cancellationToken.ThrowIfCancellationRequested();

            await InitializeCommandsAsync();

            progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitCommands,
                                                   currentStep: 3, TotalLoadSteps);
            progress?.Report(progressData);

            SubscribeOnEvents();

            cancellationToken.ThrowIfCancellationRequested();

            bool isSolutionOpen = await IsSolutionLoadedAsync();

            if (isSolutionOpen)
            {
                SetupSuppressionManager();
            }

            progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_Done,
                                                   currentStep: 4, TotalLoadSteps);
            progress?.Report(progressData);
        }
        private void InitializeLogger(IProgress <ServiceProgressData> progress)
        {
            var progressData = new ServiceProgressData(VSIXResource.PackageLoad_WaitMessage, VSIXResource.PackageLoad_InitLogger,
                                                       currentStep: 1, TotalLoadSteps);

            progress?.Report(progressData);

            try
            {
                AcuminatorLogger = new AcuminatorLogger(this, swallowUnobservedTaskExceptions: false);
            }
            catch (Exception ex)
            {
                ActivityLog.TryLogError(PackageName,
                                        $"An error occurred during the logger initialization ({ex.GetType().Name}, message: \"{ex.Message}\")");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Reports the current step of initialization.
        /// </summary>
        /// <param name="progress">The <see cref="IProgress{ServiceProgressData}"/> channel.</param>
        /// <param name="step">The number of the current step.</param>
        private static void ReportNextInitStep(IProgress <ServiceProgressData> progress, int step)
        {
            var progressData = new ServiceProgressData("Starting SteroidsVS", "Initializing...", step, 3);

            progress.Report(progressData);
        }