Example #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();
            Workspace currentWorkspace = VsHelper.Current.GetCurrentWorkspace();

            foreach (EnvDTE.Project proj in VsHelper.GetSelectedItemsOfType <EnvDTE.Project>())
            {
                if (ConfigProcessing.IsGenEnabledForProject(proj))
                {
                    IScriptGenEngineProvider <Workspace> provider = Imports.ScriptGenAssemblyCache.GetForProj(proj).EngineProvider;
                    IScriptGenEngine        engine = provider.GetEngine(currentWorkspace, proj.FullName);
                    IScriptGenerationResult result = engine.GenerateScripts();
                    // Show a message box to prove we were here
                    if (!result.Sucess)
                    {
                        VsShellUtilities.ShowMessageBox(
                            this.ServiceProvider,
                            result.ErrorMessage,
                            "Script Generation Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }
        /// <summary>
        /// Event handler for the build event, which will silently generate the typescript files
        /// </summary>
        /// <param name="Scope">the build scope</param>
        /// <param name="Action">The build action</param>
        private void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace             workspace   = VsHelper.Current.GetCurrentWorkspace();
            List <EnvDTE.Project> enabledProj = ConfigProcessing.GetEnabledProjectsForSolution();

            if (enabledProj.Count > 0)
            {
                foreach (EnvDTE.Project proj in enabledProj)
                {
                    BuildHelper.StartBuild(proj.FullName);
                    IScriptGenEngineProvider <Workspace> provider = Imports.ScriptGenAssemblyCache.GetForProj(proj).EngineProvider;
                    IScriptGenEngine engine = provider.GetEngine(workspace, proj.FullName);
                    try
                    {
                        engine.GenerateScripts();
                    }
                    catch (Exception e)
                    {
                        VsShellUtilities.ShowMessageBox(
                            this,
                            "There was an error generating script.  Scripts will be generated by MSBuild. \n\n" + e.Message,
                            "Script generation failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        BuildHelper.EndBuild(proj.FullName);
                    }
                }
            }
        }
        /// <summary>
        /// Occurs when the build is finished - removes the global property
        /// </summary>
        /// <param name="Scope"></param>
        /// <param name="Action"></param>
        private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            List <EnvDTE.Project> enabledProj = ConfigProcessing.GetEnabledProjectsForSolution();

            foreach (EnvDTE.Project project in enabledProj)
            {
                BuildHelper.EndBuild(project.FullName);
            }
        }
 /// <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)
 {
     foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
     {
         if (!VsHelper.IsSolutionItemsFolder(proj) &&
             !ConfigProcessing.ConfigExistsForProject(proj))
         {
             ConfigProcessing.CreateForProject(proj);
         }
     }
 }
        /// <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)
        {
            OleMenuCommand button  = (OleMenuCommand)sender;
            bool           hasProj = VsHelper.GetSelectedItemsOfType <Project>().Any();   // Check if the solution is selectd

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

            foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
            {
                button.Visible = true;                  // At least one project is selected...
                if (!ConfigProcessing.IsGenEnabledForProject(proj) && VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }
        /// <summary>
        /// Event handler for the build event, which will silently generate the typescript files
        /// </summary>
        /// <param name="Scope">the build scope</param>
        /// <param name="Action">The build action</param>
        private void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace             workspace   = VsHelper.Current.GetCurrentWorkspace();
            List <EnvDTE.Project> enabledProj = ConfigProcessing.GetEnabledProjectsForSolution();

            if (enabledProj.Count > 0)
            {
                foreach (EnvDTE.Project proj in enabledProj)
                {
                    BuildHelper.StartBuild(proj.FullName);
                    try
                    {
                        ScriptGenAssemblyCache.GetForProj(proj).GenerateScripts(workspace, proj.FullName, false);
                    }
                    catch (Exception e)
                    {
                        VsHelper.SetStatusBar("There was an error generating scripts.  Scripts will be generated by MSBuild: " + e.Message);
                        BuildHelper.EndBuild(proj.FullName);
                    }
                }
            }
        }