/// <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 OnExportSSOCommand(object sender, EventArgs e) { IVsHierarchy hierarchy = null; uint itemid = VSConstants.VSITEMID_NIL; if (!ImportSSO.IsSingleProjectItemSelection(out hierarchy, out itemid)) { return; } var vsProject = (IVsProject)hierarchy; // get the name of the item string itemFullPath = null; if (ErrorHandler.Failed(vsProject.GetMkDocument(itemid, out itemFullPath))) { return; } // Save the project file var solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution)); int hr = solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, hierarchy, 0); if (hr < 0) { throw new COMException(string.Format("Failed to add project item", itemFullPath, ImportSSO.GetErrorInfo()), hr); } var selectedProjectItem = ImportSSO.GetProjectItemFromHierarchy(hierarchy, itemid); if (selectedProjectItem != null) { string itemFolder = Path.GetDirectoryName(itemFullPath); string itemFilename = Path.GetFileNameWithoutExtension(itemFullPath); string itemExtension = Path.GetExtension(itemFullPath); var dialog = new Dialogs.ExportSSO(itemFilename, itemFullPath); dialog.ShowDialog(); if (!dialog.OK) { return; } // Export the SSO application ExportSSOApplication(itemFilename, itemFullPath); } }
private void menuCommand_BeforeQueryStatus(object sender, EventArgs e) { // get the menu that fired the event var menuCommand = sender as OleMenuCommand; if (menuCommand != null) { // start by assuming that the menu will not be shown menuCommand.Visible = false; menuCommand.Enabled = false; IVsHierarchy hierarchy = null; uint itemid = VSConstants.VSITEMID_NIL; if (!ImportSSO.IsSingleProjectItemSelection(out hierarchy, out itemid)) { return; } // Get the file path string itemFullPath = null; ((IVsProject)hierarchy).GetMkDocument(itemid, out itemFullPath); var transformFileInfo = new FileInfo(itemFullPath); // then check if the file is a SSO file // if not leave the menu hidden if (transformFileInfo.Extension == ".sso") { menuCommand.Visible = true; menuCommand.Enabled = true; return; } if (transformFileInfo.Extension != ".xml") { return; } if (!ImportSSO.IsSSOXmlFile(transformFileInfo)) { return; } menuCommand.Visible = true; menuCommand.Enabled = true; } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); _DTE = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); _DTE2 = (EnvDTE80.DTE2)GetService(typeof(EnvDTE.DTE)); var ow = _DTE2.ToolWindows.OutputWindow; Assembly asm = Assembly.GetAssembly(typeof(VSPackageBizTalkBuildAndDeploy)); string asmLocation = asm.Location; AssemblyName asmName = asm.GetName(); string addinname = string.Format("{0} - Version {1}", asmName.Name, asmName.Version); var owp = GetBizTalkBuildAndDeployPane(ow); owp.OutputString(string.Format("Loaded from {0}", asmLocation)); owp.OutputString(Environment.NewLine); owp.OutputString(string.Format("Hello BizTalk World! from {0}", addinname)); owp.OutputString(Environment.NewLine); owp.OutputString(Environment.NewLine); Helpers.BizTalk.BizTalkHelper.Package = this; CreateBizTalkBuildAndDeployScript.Initialize(this, _DTE2, owp); ExecuteBizTalkBuildAndDeployScript.Initialize(this, _DTE2, owp); ImportSSO.Initialize(this, owp); ExportSSO.Initialize(this, owp); try { Helpers.Options.OptionPageGrid page = (Helpers.Options.OptionPageGrid)GetDialogPage(typeof(Helpers.Options.OptionPageGrid)); if (string.IsNullOrWhiteSpace(page.TasksPath)) { FileInfo fi = new FileInfo(asmLocation); page.TasksPath = fi.DirectoryName + @"\MSBuild"; } } catch { } owp.OutputString(Environment.NewLine); }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> /// <param name="owp">OutputWindowPane</param> public static void Initialize(Package package, OutputWindowPane owp) { Instance = new ImportSSO(package); Instance._owp = owp; }