/// <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); } } } }
public override GenerateScriptsResponse GenerateScripts(Workspace workspace, string projPath, bool force) { try { IScriptGenerationResult result = _scriptGenerationAdapter.GenerateScripts(workspace, projPath, force); return(new GenerateScriptsResponse(result.Success, result.ErrorMessage)); } catch (Exception e) { string[] topStackTrace = e.StackTrace.Split(new[] { "\r\n" }, StringSplitOptions.None).Take(8).ToArray(); string message = e.Message + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, topStackTrace) + Environment.NewLine + "..."; return(new GenerateScriptsResponse(false, message)); } }