/// <summary>
        /// Registers the UI factory.
        /// </summary>
        /// <typeparam name="T">
        /// The type of the factory being registered.
        /// The <see cref="Type.GUID"/> of this type is used as the identifier for the new factory.
        /// </typeparam>
        /// <param name="registerUIFactories">
        /// The instance of <see cref="IVsRegisterUIFactories"/> used to register the new factory.
        /// </param>
        /// <param name="factory">The factory object to register.</param>
        /// <param name="token">
        /// The <see cref="CancellationToken"/> that can cancel switching to the main thread.
        /// </param>
        /// <returns>Returns <see cref="VSConstants.S_OK"/>.</returns>
        /// <seealso cref="IVsRegisterUIFactories.RegisterUIFactory"/>
        public static async Task RegisterUIFactoryAsync <T>(
            this IVsRegisterUIFactories registerUIFactories,
            T factory,
            CancellationToken token) where T : IVsUIFactory
        {
            await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            Guid guid = typeof(T).GUID;

            ErrorHandler.ThrowOnFailure(registerUIFactories.RegisterUIFactory(ref guid, factory));
        }
Ejemplo n.º 2
0
        public static void CreateAndRegister(IServiceProvider serviceProvider)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();

            IVsUIFactory factory = new UIFactory(serviceProvider);

            IVsRegisterUIFactories registry = (IVsRegisterUIFactories)serviceProvider.GetService(typeof(SVsUIFactory));

            Assumes.Present(registry);

            ErrorHandler.ThrowOnFailure(registry.RegisterUIFactory(GuidList.UiFactory, factory));
        }
        /// <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 token, IProgress <ServiceProgressData> progress)
        {
            try
            {
                _componentModel = await GetServiceAsync <SComponentModel, IComponentModel>();

                CredentialsStore = _componentModel.GetService <ICredentialsStore>();
                ExportProvider mefExportProvider = _componentModel.DefaultExportProvider;
                _shellUtilsLazy      = mefExportProvider.GetExport <IShellUtils>();
                _gcpOutputWindowLazy = mefExportProvider.GetExport <IGcpOutputWindow>();
                _processService      = mefExportProvider.GetExport <IProcessService>();
                _statusbarService    = mefExportProvider.GetExport <IStatusbarService>();
                _userPromptService   = mefExportProvider.GetExport <IUserPromptService>();
                _dataSourceFactory   = mefExportProvider.GetExport <IDataSourceFactory>();

                Dte = await GetServiceAsync <SDTE, DTE2>();

                // Remember the package.
                Instance = this;

                // Activity log utils, to aid in debugging.
                IVsActivityLog activityLog = await GetServiceAsync <SVsActivityLog, IVsActivityLog>();

                await activityLog.LogInfoAsync("Starting Google Cloud Tools.");

                // Register the command handlers.
                await Task.WhenAll(
                    CloudExplorerCommand.InitializeAsync(this, token),
                    ManageAccountsCommand.InitializeAsync(this, token),
                    PublishProjectMainMenuCommand.InitializeAsync(this, token),
                    PublishProjectContextMenuCommand.InitializeAsync(this, token),
                    LogsViewerToolWindowCommand.InitializeAsync(this, token),
                    GenerateConfigurationContextMenuCommand.InitializeAsync(this, token),
                    ErrorReportingToolWindowCommand.InitializeAsync(this, token));


                // Update the installation status of the package.
                await CheckInstallationStatusAsync();

                // Ensure the commands UI state is updated when the GCP project changes.
                CredentialsStore.CurrentProjectIdChanged += (o, e) => ShellUtils.InvalidateCommandsState();

                // With this setting we allow more concurrent connections from each HttpClient instance created
                // in the process. This will allow all GCP API services to have more concurrent connections with
                // GCP servers. The first benefit of this is that we can upload more concurrent files to GCS.
                ServicePointManager.DefaultConnectionLimit = MaximumConcurrentConnections;

                IVsRegisterUIFactories registerUIFactories =
                    await GetServiceAsync <SVsUIFactory, IVsRegisterUIFactories>();

                var controlFactory = _componentModel.GetService <GcpMenuBarControlFactory>();
                await registerUIFactories.RegisterUIFactoryAsync(controlFactory, token);
            }
            catch (Exception e)
            {
                IVsActivityLog activityLog = await GetServiceAsync <SVsActivityLog, IVsActivityLog>();

                await activityLog.LogErrorAsync(e.Message);

                await activityLog.LogErrorAsync(e.StackTrace);
            }
        }