private void CopyVariables(List <Variable> variables, bool move, DtsContainer targetContainer, Package package, System.Collections.ArrayList sourceVariableDesigners) { foreach (Variable sourceVar in variables) { if (targetContainer is IDTSPackagePath && sourceVar.GetPackagePath().StartsWith(((IDTSPackagePath)targetContainer).GetPackagePath() + ".Variables[")) { throw new VariableCopyException("You are attempting to copy the variable '" + sourceVar.QualifiedName + "' to the same scope it is already in.", null); } else if (sourceVar.SystemVariable) { throw new VariableCopyException(sourceVar.QualifiedName + " is a system variable and cannot be copied or moved.", null); } } foreach (Variable sourceVar in variables) { //Variable targetVar = targetContainer.Variables.Add(sourceVar.Name, sourceVar.ReadOnly, sourceVar.Namespace, sourceVar.Value); //this is the standard way to add a variable, but it doesn't interact well with the variables tool window Variable targetVar = (Variable)packageDesigner.GetType().InvokeMember("CreateVariable", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, packageDesigner, new object[] { targetContainer, sourceVar.Name, sourceVar.ReadOnly, sourceVar.Namespace, sourceVar.Value }); try { targetVar.Name = sourceVar.Name; } catch (Exception ex) { serviceProvider.DestroyComponent(targetVar); throw new VariableCopyException("Could not copy " + sourceVar.QualifiedName + " to scope \"" + targetContainer.Name + "\" because another variable with that name already exists.", ex); } //targetVar.DataType is read only targetVar.Description = sourceVar.Description; targetVar.EvaluateAsExpression = sourceVar.EvaluateAsExpression; targetVar.Expression = sourceVar.Expression; targetVar.RaiseChangedEvent = sourceVar.RaiseChangedEvent; if (move) { DtsContainer sourceContainer = FindObjectForVariablePackagePath(package, sourceVar.GetPackagePath()); changesvc.OnComponentChanging(sourceContainer, null); changesvc.OnComponentChanged(sourceContainer, null, null, null); //marks the package designer as dirty } } if (move) { #if DENALI || SQL2014 //terrible workaround to get the exact right parameter type for the DeleteVariables method in Denali. Guess calling InvokeMember against a function with a parameter of a generic type is tricky System.Collections.IList listParam = ((System.Collections.IList)System.Type.GetType("System.Collections.Generic.List`1[[" + ExpressionHighlighterPlugin.GetPrivateType(variablesToolWindowControl.GetType(), "Microsoft.DataTransformationServices.Design.VariableDesigner").AssemblyQualifiedName + "]]").GetConstructor(new Type[] { }).Invoke(new object[] { })); foreach (object o in sourceVariableDesigners) { listParam.Add(o); } variablesToolWindowControl.GetType().GetMethod("DeleteVariables", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance).Invoke(variablesToolWindowControl, new object[] { listParam }); #else variablesToolWindowControl.GetType().InvokeMember("DeleteVariables", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, new object[] { sourceVariableDesigners }); #endif } changesvc.OnComponentChanging(targetContainer, null); changesvc.OnComponentChanged(targetContainer, null, null, null); //marks the package designer as dirty SSISHelpers.MarkPackageDirty(package); ValidatePackage(package); }
public static PackageConfigurationSetting[] GetPackageConfigurationSettings(Microsoft.SqlServer.Dts.Runtime.Configuration c, Package p, string sVisualStudioRelativePath, bool bOfflineMode) { List <PackageConfigurationSetting> list = new List <PackageConfigurationSetting>(); if (c.ConfigurationType == DTSConfigurationType.ConfigFile || c.ConfigurationType == DTSConfigurationType.IConfigFile) { string sConfigurationString = c.ConfigurationString; if (c.ConfigurationType == DTSConfigurationType.IConfigFile) { sConfigurationString = System.Environment.GetEnvironmentVariable(c.ConfigurationString); } XmlDocument dom = new XmlDocument(); if (sConfigurationString != null) { if (sConfigurationString.Contains("\\")) { dom.Load(sConfigurationString); } else { //if it's a relative file path, then try this directory first, and if it's not there, then try the path relative to the dtsx package if (System.IO.File.Exists(sVisualStudioRelativePath + sConfigurationString)) { dom.Load(sVisualStudioRelativePath + sConfigurationString); } else { dom.Load(sConfigurationString); } } foreach (XmlNode node in dom.GetElementsByTagName("Configuration")) { list.Add(new PackageConfigurationSetting(node.Attributes["Path"].Value, node.SelectSingleNode("ConfiguredValue").InnerText)); } } } else if (c.ConfigurationType == DTSConfigurationType.SqlServer && !bOfflineMode) //not when in offline mode { string sConnectionManagerName; string sTableName; string sFilter; Microsoft.DataTransformationServices.Design.DesignUtils.ParseSqlServerConfigurationString(c.ConfigurationString, out sConnectionManagerName, out sTableName, out sFilter); ConnectionManager cm = p.Connections[sConnectionManagerName]; if (cm.OfflineMode) { return(list.ToArray()); } ISessionProperties o = cm.AcquireConnection(null) as ISessionProperties; try { IDBCreateCommand command = (IDBCreateCommand)o; ICommandText ppCommand; Guid IID_ICommandText = new Guid(0xc733a27, 0x2a1c, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); command.CreateCommand(IntPtr.Zero, ref IID_ICommandText, out ppCommand); Guid DBGUID_DEFAULT = new Guid(0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); ppCommand.SetCommandText(ref DBGUID_DEFAULT, "select ConfiguredValue, PackagePath from " + sTableName + " Where ConfigurationFilter = '" + sFilter.Replace("'", "''") + "'"); IntPtr PtrZero = new IntPtr(0); Guid IID_IRowset = new Guid(0xc733a7c, 0x2a1c, 0x11ce, 0xad, 0xe5, 0, 170, 0, 0x44, 0x77, 0x3d); tagDBPARAMS dbParams = null; int recordsAffected = 0; object executeResult = null; int result = ppCommand.Execute(PtrZero, ref IID_IRowset, dbParams, out recordsAffected, out executeResult); System.Reflection.BindingFlags getmethodflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; System.Reflection.BindingFlags getstaticflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static; Type chapterHandleType = ExpressionHighlighterPlugin.GetPrivateType(typeof(System.Data.OleDb.OleDbCommand), "System.Data.OleDb.ChapterHandle"); object chapterHandle = chapterHandleType.InvokeMember("DB_NULL_HCHAPTER", getstaticflags, null, null, null); System.Data.OleDb.OleDbDataReader dataReader = null; dataReader = (System.Data.OleDb.OleDbDataReader) typeof(System.Data.OleDb.OleDbDataReader).GetConstructors(getmethodflags)[0].Invoke(new object[] { null, null, 0, System.Data.CommandBehavior.SingleResult }); IntPtr intPtrRecordsAffected = new IntPtr(-1); dataReader.GetType().InvokeMember("InitializeIRowset", getmethodflags, null, dataReader, new object[] { executeResult, chapterHandle, intPtrRecordsAffected }); dataReader.GetType().InvokeMember("BuildMetaInfo", getmethodflags, null, dataReader, new object[] { }); dataReader.GetType().InvokeMember("HasRowsRead", getmethodflags, null, dataReader, new object[] { }); executeResult = null; while (dataReader.Read()) { list.Add(new PackageConfigurationSetting(dataReader["PackagePath"].ToString(), dataReader["ConfiguredValue"].ToString())); } dataReader.Close(); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(o); } } else if (c.ConfigurationType == DTSConfigurationType.EnvVariable) { list.Add(new PackageConfigurationSetting(c.PackagePath, System.Environment.GetEnvironmentVariable(c.ConfigurationString))); } else if (c.ConfigurationType == DTSConfigurationType.ParentVariable || c.ConfigurationType == DTSConfigurationType.IParentVariable) { list.Add(new PackageConfigurationSetting(c.PackagePath, "")); //can't know value at design time } else if (c.ConfigurationType == DTSConfigurationType.RegEntry) { list.Add(new PackageConfigurationSetting(c.PackagePath, (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\" + c.ConfigurationString, "Value", ""))); } else if (c.ConfigurationType == DTSConfigurationType.IRegEntry) { list.Add(new PackageConfigurationSetting(c.PackagePath, (string)Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\" + System.Environment.GetEnvironmentVariable(c.ConfigurationString), "Value", ""))); } return(list.ToArray()); }
private bool IsContextMenuLocationValid(out string DataFlowGUID) { DataFlowGUID = null; try { if (this.ApplicationObject.ActiveWindow == null || this.ApplicationObject.ActiveWindow.ProjectItem == null) { return(false); } ProjectItem pi = this.ApplicationObject.ActiveWindow.ProjectItem; if (!pi.Name.ToLower().EndsWith(".dtsx")) { return(false); } if (pi.ContainingProject == null || pi.ContainingProject.Kind != BIDSProjectKinds.SSIS) { return(false); //if the dtsx isn't in an SSIS project, or if you're editing the package standalone (not as a part of a project) } IDesignerHost designer = this.ApplicationObject.ActiveWindow.Object as IDesignerHost; if (designer == null) { return(false); } EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator)); Package package = (Package)win.PropertiesLinkComponent; if (win.SelectedIndex == (int)SSISHelpers.SsisDesignerTabIndex.ControlFlow) { //control flow EditorWindow.EditorView view = win.SelectedView; Control viewControl = (Control)view.GetType().InvokeMember("ViewControl", getflags, null, view, null); #if DENALI || SQL2014 Microsoft.SqlServer.IntegrationServices.Designer.Model.ControlFlowGraphModelElement ctlFlowModel = (Microsoft.SqlServer.IntegrationServices.Designer.Model.ControlFlowGraphModelElement)viewControl.GetType().InvokeMember("GraphModel", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty, null, viewControl, null); if (ctlFlowModel == null) { return(false); } Microsoft.SqlServer.IntegrationServices.Designer.Model.TaskModelElement taskModelEl = ctlFlowModel.SelectedItems[0] as Microsoft.SqlServer.IntegrationServices.Designer.Model.TaskModelElement; if (taskModelEl == null) { return(false); } TaskHost task = taskModelEl.TaskHost; if (task == null) { return(false); } if (!(task.InnerObject is MainPipe)) { return(false); } DataFlowGUID = taskModelEl.LogicalID; return(true); #else DdsDiagramHostControl diagram = viewControl.Controls["panel1"].Controls["ddsDiagramHostControl1"] as DdsDiagramHostControl; if (diagram == null || diagram.DDS == null) { return(false); } if (diagram.DDS.Selection.Count != 1) { return(false); } MSDDS.IDdsDiagramObject o = diagram.DDS.Selection.Item(0); if (o.Type != DdsLayoutObjectType.dlotShape) { return(false); } MSDDS.IDdsExtendedProperty prop = o.IDdsExtendedProperties.Item("LogicalObject"); if (prop == null) { return(false); } string sObjectGuid = prop.Value.ToString(); Executable exe = ExpressionHighlighterPlugin.FindExecutable(package, sObjectGuid); if (exe == null || !(exe is TaskHost)) { return(false); } TaskHost task = (TaskHost)exe; if (!(task.InnerObject is MainPipe)) { return(false); } DataFlowGUID = task.ID; return(true); #endif } else if (win.SelectedIndex == (int)SSISHelpers.SsisDesignerTabIndex.DataFlow) { //data flow EditorWindow.EditorView view = win.SelectedView; Control viewControl = (Control)view.GetType().InvokeMember("ViewControl", getflags, null, view, null); Microsoft.DataTransformationServices.Design.Controls.PipelineComboBox pipelineComboBox = (Microsoft.DataTransformationServices.Design.Controls.PipelineComboBox)(viewControl.Controls["panel1"].Controls["pipelineComboBox"]); foreach (Control c in viewControl.Controls["panel2"].Controls["pipelineDetailsControl"].Controls) { if (!c.Visible) { continue; } #if DENALI || SQL2014 if (c.GetType().FullName != "Microsoft.DataTransformationServices.Design.PipelineTaskView") { continue; } object pipelineDesigner = c.GetType().InvokeMember("PipelineTaskDesigner", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty, null, c, null); if (pipelineDesigner == null) { continue; } Microsoft.SqlServer.IntegrationServices.Designer.Model.DataFlowGraphModelElement dataFlowModel = (Microsoft.SqlServer.IntegrationServices.Designer.Model.DataFlowGraphModelElement)pipelineDesigner.GetType().InvokeMember("DataFlowGraphModel", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty, null, pipelineDesigner, null); if (dataFlowModel == null) { continue; } DataFlowGUID = dataFlowModel.PipelineTask.ID; #else DdsDiagramHostControl diagram = c as DdsDiagramHostControl; if (diagram == null || diagram.DDS == null) { return(false); } if (diagram.DDS.Selection.Count != 0) { return(false); } TaskHost task = (TaskHost)diagram.ComponentDiagram.RootComponent; DataFlowGUID = task.ID; #endif return(true); } } } catch { } return(false); }