Esempio n. 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);
                    }
                }
            }
        }