/// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token"></param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new OleMenuCommand(OnDeployCommand, menuCommandID);
                menuItem.BeforeQueryStatus += OnBeforeQueryStatus;
                commandService.AddCommand(menuItem);
            }

            // <summary>
            // This function is the callback used to execute the command when the menu item is clicked.
            // See the constructor to see how the menu item is associated with this function using
            // OleMenuCommandService service and MenuCommand class.
            // </summary>
            // <param name="sender">Event sender.</param>
            // <param name="e">Event args.</param>
            async void OnDeployCommand(object sender, EventArgs e)
            {
                await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

                IParsedDteProject project = SolutionHelper.CurrentSolution.StartupProject.ParsedProject;

                PublishDialogWindow.PromptUser(project);
            }

            void OnBeforeQueryStatus(object sender, EventArgs e)
            {
#pragma warning disable VSTHRD109 // Switch instead of assert in async methods
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD109 // Switch instead of assert in async methods
                if (!(sender is OleMenuCommand menuCommand))
                {
                    return;
                }

                menuCommand.Visible = true;

                IParsedDteProject startupProject = SolutionHelper.CurrentSolution.StartupProject?.ParsedProject;
                if (startupProject == null)
                {
                    menuCommand.Enabled = false;
                    menuCommand.Text    = Resources.PublishDialogGenericMenuHeader;
                }
                else
                {
                    menuCommand.Enabled =
                        PublishDialogWindow.CanPublish(startupProject) && !ShellUtils.Default.IsBusy();
                    menuCommand.Text = string.Format(Resources.PublishDialogProjectMenuHeader, startupProject.Name);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token"></param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is IMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new OleMenuCommand(OnGenerateConfiguration, menuCommandID);
                menuItem.BeforeQueryStatus += OnBeforeQueryStatus;
                commandService.AddCommand(menuItem);
            }
        }
예제 #3
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The token to cancel adding the command.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is IMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuItem = new OleMenuCommand(
                    (sender, e) => package.JoinableTaskFactory.Run(ToolWindowCommandUtils.AddToolWindowAsync <LogsViewerToolWindow>),
                    MenuCommandID);
                menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId;
                commandService.AddCommand(menuItem);
            }
        }
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The cancellation token.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (await package.GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService commandService)
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

                var menuCommandID = new CommandID(CommandSet, CommandId);
                var menuItem      = new MenuCommand(ShowToolWindow, menuCommandID);
                commandService.AddCommand(menuItem);
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The cancellation token.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            object menuCommandService = await package.GetServiceAsync(typeof(IMenuCommandService));

            await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            if (menuCommandService is OleMenuCommandService commandService)
            {
                var menuCommandID = new CommandID(s_commandSet, CommandId);
                var menuItem      = new MenuCommand(ShowToolWindow, menuCommandID);
                commandService.AddCommand(menuItem);
            }

            // <summary>
            // Shows the tool window when the menu item is clicked.
            // </summary>
            // <param name="sender">The event sender.</param>
            // <param name="e">The event args.</param>
            void ShowToolWindow(object sender, EventArgs e)
            {
                EventsReporterWrapper.EnsureAnalyticsOptIn();

                ErrorHandlerUtils.HandleExceptionsAsync(ShowToolWindowAsync);
            }

            async Task ShowToolWindowAsync()
            {
                // Get the instance number 0 of this tool window. This window is single instance so this instance
                // is actually the only one.
                // The last flag is set to true so that if the tool window does not exists it will be created.
                var window = package.FindToolWindow <CloudExplorerToolWindow>(true);

                if (window?.Frame == null)
                {
                    throw new NotSupportedException("Cannot create tool window");
                }

                await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                var windowFrame = (IVsWindowFrame)window.Frame;

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
예제 #6
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="token">The token to cancel adding the command.</param>
        public static async Task InitializeAsync(IGoogleCloudExtensionPackage package, CancellationToken token)
        {
            package.ThrowIfNull(nameof(package));

            IMenuCommandService commandService =
                await package.GetServiceAsync <IMenuCommandService, IMenuCommandService>();

            await package.JoinableTaskFactory.SwitchToMainThreadAsync(token);

            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem      = new OleMenuCommand(
                async(sender, e) =>
            {
                await ToolWindowCommandUtils.ShowToolWindowAsync <ErrorReportingToolWindow>();
                EventsReporterWrapper.ReportEvent(ErrorsViewerOpenEvent.Create());
            },
                menuCommandID);

            menuItem.BeforeQueryStatus += ToolWindowCommandUtils.EnableMenuItemOnValidProjectId;
            commandService.AddCommand(menuItem);
        }