CanPublish() public static method

Returns true if project can be published using this wizard.
public static CanPublish ( ISolutionProject project ) : bool
project ISolutionProject The project to check.
return bool
        /// <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
        private static void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!(sender is OleMenuCommand menuCommand))
            {
                return;
            }

            IParsedDteProject selectedProject = SolutionHelper.CurrentSolution.SelectedProject?.ParsedProject;

            if (selectedProject == null || !PublishDialogWindow.CanPublish(selectedProject))
            {
                menuCommand.Visible = false;
            }
            else
            {
                menuCommand.Visible = true;
                menuCommand.Enabled = !ShellUtils.Default.IsBusy();
            }
        }
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            var menuCommand = sender as OleMenuCommand;

            if (menuCommand == null)
            {
                return;
            }

            var selectedProject = SolutionHelper.CurrentSolution.SelectedProject;

            if (selectedProject == null || !PublishDialogWindow.CanPublish(selectedProject))
            {
                menuCommand.Visible = false;
            }
            else
            {
                menuCommand.Visible = true;
                menuCommand.Enabled = !ShellUtils.IsBusy();
            }
        }
コード例 #4
0
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            var menuCommand = sender as OleMenuCommand;

            if (menuCommand == null)
            {
                return;
            }

            menuCommand.Visible = true;

            var startupProject = SolutionHelper.CurrentSolution.StartupProject;

            if (startupProject == null)
            {
                menuCommand.Enabled = false;
                menuCommand.Text    = Resources.PublishDialogGenericMenuHeader;
            }
            else
            {
                menuCommand.Enabled = PublishDialogWindow.CanPublish(startupProject) && !ShellUtils.IsBusy();
                menuCommand.Text    = String.Format(Resources.PublishDialogProjectMenuHeader, startupProject.Name);
            }
        }