Пример #1
0
        /// <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>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (!ConfigProcessing.ConfigExistsForProject(proj))
                {
                    string configPath = ScriptGenAssemblyCache.GetForProj(proj)?.GetConfigFilepath(proj.FullName);
                    if (string.IsNullOrEmpty(configPath))
                    {
                        VsShellUtilities.ShowMessageBox(
                            ServiceProvider,
                            "Failed to find target configuration file path.  It is possible you need to update the Nuget Package.",
                            "Add Config Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        return;
                    }


                    if (!File.Exists(configPath))
                    {
                        ScriptGenAssemblyCache.GetForProj(proj).CreateNewConfigFile(configPath);
                    }
                    proj.ProjectItems.AddFromFile(configPath);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Determines whether this command is visible
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Enabled = false;
            button.Visible = false;

            var selProjs = VsHelper.GetSelectedCsharpProjects();

            if (!selProjs.Any())
            {
                return;
            }

            button.Visible = true;

            foreach (Project proj in selProjs)
            {
                if (!VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }
Пример #3
0
        /// <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>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var question = MessageBox.Show("Selecting this command will install a NuGet package that will enable this project for script generation. " +
                                           "\r\rDo you want to continue?", "Install NuGet Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (question == DialogResult.No)
            {
                return;
            }

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (!VsHelper.IsPackageInstalled(proj))
                {
                    try
                    {
                        IComponentModel     componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
                        IVsPackageInstaller installer      = componentModel.GetService <IVsPackageInstaller>();
                        installer.InstallPackage(null, proj, TypeRightPackage.NugetID, (string)null, false);
                    }
                    catch (Exception exception)
                    {
                        // Show a message box to prove we were here
                        VsShellUtilities.ShowMessageBox(
                            this.ServiceProvider,
                            "There was an error installing the package: \n\n" + exception.Message,
                            "Could not install package",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Before query for Adding a config file to the solution
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Visible = false;
            button.Enabled = false;

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                button.Visible = true;                  // At least one project is selected...
                if (!ConfigProcessing.ConfigExistsForProject(proj) && VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }
Пример #5
0
        /// <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>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace currentWorkspace = VsHelper.Current.GetCurrentWorkspace();

            foreach (EnvDTE.Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (ConfigProcessing.ConfigExistsForProject(proj))
                {
                    var result = Imports.ScriptGenAssemblyCache.GetForProj(proj).GenerateScripts(currentWorkspace, proj.FullName, true);
                    // Show a message box to prove we were here
                    if (!result.Success)
                    {
                        VsShellUtilities.ShowMessageBox(
                            ServiceProvider,
                            result.ErrorMessage,
                            "Script Generation Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }
Пример #6
0
        /// <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>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ProjectInformationDialog dialog = new ProjectInformationDialog(VsHelper.GetSelectedCsharpProjects().First());

            dialog.ShowModal();
        }