private void cmdButtonProperties_Click(CommandBarButton Ctrl, ref bool CancelDefault) { if (Enabled) { try { UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer; if (((System.Array)solExplorer.SelectedItems).Length != 1) return; Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt proj = GetSelectedProjectReference(); if (proj == null || proj.Kind != BIDSProjectKinds.SSIS) return; Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)proj).GetService(typeof(Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)); projectManager = (Microsoft.DataWarehouse.Project.DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null); if (!IsLegacyDeploymentMode(projectManager)) { //new project deployment mode CancelDefault = false; //let the Microsoft code fire return; } else { CancelDefault = true; //don't let the Microsoft code fire as I'm going to pop up the dialog myself } string sFileName = projectManager.GetSelectedProjectNode().FullPath + ".bidsHelper.user"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); if (System.IO.File.Exists(sFileName)) { doc.Load(sFileName); } ConfigurationManager = projectManager.ConfigurationManager; foreach (IProjectConfiguration config in projectManager.ConfigurationManager.Configurations) { DtsProjectExtendedConfigurationOptions newOptions = new DtsProjectExtendedConfigurationOptions((DataTransformationsProjectConfigurationOptions)config.Options); LoadFromBidsHelperConfiguration(doc, config.DisplayName, newOptions); if (!(config.Options is DtsProjectExtendedConfigurationOptions)) { config.Options = newOptions; //override the Options object in memory so the configuration properties dialog will show our dialog } } //pop up the configuration properties dialog IVsPropertyPageFrame frame = (IVsPropertyPageFrame)((System.IServiceProvider)proj).GetService(typeof(SVsPropertyPageFrame)); int hr = frame.ShowFrame(guidForCustomPropertyFrame); if (hr < 0) { frame.ReportError(hr); MessageBox.Show("Could not open BIDS Helper properties window customizations."); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); CancelDefault = false; //let the Microsoft code fire } } }
private void LoadFromBidsHelperConfiguration(System.Xml.XmlDocument doc, string sConfigurationName, DtsProjectExtendedConfigurationOptions newOptions) { System.Xml.XmlNode nodeOptions = doc.SelectSingleNode("/Configurations/Configuration/Name[text()='" + sConfigurationName.Replace("'", "'") + "']/../Options"); if (nodeOptions != null) { System.Xml.XmlNode node; node = nodeOptions.SelectSingleNode("DeploymentType"); try { if (node != null) newOptions.DeploymentType = (DtsProjectExtendedConfigurationOptions.DeploymentTypes)System.Enum.Parse(typeof(DtsProjectExtendedConfigurationOptions.DeploymentTypes), node.InnerText); } catch { } node = nodeOptions.SelectSingleNode("FilePath"); if (node != null) newOptions.FilePath = node.InnerText; node = nodeOptions.SelectSingleNode("DestinationServer"); if (node != null) newOptions.DestinationServer = node.InnerText; node = nodeOptions.SelectSingleNode("DestinationFolder"); if (node != null) newOptions.DestinationFolder = node.InnerText; } }
private void DeployProject(Project proj, IOutputWindow outputWindow, System.Array selectedItems, bool bCreateBat) { Microsoft.DataWarehouse.Interfaces.IConfigurationSettings settings = (Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)((System.IServiceProvider)proj).GetService(typeof(Microsoft.DataWarehouse.Interfaces.IConfigurationSettings)); DataWarehouseProjectManager projectManager = (DataWarehouseProjectManager)settings.GetType().InvokeMember("ProjectManager", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy, null, settings, null); StringBuilder sBatFileContents = new StringBuilder(); try { string sConfigFileName = ((Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)proj).FullName + ".bidsHelper.user"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); if (System.IO.File.Exists(sConfigFileName)) { doc.Load(sConfigFileName); } #if SQL2014 //refreshes the cached target version which is needed in GetPathToDtsExecutable below SSISHelpers.ProjectTargetVersion? projectTargetVersion = SSISHelpers.GetProjectTargetVersion(proj); #endif IProjectConfiguration config = projectManager.ConfigurationManager.CurrentConfiguration; DtsProjectExtendedConfigurationOptions newOptions = new DtsProjectExtendedConfigurationOptions(); LoadFromBidsHelperConfiguration(doc, config.DisplayName, newOptions); //print out header in output window if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.FilePathDestination) { if (string.IsNullOrEmpty(newOptions.FilePath)) { outputWindow.ReportStatusError(OutputWindowErrorSeverity.Error, "Deployment FilePath is not set. Right click on the project node and set the FilePath property."); return; } outputWindow.ReportStatusMessage("Deploying to file path " + newOptions.FilePath + "\r\n"); } else { if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.SsisPackageStoreMsdbDestination) { outputWindow.ReportStatusMessage("Deploying to SSIS Package Store MSDB on server " + newOptions.DestinationServer); } else if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.SsisPackageStoreFileSystemDestination) { outputWindow.ReportStatusMessage("Deploying to SSIS Package Store File System on server " + newOptions.DestinationServer); } else if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.SqlServerDestination) { outputWindow.ReportStatusMessage("Deploying to SQL Server MSDB on server: " + newOptions.DestinationServer); } if (!string.IsNullOrEmpty(newOptions.DestinationFolder)) outputWindow.ReportStatusMessage("Deploying to folder: " + newOptions.DestinationFolder); outputWindow.ReportStatusMessage(string.Empty); } System.Windows.Forms.Application.DoEvents(); //determine destination types and folders string sDestFolder = newOptions.DestinationFolder; sDestFolder = sDestFolder.Replace("/", "\\"); if (!string.IsNullOrEmpty(sDestFolder) && !sDestFolder.EndsWith("\\")) sDestFolder += "\\"; while (sDestFolder.StartsWith("\\")) sDestFolder = sDestFolder.Substring(1); string sDestType = "SQL"; if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.SsisPackageStoreFileSystemDestination) { sDestFolder = "File System\\" + sDestFolder; sDestType = "DTS"; } else if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.SsisPackageStoreMsdbDestination) { sDestFolder = "MSDB\\" + sDestFolder; sDestType = "DTS"; } else if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.FilePathDestination) { string sDestinationPath = newOptions.FilePath; if (!sDestinationPath.EndsWith("\\")) sDestinationPath += "\\"; if (!System.IO.Directory.Exists(sDestinationPath)) System.IO.Directory.CreateDirectory(sDestinationPath); sDestFolder = sDestinationPath; sBatFileContents.Append("mkdir \"").Append(sDestFolder).AppendLine("\""); } //setup Process object to call the dtutil EXE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = SSIS.PerformanceVisualization.PerformanceTab.GetPathToDtsExecutable("dtutil.exe", false); //makes the bat file less portable, but does workaround the problem if SSIS2005 and SSIS2008 are both installed... issue 21074 if (newOptions.DeploymentType != DtsProjectExtendedConfigurationOptions.DeploymentTypes.FilePathDestination) { //create the directories string sAccumulatingDir = ""; try { foreach (string dir in sDestFolder.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries)) { if (!(string.IsNullOrEmpty(sAccumulatingDir) && sDestType == "DTS")) { process.StartInfo.Arguments = string.Format("/FCreate {0};{1};\"{2}\" /SourceServer {3} ", sDestType, (sAccumulatingDir == "" ? "\\" : "\"" + sAccumulatingDir + "\""), dir, newOptions.DestinationServer); sBatFileContents.Append("\"").Append(process.StartInfo.FileName).Append("\" ").AppendLine(process.StartInfo.Arguments); process.Start(); process.WaitForExit(); } if (!string.IsNullOrEmpty(sAccumulatingDir)) sAccumulatingDir += "\\"; sAccumulatingDir += dir; } } catch { } } //loop through each package to deploy foreach (object selected in selectedItems) { ProjectItem pi; string sFileName; string sFilePath; if (selected is ProjectItem) { pi = (ProjectItem)selected; } else if (selected is UIHierarchyItem && ((UIHierarchyItem)selected).Object is ProjectItem) { pi = ((ProjectItem)((UIHierarchyItem)selected).Object); } else { continue; } sFileName = pi.Name; sFilePath = pi.get_FileNames(0); if (!sFileName.ToLower().EndsWith(".dtsx")) continue; if (pi.Document != null && !pi.Document.Saved) { pi.Save(""); } if (newOptions.DeploymentType == DtsProjectExtendedConfigurationOptions.DeploymentTypes.FilePathDestination) { string sDestinationPath = sDestFolder + sFileName; if (System.IO.File.Exists(sDestinationPath)) { System.IO.File.SetAttributes(sDestinationPath, System.IO.FileAttributes.Normal); } sBatFileContents.Append("xcopy \"").Append(sFilePath).Append("\" \"").Append(sDestFolder).AppendLine("\" /Y /R"); System.IO.File.Copy(sFilePath, sDestinationPath, true); outputWindow.ReportStatusMessage("Deployed " + sFileName); } else { process.Refresh(); process.StartInfo.Arguments = string.Format("/FILE \"{0}\" /DestServer {1} /COPY {2};\"{3}\" /Q", sFilePath, newOptions.DestinationServer, sDestType, sDestFolder + sFileName.Substring(0, sFileName.Length - ".dtsx".Length)); sBatFileContents.Append("\"").Append(process.StartInfo.FileName).Append("\" ").AppendLine(process.StartInfo.Arguments); process.Start(); string sError = process.StandardError.ReadToEnd(); string sStandardOutput = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (process.ExitCode > 0) { outputWindow.ReportStatusError(OutputWindowErrorSeverity.Error, "BIDS Helper encountered an error when deploying package " + sFileName + "!\r\n\"" + process.StartInfo.FileName + "\" " + process.StartInfo.Arguments + "\r\nexit code = " + process.ExitCode + "\r\n" + sStandardOutput); this.ApplicationObject.ToolWindows.OutputWindow.Parent.AutoHides = false; //pin the window open so you can see the problem return; } outputWindow.ReportStatusMessage("Deployed " + sFileName); System.Windows.Forms.Application.DoEvents(); } } outputWindow.ReportStatusMessage("BIDS Helper completed deploying packages successfully."); if (bCreateBat) { string sBatFilename = System.IO.Path.GetDirectoryName(((Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)proj).FullName); sBatFilename += "\\" + newOptions.OutputPath; if (!System.IO.Directory.Exists(sBatFilename)) System.IO.Directory.CreateDirectory(sBatFilename); sBatFilename += "\\bidsHelperDeployPackages.bat"; if (System.IO.File.Exists(sBatFilename)) { System.IO.File.SetAttributes(sBatFilename, System.IO.FileAttributes.Normal); } System.IO.File.WriteAllText(sBatFilename, sBatFileContents.ToString()); outputWindow.ReportStatusMessage("Deployment commands saved to: " + sBatFilename + "\r\n\r\n"); } } catch (Exception ex) { outputWindow.ReportStatusError(OutputWindowErrorSeverity.Error, "BIDS Helper encountered an error when deploying packages:\r\n" + ex.Message + "\r\n" + ex.StackTrace); this.ApplicationObject.ToolWindows.OutputWindow.Parent.AutoHides = false; //pin the window open so you can see the problem } }