Exemplo n.º 1
0
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            var commandServicesContainerBuilder = new CommandServicesContainer.Builder(this);

            await commandServicesContainerBuilder.CreateServicesAsync();

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            commandServicesContainerBuilder.CreateServicesOnUIThread();

            var commandServicesContainer = commandServicesContainerBuilder.GetCommandServicesContainer();

            InitializeCommands();

            await base.InitializeAsync(cancellationToken, progress);

            void InitializeCommands()
            {
                AnalyzeSolutionCommand.Initialize(commandServicesContainer);
                AnalyzeSelectedProjectsCommand.Initialize(commandServicesContainer);

                ShowOptionsDialogCommand.Initialize(commandServicesContainer);
                ShowSharpenResultsToolWindowCommand.Initialize(commandServicesContainer);

                AnalyzeCurrentDocumentContextCommand.Initialize(commandServicesContainer);
                AnalyzeSolutionContextCommand.Initialize(commandServicesContainer);
                AnalyzeSelectedProjectsContextCommand.Initialize(commandServicesContainer);
                AnalyzeSelectedDocumentsContextCommand.Initialize(commandServicesContainer);
                AnalyzeSelectedFoldersContextCommand.Initialize(commandServicesContainer);
            }
        }
        /// <summary>
        /// Initialize the package. All the initialization code that relies on services provided by
        /// Visual Studio belongs here.
        /// </summary>
        /// <param name="cancellationToken">
        /// A <see cref="CancellationToken"/> that can be used to cancel the initialization.
        /// </param>
        /// <param name="progress">
        /// A provider to update progress.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.
        /// </returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(continueOnCapturedContext: true);

            // When initialized asynchronously, we *may* be on a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            // Otherwise, remove the switch to the UI thread if you don't need it.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            ((IServiceContainer)this).AddService(
                typeof(IBackgroundAnalysisService),
                new BackgroundAnalysisService());

            // The OleCommandService object provided by the MPF is responsible for managing the set
            // of commands implemented by the package.
            if (await this.GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService mcs &&
                await this.GetServiceAsync(typeof(SVsShell)) is IVsShell vsShell)
            {
                _ = new GenerateTestDataCommand(vsShell, mcs);
                this.analyzeSolutionCommand = new AnalyzeSolutionCommand(mcs);
                this.analyzeProjectCommand  = new AnalyzeProjectCommand(mcs);
                this.analyzeFileCommand     = new AnalyzeFileCommand(mcs);
            }

            if (await this.GetServiceAsync(typeof(SVsOutputWindow)) is IVsOutputWindow output)
            {
                this.outputWindowTraceListener = new OutputWindowTracerListener(output, "Sarifer");
            }

            SolutionEvents.OnBeforeCloseSolution += this.SolutionEvents_OnBeforeCloseSolution;

            await SariferOption.InitializeAsync(this).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        protected override void Initialize()
        {
            SharpenExtensionService.CreateSingleInstance();

            AnalyzeSolutionCommand.Initialize(this, SharpenExtensionService.Instance);
            AnalyzeSelectedProjectsCommand.Initialize(this, SharpenExtensionService.Instance);
            ShowOptionsDialogCommand.Initialize(this);
            ShowSharpenResultsToolWindowCommand.Initialize(this);

            base.Initialize();
        }