public override void Exec() { try { string propertyPath; string newValue; //Get PropertyPath values BatchPropertyUpdateForm frm = new BatchPropertyUpdateForm(); if (frm.ShowDialog() == DialogResult.OK) { propertyPath = frm.PropertyPath; newValue = frm.NewValue; } else { return; } UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer; foreach (UIHierarchyItem hi in ((System.Array)solExplorer.SelectedItems)) { ProjectItem pi = (ProjectItem)hi.Object; Window w = pi.Open(BIDSViewKinds.Designer); //opens the designer w.Activate(); IDesignerHost designer = w.Object as IDesignerHost; if (designer == null) { continue; } changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator)); Package package = win.PropertiesLinkComponent as Package; if (package == null) { continue; } SetPropertyValue(package, propertyPath, newValue); SSISHelpers.MarkPackageDirty(package); //for now always mark it as dirty //ApplicationObject.ActiveDocument.Save(null); //w.Close(vsSaveChanges.vsSaveChangesYes); //w.Close(vsSaveChanges.vsSaveChangesNo); //close the designer //w = pi.Open(BIDSViewKinds.Designer); //opens the designer w.Activate(); //that was the quick and easy way to get the expression highlighter up to date } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + " " + ex.StackTrace); } }
private void RecurseExecutablesAndCaptureGuids(IDTSSequence parentExecutable) { foreach (Variable v in ((DtsContainer)parentExecutable).Variables) { //don't replace system variables since they're not in the XML //don't replace parameters which show as variables since they have a different ID and you won't find the variable's ID in the XML to replace if (!v.SystemVariable && !SSISHelpers.IsParameterVariable(v)) { AddGuid(v.ID); } } foreach (Executable e in parentExecutable.Executables) { AddGuid(((DtsContainer)e).ID); if (e is IDTSSequence) { RecurseExecutablesAndCaptureGuids((IDTSSequence)e); } } }
public override void Exec() { try { UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer; UIHierarchyItem hierItem = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0)); ProjectItem pi = (ProjectItem)hierItem.Object; Window win = pi.Document.ActiveWindow; IDesignerHost designer = (IDesignerHost)pi.Document.ActiveWindow.Object; Package package = null; ConnectionManager conn = GetSelectedConnectionManager(designer, out package); BIDSHelper.SSIS.FixedWidthColumnsForm form = new BIDSHelper.SSIS.FixedWidthColumnsForm(); if (conn != null && conn.Properties["Format"].GetValue(conn).ToString() == "FixedWidth") { //hiding properties for ragged right form.dataGridView1.Height = form.dataGridView1.Height + 50 + 26; form.dataGridView1.Top -= 50; form.label1.Height -= 50; form.cboRaggedRightDelimiter.Visible = false; form.lblRaggedRight.Visible = false; } DialogResult dialogResult = form.ShowDialog(); if (dialogResult == DialogResult.OK) { #if KATMAI || DENALI || SQL2014 wrap.IDTSConnectionManagerFlatFile100 ff = conn.InnerObject as wrap.IDTSConnectionManagerFlatFile100; DtsConvert.GetExtendedInterface(conn); #else wrap.IDTSConnectionManagerFlatFile90 ff = conn.InnerObject as wrap.IDTSConnectionManagerFlatFile90; DtsConvert.ToConnectionManager90(conn); #endif while (ff.Columns.Count > 0) { ff.Columns.Remove(0); } List <string> listUsedNames = new List <string>(); //JCW - Added counter to identify the last column int columnCount = 1; foreach (DataGridViewRow row in form.dataGridView1.Rows) { string sName = row.Cells[0].Value.ToString().Trim(); string sOriginalName = sName; int i = 1; while (listUsedNames.Contains(sName)) //find a unique name for the column { sName = sOriginalName + (++i); } listUsedNames.Add(sName); #if KATMAI || DENALI || SQL2014 wrap.IDTSConnectionManagerFlatFileColumn100 col = ff.Columns.Add(); wrap.IDTSName100 name = col as wrap.IDTSName100; #else wrap.IDTSConnectionManagerFlatFileColumn90 col = ff.Columns.Add(); wrap.IDTSName90 name = col as wrap.IDTSName90; #endif name.Name = sName; col.MaximumWidth = int.Parse(row.Cells[1].Value.ToString()); col.DataType = Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_STR; if (columnCount == form.dataGridView1.Rows.Count && form.cboRaggedRightDelimiter.Text != "[None]") { col.ColumnWidth = 0; col.ColumnType = "Delimited"; col.ColumnDelimiter = DecodeDelimiter(form.cboRaggedRightDelimiter.Text); } else { col.ColumnWidth = int.Parse(row.Cells[1].Value.ToString()); col.ColumnType = "FixedWidth"; } columnCount++; } //mark package object as dirty IComponentChangeService changesvc = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); changesvc.OnComponentChanging(package, null); changesvc.OnComponentChanged(package, null, null, null); //marks the package designer as dirty SSISHelpers.MarkPackageDirty(package); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//they asked to pop up the Package Configurations dialog, so replace the Microsoft functionality so we can control the popup form void cmdEvent_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault) { if (Enabled) { try { if (this.ApplicationObject.ActiveWindow == null || this.ApplicationObject.ActiveWindow.ProjectItem == null) { return; } ProjectItem pi = this.ApplicationObject.ActiveWindow.ProjectItem; if (!pi.Name.ToLower().EndsWith(".dtsx")) { return; } IDesignerHost designer = this.ApplicationObject.ActiveWindow.Object as IDesignerHost; if (designer == null) { return; } EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator)); Package package = (Package)win.PropertiesLinkComponent; this.packageForFixButton = package; this.pathForPackageForFixButton = pi.get_FileNames(1); DtsConfigurationsForm form = new DtsConfigurationsForm(package); if (win.SelectedIndex == 0) { //control flow EditorWindow.EditorView view = win.SelectedView; System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; Control viewControl = (Control)view.GetType().InvokeMember("ViewControl", getflags, null, view, null); IWin32Window parentWin; #if DENALI || SQL2014 parentWin = viewControl; #else DdsDiagramHostControl diagram = viewControl.Controls["panel1"].Controls["ddsDiagramHostControl1"] as DdsDiagramHostControl; if (diagram == null || diagram.DDS == null) { return; } parentWin = diagram.DDS; #endif Button editSelectedButton = (Button)form.Controls["editSelectedConfiguration"]; Control packageConfigurationsGridControl1 = form.Controls["packageConfigurationsGridControl1"]; Button btnRelativePaths = new Button(); btnRelativePaths.Text = "Fix All Relative Paths"; btnRelativePaths.Width = 140; btnRelativePaths.Left = packageConfigurationsGridControl1.Left; btnRelativePaths.Top = editSelectedButton.Top; btnRelativePaths.Height = editSelectedButton.Height; btnRelativePaths.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; btnRelativePaths.Click += new EventHandler(btnRelativePaths_Click); form.Controls.Add(btnRelativePaths); if (DesignUtils.ShowDialog((Form)form, parentWin, (IServiceProvider)package.Site) == DialogResult.OK) { SSISHelpers.MarkPackageDirty(package); } CancelDefault = true; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } } }
public override void Exec() { if (MessageBox.Show("Are you sure you want to change any hardcoded paths pointing to files in the packages directory to relative paths?\r\n\r\nThis command impacts configurations and connection managers.", "BIDS Helper - Fix Relative Paths", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } try { this.ApplicationObject.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationFind); this.ApplicationObject.StatusBar.Text = "Fixing relative paths..."; EnvDTE.Project proj = GetSelectedProjectReference(); 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); this.ApplicationObject.ToolWindows.OutputWindow.Parent.SetFocus(); IOutputWindowFactory service = ((System.IServiceProvider)proj).GetService(typeof(IOutputWindowFactory)) as IOutputWindowFactory; IOutputWindow outputWindow = service.GetStandardOutputWindow(StandardOutputWindow.Deploy); outputWindow.Activate(); outputWindow.Clear(); outputWindow.ReportStatusMessage("BIDS Helper is fixing relative paths in all open packages...\r\n"); bool bFoundOpenPackage = false; StringBuilder sb = new StringBuilder(); string sPackageDirectory = string.Empty; foreach (ProjectItem item in proj.ProjectItems) { try { if (!item.get_IsOpen(BIDSViewKinds.Designer)) { continue; } } catch { continue; } if (!bFoundOpenPackage) { bFoundOpenPackage = true; sPackageDirectory = System.IO.Path.GetDirectoryName(item.get_FileNames(0)); outputWindow.ReportStatusMessage("The current working directory is:"); outputWindow.ReportStatusMessage(System.IO.Directory.GetCurrentDirectory()); outputWindow.ReportStatusMessage(string.Empty); outputWindow.ReportStatusMessage("The directory for the packages is:"); outputWindow.ReportStatusMessage(sPackageDirectory); outputWindow.ReportStatusMessage(string.Empty); if (string.Compare(sPackageDirectory, System.IO.Directory.GetCurrentDirectory(), true) != 0) { outputWindow.ReportStatusMessage("PROBLEM:"); outputWindow.ReportStatusMessage("Since the packages are not in the current working directory, no changes to configurations will be made. Please start Visual Studio by double clicking on the .sln file for the project, and make sure the .sln file is in the same directory as the packages."); return; } } Window w = item.Open(BIDSViewKinds.Designer); //opens the designer w.Activate(); IDesignerHost designer = w.Object as IDesignerHost; if (designer == null) { continue; } EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator)); Package package = win.PropertiesLinkComponent as Package; if (package == null) { continue; } outputWindow.ReportStatusMessage("Package " + item.Name); #if DENALI || SQL2014 Cud.Transaction trans = Cud.BeginTransaction(package); #endif bool bChanged = false; foreach (Microsoft.SqlServer.Dts.Runtime.Configuration config in package.Configurations) { if (config.ConfigurationType == DTSConfigurationType.ConfigFile) { if (string.Compare(System.IO.Path.GetDirectoryName(config.ConfigurationString), System.IO.Directory.GetCurrentDirectory(), true) == 0) { config.ConfigurationString = System.IO.Path.GetFileName(config.ConfigurationString); outputWindow.ReportStatusMessage(" Configuration " + config.Name + " changed to relative path"); bChanged = true; #if DENALI || SQL2014 trans.ChangeProperty(config, "ConfigurationString"); #endif } } } foreach (ConnectionManager conn in package.Connections) { if (string.IsNullOrEmpty(conn.GetExpression("ConnectionString")) && string.Compare(System.IO.Path.GetDirectoryName(conn.ConnectionString), System.IO.Directory.GetCurrentDirectory(), true) == 0) { conn.ConnectionString = System.IO.Path.GetFileName(conn.ConnectionString); outputWindow.ReportStatusMessage(" Connection " + conn.Name + " changed to relative path"); bChanged = true; #if DENALI || SQL2014 trans.ChangeProperty(conn, "ConnectionString"); #endif } } if (bChanged) { SSISHelpers.MarkPackageDirty(package); } else { outputWindow.ReportStatusMessage(" No changes"); } } if (!bFoundOpenPackage) { outputWindow.ReportStatusMessage("PROBLEM:"); outputWindow.ReportStatusMessage("No packages in this project were open."); return; } outputWindow.Activate(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } finally { this.ApplicationObject.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationFind); this.ApplicationObject.StatusBar.Text = string.Empty; } }