/// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static async Task InitializeAsync(AsyncPackage package)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            _componentModel = Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel;

            var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            Instance = new DoCreateClusterCommand(package, commandService !);
        }
Beispiel #2
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _componentModel_doNotAccessDirectly = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true);

            Assumes.Present(_componentModel_doNotAccessDirectly);
        }
Beispiel #3
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true);

            cancellationToken.ThrowIfCancellationRequested();
            Assumes.Present(_componentModel);

            // Ensure the options persisters are loaded since we have to fetch options from the shell
            foreach (var provider in await GetOptionPersistersAsync(_componentModel, cancellationToken).ConfigureAwait(true))
            {
                _ = await provider.GetOrCreatePersisterAsync(cancellationToken).ConfigureAwait(true);
            }

            _workspace = _componentModel.GetService <VisualStudioWorkspace>();
            _workspace.Services.GetService <IExperimentationService>();

            // Fetch the session synchronously on the UI thread; if this doesn't happen before we try using this on
            // the background thread then we will experience hangs like we see in this bug:
            // https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=190808 or
            // https://devdiv.visualstudio.com/DevDiv/_workitems?id=296981&_a=edit
            var telemetryService = (VisualStudioWorkspaceTelemetryService)_workspace.Services.GetRequiredService <IWorkspaceTelemetryService>();

            telemetryService.InitializeTelemetrySession(TelemetryService.DefaultSession);

            Logger.Log(FunctionId.Run_Environment,
                       KeyValueLogMessage.Create(m => m["Version"] = FileVersionInfo.GetVersionInfo(typeof(VisualStudioWorkspace).Assembly.Location).FileVersion));

            InitializeColors();

            // load some services that have to be loaded in UI thread
            LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget();

            _solutionEventMonitor = new SolutionEventMonitor(_workspace);

            TrackBulkFileOperations();

            var settingsEditorFactory = _componentModel.GetService <SettingsEditorFactory>();

            RegisterEditorFactory(settingsEditorFactory);
Beispiel #4
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            object componentModel = await GetServiceAsync(typeof(SComponentModel));

            var mcs = await this.GetServiceAsync(typeof(IMenuCommandService))
                      as OleMenuCommandService;

            Debug.Assert(mcs != null);

            if (null != mcs)
            {
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpNext, ContextJumpNext));
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpPrev, ContextJumpPrev));
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpUp, ContextJumpUp));
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpDown, ContextJumpDown));
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpNextSibling, ContextJumpNextSubling));
                mcs.AddCommand(
                    CreateMenuCommand((int)CommandIds.ContextJumpPrevSibling, ContextJumpPrevSubling));
            }

            // 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 this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            this.componentModel = componentModel as IComponentModel
                                  ?? throw new InvalidOperationException("Unable to access the component model.");

            this.exportProvider = this.componentModel.DefaultExportProvider;

            this.viewAccessor = this.exportProvider.GetExportedValue <IActiveViewAccessor>();
        }
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true);

            cancellationToken.ThrowIfCancellationRequested();
            Assumes.Present(_componentModel);

            // Fetch the session synchronously on the UI thread; if this doesn't happen before we try using this on
            // the background thread then we will experience hangs like we see in this bug:
            // https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=190808 or
            // https://devdiv.visualstudio.com/DevDiv/_workitems?id=296981&_a=edit
            var telemetrySession = TelemetryService.DefaultSession;

            WatsonReporter.InitializeFatalErrorHandlers(telemetrySession);

            // Ensure the options persisters are loaded since we have to fetch options from the shell
            _componentModel.GetExtensions <IOptionPersister>();

            _workspace = _componentModel.GetService <VisualStudioWorkspace>();
            _workspace.Services.GetService <IExperimentationService>();

            RoslynTelemetrySetup.Initialize(this, telemetrySession);

            InitializeColors();

            // load some services that have to be loaded in UI thread
            LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget();

            _solutionEventMonitor = new SolutionEventMonitor(_workspace);

            TrackBulkFileOperations();
        }