private void expressionListWindow_RefreshExpressions(object sender, EventArgs e) { expressionListWindow.ClearResults(); if (win == null) { return; } try { Package package = GetCurrentPackage(); if (package == null) { return; } expressionListWindow.StartProgressBar(); // Set target version on PackageHelper to ensure any ComponentInfos is for the correct info. PackageHelper.SetTargetServerVersion(package); IDTSSequence sequence = (IDTSSequence)package; processPackage.RunWorkerAsync(sequence); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SetPackageAsDirty(IDTSSequence container, string expression, object objectChanged) { try { if (!string.IsNullOrEmpty(expression)) { shouldSkipExpressionHighlighting = true; //this flag is used by the expression highlighter to skip re-highlighting if all that's changed is the string of an existing expression... if one has been removed, then re-highlight } PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(objectChanged); System.ComponentModel.PropertyDescriptor expressionsProperty = properties.Find("Expressions", false); // Mark package object as dirty IComponentChangeService changeService = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService)); if (objectChanged == null) { changeService.OnComponentChanging(container, null); changeService.OnComponentChanged(container, null, null, null); //marks the package designer as dirty } else { changeService.OnComponentChanging(objectChanged, expressionsProperty); changeService.OnComponentChanged(objectChanged, expressionsProperty, null, null); //marks the package designer as dirty } if (container is Package) { SSISHelpers.MarkPackageDirty((Package)container); } } finally { shouldSkipExpressionHighlighting = false; } }
private void expressionListWindow_RefreshExpressions(object sender, EventArgs e) { expressionListWindow.ClearResults(); if (win == null) { return; } try { Package package = GetCurrentPackage(); if (package == null) { return; } expressionListWindow.StartProgressBar(); IDTSSequence sequence = (IDTSSequence)package; processPackage.RunWorkerAsync(sequence); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private string[] RecurseContainersAndGetVariableValidationErrors(IDTSSequence parentExecutable) { List <string> listOtherErrors = new List <string>(); listOtherErrors.AddRange(ScanDtsObjectVariablesForErrors((DtsContainer)parentExecutable)); if (parentExecutable is EventsProvider) { foreach (DtsEventHandler eh in (parentExecutable as EventsProvider).EventHandlers) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors(eh)); } } foreach (Executable e in parentExecutable.Executables) { if (e is IDTSSequence) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors((IDTSSequence)e)); } else { if (e is DtsContainer) { listOtherErrors.AddRange(ScanDtsObjectVariablesForErrors((DtsContainer)e)); } if (e is EventsProvider) { foreach (DtsEventHandler eh in (e as EventsProvider).EventHandlers) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors(eh)); } } } } return(listOtherErrors.ToArray()); }
private void RecurseComponentsAndBuildPerformanceObjects(IDTSSequence container, DtsObjectPerformance performance, int indent) { foreach (Executable exe in container.Executables) { if (exe is DtsContainer) { DtsContainer child = (DtsContainer)exe; DtsObjectPerformance childPerformance; if (exe is TaskHost) { TaskHost task = (TaskHost)exe; MainPipe pipeline = task.InnerObject as MainPipe; if (pipeline != null) { childPerformance = new DtsPipelinePerformance(child.ID, child.Name, pipeline, indent + 1); } else { childPerformance = new DtsObjectPerformance(child.ID, child.Name, child.GetType(), indent + 1); } listComponentsPerformanceLookup.Add(child.ID, childPerformance); } else { childPerformance = new DtsObjectPerformance(child.ID, child.Name, child.GetType(), indent + 1); listComponentsPerformanceLookup.Add(child.ID, childPerformance); } performance.Children.Add(childPerformance); if (exe is IDTSSequence) { RecurseComponentsAndBuildPerformanceObjects((IDTSSequence)exe, childPerformance, indent + 1); } } } }
public static List <TaskHost> GetControlFlowObjects <T>(DtsContainer container) { List <TaskHost> returnItems = new List <TaskHost>(); if (container is EventsProvider) { EventsProvider ep = (EventsProvider)container; foreach (DtsEventHandler eh in ep.EventHandlers) { returnItems.AddRange(GetControlFlowObjects <T>(eh)); } } IDTSSequence sequence = (IDTSSequence)container; foreach (Executable exec in sequence.Executables) { if (exec is IDTSSequence) { returnItems.AddRange(GetControlFlowObjects <T>((DtsContainer)exec)); } else if (exec is TaskHost) { TaskHost th = (TaskHost)exec; if (th.InnerObject is T) { returnItems.Add(th); } } } return(returnItems); }
private void RecurseExecutables(IDTSSequence parentExecutable) { Package package = GetPackageFromContainer((DtsContainer)parentExecutable); ScanIntegrationServicesExecutableForPropertiesWithNonDefaultValue((Executable)parentExecutable, this.PackagePathPrefix + ((IDTSPackagePath)parentExecutable).GetPackagePath()); if (parentExecutable is EventsProvider) { foreach (DtsEventHandler eh in (parentExecutable as EventsProvider).EventHandlers) { RecurseExecutables(eh); } } foreach (Executable e in parentExecutable.Executables) { if (e is IDTSSequence) { RecurseExecutables((IDTSSequence)e); } else { ScanIntegrationServicesExecutableForPropertiesWithNonDefaultValue(e, this.PackagePathPrefix + ((IDTSPackagePath)e).GetPackagePath()); if (e is EventsProvider) { foreach (DtsEventHandler eh in (e as EventsProvider).EventHandlers) { RecurseExecutables(eh); } } } } }
private void ProcessSequence(DtsContainer container, IDTSSequence sequence, string path) { foreach (Executable executable in sequence.Executables) { ProcessObject(executable, path); } }
private DtsContainer FindObjectForVariablePackagePath(DtsContainer parent, string PackagePath) { if (PackagePath.StartsWith(((IDTSPackagePath)parent).GetPackagePath() + ".Variables[")) { return((DtsContainer)parent); } IDTSSequence seq = parent as IDTSSequence; if (seq != null) { foreach (Executable e in seq.Executables) { if (e is IDTSPackagePath) { if (PackagePath.StartsWith(((IDTSPackagePath)e).GetPackagePath() + ".Variables[")) { return((DtsContainer)e); } } if (e is DtsContainer) { DtsContainer ret = FindObjectForVariablePackagePath((DtsContainer)e, PackagePath); if (ret != null) { return(ret); } } } } EventsProvider prov = parent as EventsProvider; if (prov != null) { foreach (DtsEventHandler eh in prov.EventHandlers) { if (eh is IDTSPackagePath) { if (PackagePath.StartsWith(((IDTSPackagePath)eh).GetPackagePath() + ".Variables[")) { return((DtsContainer)eh); } } if (eh is IDTSSequence) { DtsContainer ret = FindObjectForVariablePackagePath((DtsContainer)eh, PackagePath); if (ret != null) { return(ret); } } } } return(null); }
/// <summary> /// Find an executable in a package. /// </summary> /// <param name="parentExecutable">The parent sequence to search</param> /// <param name="taskId">The task to find. This can be a task name, a GUID, or a 2012-format RefId.</param> /// <param name="remainingPath">Outputs the remaining path. This is used with RefIds which contain data flow components. The remaining path will include the portion of the path after the data flow task.</param> /// <returns>The task or container if found, null if it was not found.</returns> public static DtsContainer FindExecutable(IDTSSequence parentExecutable, string taskId, out string remainingPath) { if (taskId.Contains("\\") || taskId.Equals("Package", StringComparison.Ordinal)) { return(NavigateReferencePath(parentExecutable, taskId, out remainingPath)); } remainingPath = string.Empty; DtsContainer matchingExecutable; var parent = (DtsContainer)parentExecutable; if (parent.ID == taskId || parent.Name == taskId) { return(parent); } var provider = parent as EventsProvider; if (provider != null) { foreach (DtsEventHandler eh in provider.EventHandlers) { matchingExecutable = FindExecutable(eh, taskId, out remainingPath); if (matchingExecutable != null) { return(matchingExecutable); } } } if (parentExecutable.Executables.Contains(taskId)) { return((DtsContainer)parentExecutable.Executables[taskId]); } foreach (Executable e in parentExecutable.Executables) { var sequence = e as IDTSSequence; if (sequence == null) { continue; } matchingExecutable = FindExecutable(sequence, taskId, out remainingPath); if (matchingExecutable != null) { return(matchingExecutable); } } return(null); }
public Executable AddDFTTask(IDTSSequence _Package, string Name, int iCount) { Executable exe = _Package.Executables.Add(SSISMoniker.PIPE_LINE); TaskHost taskHost = exe as TaskHost; taskHost.Name = Name + iCount; taskHost.DelayValidation = true; return(exe); }
private void ProcessSequence(DtsContainer container, IDTSSequence sequence, System.ComponentModel.BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } foreach (Executable executable in sequence.Executables) { ProcessObject(executable, worker, path); } }
public void AddPrecedenceConstraints(Executable sqlTaskExe, IDTSSequence container = null) { if (container == null) { container = _Package; } if (_preTaskHost != null) { container.PrecedenceConstraints.Add(_preTaskHost, sqlTaskExe); } _preTaskHost = sqlTaskExe; }
private void ProcessObject(object component, System.ComponentModel.BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } DtsContainer container = component as DtsContainer; // Should only get package as we call GetPackage up front. Could make scope like, but need UI indicator that this is happening Package package = component as Package; if (package != null) { path = "\\Package"; CheckConnectionManagers(package, worker, path); } else if (!(component is DtsEventHandler)) { path = path + "\\" + container.Name; } IDTSPropertiesProvider propertiesProvider = component as IDTSPropertiesProvider; if (propertiesProvider != null) { CheckProperties(propertiesProvider, worker, path); } EventsProvider eventsProvider = component as EventsProvider; if (eventsProvider != null) { foreach (DtsEventHandler eventhandler in eventsProvider.EventHandlers) { ProcessObject(eventhandler, worker, path + ".EventHandlers[" + eventhandler.Name + "]"); } } IDTSSequence sequence = component as IDTSSequence; if (sequence != null) { ProcessSequence(container, sequence, worker, path); ScanPrecedenceConstraints(worker, path, container.ID, sequence.PrecedenceConstraints); } }
private void AddTruncateOrDeleteSQLTask(IDTSSequence container, string name, string taskName, string targetName, string targetConnectionName, string truncateOrDeleteBeforeInsert, string deleteFiltration = "") { Executable truncateOrDeleteExe = null; if (truncateOrDeleteBeforeInsert.ToUpper() == "DELETE" || truncateOrDeleteBeforeInsert.ToUpper() == "TRUNCATE") { string strSQLQuery = string.Empty; string sqlTaskName = string.Empty; if (taskName == null || taskName == string.Empty) { taskName = name; } name = name + "_" + truncateOrDeleteBeforeInsert; if (truncateOrDeleteBeforeInsert.ToUpper() == "DELETE") { sqlTaskName = "DELETE" + taskName; if (deleteFiltration.Trim() != string.Empty) { strSQLQuery = "Delete from " + " " + targetName + " WHERE " + deleteFiltration; } else { strSQLQuery = "Delete from " + " " + targetName; } } else { sqlTaskName = "TRUNCATE_" + taskName; strSQLQuery = "TRUNCATE table " + " " + targetName; } //pre Log Executable sqlTaskPreExe = AddExecutableSQLTask(PreSQL.Replace("<StepName>", name) + ",0", LogConnectionKey, "Pre-" + sqlTaskName, string.Empty, container); AddPrecedenceConstraints(sqlTaskPreExe, container); //Truncate or Delete truncateOrDeleteExe = AddExecutableSQLTask(strSQLQuery, targetConnectionName, sqlTaskName, string.Empty, container); AddPrecedenceConstraints(truncateOrDeleteExe, container); //Post Log Executable sqlTaskPostExe = AddExecutableSQLTask(PostSQL.Replace("<StepName>", name).Replace('?', '0') + "", LogConnectionKey, "Post-" + sqlTaskName, string.Empty, container); AddPrecedenceConstraints(sqlTaskPostExe, container); } else if (truncateOrDeleteBeforeInsert.ToUpper() != "NONE") { throw new Exception("TRUNCATE or delete before insertion parameter is incorrect : Possible values-DELETE, TRUNCATE or NONE."); } }
internal static PrecedenceConstraint FindConstraint(DtsContainer container, string objectID) { IDTSSequence sequence = container as IDTSSequence; if (sequence == null) { System.Diagnostics.Debug.Assert(false, "sequence cannot be found"); return(null); } if (sequence.PrecedenceConstraints.Contains(objectID)) { return(sequence.PrecedenceConstraints[objectID]); } return(null); }
private void ProcessSequence(IDTSSequence sequence, TreeNode parentNode) { if (sequence == null) { return; } if (this.CancellationPending) { return; } foreach (Executable executable in sequence.Executables) { ProcessObject(executable, parentNode); } }
private DtsContainer FindContainer(DtsContainer component, string objectId) { //DtsContainer container = component as DtsContainer; if (component == null) { return(null); } else if (component.ID == objectId) { return(component); } EventsProvider eventsProvider = component as EventsProvider; if (eventsProvider != null) { foreach (DtsEventHandler eventhandler in eventsProvider.EventHandlers) { DtsContainer container = FindContainer(eventhandler, objectId); if (container != null) { return(container); } } } IDTSSequence sequence = component as IDTSSequence; if (sequence != null) { foreach (Executable executable in sequence.Executables) { DtsContainer container = FindContainer((DtsContainer)executable, objectId); if (container != null) { return(container); } } } return(null); }
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) { AddGuid(v.ID+" \\ "+v.Name); } } foreach (Executable e in parentExecutable.Executables) { AddGuid(((DtsContainer)e).ID); if (e is IDTSSequence) { RecurseExecutablesAndCaptureGuids((IDTSSequence)e); } } }
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); } } }
private static void RecurseTasksAndSetupLogging(IDTSSequence container) { foreach (Executable exe in container.Executables) { if (exe is DtsContainer) { DtsContainer child = (DtsContainer)exe; child.LoggingMode = DTSLoggingMode.UseParentSetting; //remove existing selected log providers while (child.LoggingOptions.SelectedLogProviders != null && child.LoggingOptions.SelectedLogProviders.Count > 0) { child.LoggingOptions.SelectedLogProviders.Remove(0); } } if (exe is IDTSSequence) { RecurseTasksAndSetupLogging((IDTSSequence)exe); } } }
private void ProcessObject(object component, string path) { DtsContainer container = component as DtsContainer; // Should only get package as we call GetPackage up front. Could make scope like, but need UI indicator that this is happening Package package = component as Package; if (package != null) { path = "\\Package"; } else if (!(component is DtsEventHandler)) { path = path + "\\" + container.Name; } if (container != null) { ScanVariables(path, container.Variables); } EventsProvider eventsProvider = component as EventsProvider; if (eventsProvider != null) { foreach (DtsEventHandler eventhandler in eventsProvider.EventHandlers) { ProcessObject(eventhandler, path + ".EventHandlers[" + eventhandler.Name + "]"); } } IDTSSequence sequence = component as IDTSSequence; if (sequence != null) { ProcessSequence(container, sequence, path); } }
private void ProcessObject(object component, TreeNode parentNode) { if (this.CancellationPending) { return; } Package package = component as Package; if (package != null) { // Package node is created in calling function. CheckConnectionManagers(package, parentNode); } DtsContainer container = component as DtsContainer; if (container != null) { string containerKey = PackageHelper.GetContainerKey(container); TaskHost taskHost = null; if (package == null) { int imageIndex = GetControlFlowImageIndex(containerKey); parentNode = AddNode(parentNode, container.Name, imageIndex, component); taskHost = container as TaskHost; } if (taskHost != null) { CheckTask(taskHost, parentNode); } else if (containerKey == PackageHelper.ForLoopCreationName) { CheckForLoop(container as IDTSPropertiesProvider, parentNode); } else if (containerKey == PackageHelper.ForEachLoopCreationName) { CheckForEachLoop(container as ForEachLoop, parentNode); } else if (containerKey == PackageHelper.SequenceCreationName) { ScanProperties(container as IDTSPropertiesProvider, parentNode); } else { // Package, Event Handlers etc ScanProperties(container as IDTSPropertiesProvider, parentNode); } string currentPath = string.Empty; IDTSPackagePath packagePath = component as IDTSPackagePath; if (packagePath != null) { currentPath = packagePath.GetPackagePath(); } ScanVariables(container.Variables, parentNode, currentPath); } EventsProvider eventsProvider = component as EventsProvider; if (eventsProvider != null) { TreeNode eventsNode = AddFolder("EventHandlers", parentNode); foreach (DtsEventHandler eventhandler in eventsProvider.EventHandlers) { ProcessObject(eventhandler, eventsNode); } } IDTSSequence sequence = component as IDTSSequence; if (sequence != null) { ProcessSequence(sequence, parentNode); ScanPrecedenceConstraints(container.ID, sequence.PrecedenceConstraints, parentNode); } }
private ConnectionManager GetSelectedConnectionManager(IDesignerHost designer, out Package package) { package = null; System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; EditorWindow win = (EditorWindow)designer.GetService(typeof(Microsoft.DataWarehouse.ComponentModel.IComponentNavigator)); Control viewControl = (Control)win.SelectedView.GetType().InvokeMember("ViewControl", getflags, null, win.SelectedView, null); #if DENALI || SQL2014 Control lvwConnMgrs = null; package = (Package)win.PropertiesLinkComponent; if (win.SelectedIndex == (int)SSISHelpers.SsisDesignerTabIndex.ControlFlow) { //it's now a Microsoft.DataTransformationServices.Design.Controls.DtsConnectionsListView object which doesn't inherit from ListView and which is internal lvwConnMgrs = (Control)viewControl.Controls["controlFlowTrayTabControl"].Controls["controlFlowConnectionsTabPage"].Controls["controlFlowConnectionsListView"]; } else if (win.SelectedIndex == (int)SSISHelpers.SsisDesignerTabIndex.DataFlow) { lvwConnMgrs = (Control)viewControl.Controls["dataFlowsTrayTabControl"].Controls["dataFlowConnectionsTabPage"].Controls["dataFlowConnectionsListView"]; } else if (win.SelectedIndex == (int)SSISHelpers.SsisDesignerTabIndex.EventHandlers) { lvwConnMgrs = (Control)viewControl.Controls["controlFlowTrayTabControl"].Controls["controlFlowConnectionsTabPage"].Controls["controlFlowConnectionsListView"]; } else { return(null); } Microsoft.SqlServer.IntegrationServices.Designer.ConnectionManagers.ConnectionManagerUserControl cmControl = (Microsoft.SqlServer.IntegrationServices.Designer.ConnectionManagers.ConnectionManagerUserControl)lvwConnMgrs.GetType().InvokeMember("m_connectionManagerUserControl", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, lvwConnMgrs, null); Microsoft.SqlServer.IntegrationServices.Designer.ConnectionManagers.ConnectionManagerModelElement connModelEl = cmControl.SelectedItem as Microsoft.SqlServer.IntegrationServices.Designer.ConnectionManagers.ConnectionManagerModelElement; if (connModelEl == null) { return(null); } ConnectionManager conn = connModelEl.ConnectionManager; #else ListView lvwConnMgrs = null; IDTSSequence container = null; TaskHost taskHost = null; DdsDiagramHostControl diagram = null; if (win.SelectedIndex == 0) //Control Flow { diagram = (DdsDiagramHostControl)viewControl.Controls["panel1"].Controls["ddsDiagramHostControl1"]; lvwConnMgrs = (ListView)viewControl.Controls["controlFlowTrayTabControl"].Controls["controlFlowConnectionsTabPage"].Controls["controlFlowConnectionsListView"]; container = (IDTSSequence)diagram.ComponentDiagram.RootComponent; } else if (win.SelectedIndex == 1) //Data Flow { diagram = (DdsDiagramHostControl)viewControl.Controls["panel2"].Controls["pipelineDetailsControl"].Controls["PipelineTaskView"]; taskHost = (TaskHost)diagram.ComponentDiagram.RootComponent; container = (IDTSSequence)taskHost.Parent; lvwConnMgrs = (ListView)viewControl.Controls["dataFlowsTrayTabControl"].Controls["dataFlowConnectionsTabPage"].Controls["dataFlowConnectionsListView"]; } else if (win.SelectedIndex == 2) //Event Handlers { diagram = (DdsDiagramHostControl)viewControl.Controls["panel1"].Controls["panelDiagramHost"].Controls["EventHandlerView"]; lvwConnMgrs = (ListView)viewControl.Controls["controlFlowTrayTabControl"].Controls["controlFlowConnectionsTabPage"].Controls["controlFlowConnectionsListView"]; container = (IDTSSequence)diagram.ComponentDiagram.RootComponent; } else { return(null); } if (lvwConnMgrs.SelectedItems.Count != 1) { return(null); } package = GetPackageFromContainer((DtsContainer)container); ListViewItem lviConn = lvwConnMgrs.SelectedItems[0]; ConnectionManager conn = FindConnectionManager(package, lviConn.Text); #endif return(conn); }
private object SetPropertyValue(DtsObject dtsObject, string propertyPath, object value) { propertyPath = propertyPath.Replace("\\", "."); object returnValue = null; string firstPart = propertyPath; string restOfString = string.Empty; if (propertyPath.Contains(".")) { //Can have periods in object names (like connection manager names) //Need to verify that period is not between an index marker int delimiterIndex = propertyPath.IndexOf("."); //while (delimiterIndex > propertyPath.IndexOf("[") && // delimiterIndex < propertyPath.IndexOf("]")) //{ // delimiterIndex = propertyPath.IndexOf(".", delimiterIndex + 1 ); //} if (delimiterIndex > propertyPath.IndexOf("[") && delimiterIndex < propertyPath.IndexOf("]")) { delimiterIndex = propertyPath.IndexOf(".", propertyPath.IndexOf("]")); } if (delimiterIndex > -1) { firstPart = propertyPath.Substring(0, delimiterIndex); restOfString = propertyPath.Substring(delimiterIndex + 1, (propertyPath.Length - (delimiterIndex + 1))); if (firstPart.Length == 0) { return(SetPropertyValue(dtsObject, restOfString, value)); } } } if (firstPart.ToUpper().StartsWith("PACKAGE")) { if (!(dtsObject is Package)) { throw new ArgumentException("The initial object must be of type Package.", "dtsObject"); } return(SetPropertyValue(dtsObject, restOfString, value)); } // \Package.Variables[User::TestVar].Properties[Value] if (firstPart.ToUpper().StartsWith("VARIABLES")) { if (!(dtsObject is DtsContainer)) { throw new ArgumentException("Object must be of type DtsContainer to reference variables.", "dtsObject"); } Variables vars = null; string varName = GetSubStringBetween(firstPart, "[", "]"); DtsContainer cont = (DtsContainer)dtsObject; cont.VariableDispenser.LockOneForRead(varName, ref vars); returnValue = SetPropertyValue(vars[varName], restOfString, value); vars.Unlock(); return(returnValue); } // \Package.Properties[CreationDate] if (firstPart.ToUpper().StartsWith("PROPERTIES")) { if (!(dtsObject is IDTSPropertiesProvider)) { throw new ArgumentException("Object must be of type IDTSPropertiesProvider to reference properties.", "dtsObject"); } IDTSPropertiesProvider propProv = (IDTSPropertiesProvider)dtsObject; string propIndex = GetSubStringBetween(firstPart, "[", "]"); DtsProperty prop = propProv.Properties[propIndex]; if (dtsObject is Variable && prop.Name == "Value") { Variable var = (Variable)dtsObject; prop.SetValue(dtsObject, Convert.ChangeType(value, var.DataType)); } else { prop.SetValue(dtsObject, Convert.ChangeType(value, propProv.Properties[propIndex].Type)); } //Flag value as changing changesvc.OnComponentChanging(prop, null); changesvc.OnComponentChanged(prop, null, null, null); //marks the package designer as dirty return(prop.GetValue(dtsObject)); } // \Package.Connections[localhost.AdventureWorksDW2008].Properties[Description] if (firstPart.ToUpper().StartsWith("CONNECTIONS")) { if (!(dtsObject is Package)) { throw new ArgumentException("Object must be of type Package to reference Connections.", "dtsObject"); } string connIndex = GetSubStringBetween(firstPart, "[", "]"); Package pkg = (Package)dtsObject; return(SetPropertyValue(pkg.Connections[connIndex], restOfString, value)); } // \Package.EventHandlers[OnError].Properties[Description] if (firstPart.ToUpper().StartsWith("EVENTHANDLERS")) { if (!(dtsObject is EventsProvider)) { throw new ArgumentException("Object must be of type EventsProvider to reference events.", "dtsObject"); } EventsProvider eventProvider = (EventsProvider)dtsObject; string eventIndex = GetSubStringBetween(firstPart, "[", "]"); return(SetPropertyValue(eventProvider.EventHandlers[eventIndex], restOfString, value)); } //First Part of string is not one of the hard-coded values - it's either a task or container if (!(dtsObject is IDTSSequence)) { throw new ArgumentException("Object must be of type IDTSSequence to reference other tasks or containers.", "dtsObject"); } IDTSSequence seq = (IDTSSequence)dtsObject; if (seq.Executables.Contains(firstPart)) { return(SetPropertyValue(seq.Executables[firstPart], restOfString, value)); } // \Package\Sequence Container\Script Task.Properties[Description] // \Package\Sequence Container.Properties[Description] // \Package\Execute SQL Task.Properties[Description] //\Package.EventHandlers[OnError].Variables[System::Cancel].Properties[Value] // \Package.EventHandlers[OnError]\Script Task.Properties[Description] if (restOfString.Length > 0) { returnValue = SetPropertyValue(dtsObject, restOfString, value); } return(returnValue); }
private void RecurseExecutablesAndCaptureGuids(IDTSSequence parentExecutable) { foreach (Variable v in ((DtsContainer)parentExecutable).Variables) { //if (v.Namespace == "User") if (! v.SystemVariable) { AddGuid(v.ID); } } foreach (Executable e in parentExecutable.Executables) { AddGuid(((DtsContainer)e).ID); if (e is IDTSSequence) { RecurseExecutablesAndCaptureGuids((IDTSSequence)e); } } }
private void GetExecutableStatistics(IDTSSequence input) { //CreationName has STOCK:SEQUENCE //Name has sequencename onPreExecuteAllPrecedenceExecutablesNames = new List <string>(); onPreExecuteAllConstrainedExecutablesNames = new List <string>(); foreach (PrecedenceConstraint pc in input.PrecedenceConstraints) { onPreExecuteAllPrecedenceExecutablesNames.Add(((DtsContainer)(pc.PrecedenceExecutable)).Name); onPreExecuteAllConstrainedExecutablesNames.Add(((DtsContainer)(pc.ConstrainedExecutable)).Name); } //compare the two lists. if the item occurance is not more than one, then it is the entry in PrecedenceExecutableList // and the exit in the ConstrainedExecutableList onPreExecuteTopMostPreceedenceExecutableNames = new List <string>(); foreach (string s in onPreExecuteAllPrecedenceExecutablesNames) { if (onPreExecuteAllConstrainedExecutablesNames.Contains(s)) { //connected node } else { if (!onPreExecuteTopMostPreceedenceExecutableNames.Contains(s)) { onPreExecuteTopMostPreceedenceExecutableNames.Add(s); } } } onPreExecuteBottomMostPreceedenceExecutableNames = new List <string>(); foreach (string s in onPreExecuteAllConstrainedExecutablesNames) { if (onPreExecuteAllPrecedenceExecutablesNames.Contains(s)) { //conected node } else { if (!onPreExecuteBottomMostPreceedenceExecutableNames.Contains(s)) { onPreExecuteBottomMostPreceedenceExecutableNames.Add(s); } } } onPreExecuteAllExecutablesNames = new List <string>(); onPreExecuteDanglingExecutablesNames = new List <string>(); foreach (Executable executable in input.Executables) { string execName = ((DtsContainer)executable).Name; onPreExecuteAllExecutablesNames.Add(execName); if (!onPreExecuteAllPrecedenceExecutablesNames.Contains(execName) && !onPreExecuteAllConstrainedExecutablesNames.Contains(execName)) { onPreExecuteDanglingExecutablesNames.Add(execName); } } onPreExecuteAllExecCount = input.Executables.Count; onPreExecuteDanglingExecCount = onPreExecuteDanglingExecutablesNames.Count; onPreExecutePreConstraintsCount = input.PrecedenceConstraints.Count; }
private static void RecurseTasksAndSetupLogging(IDTSSequence container) { foreach (Executable exe in container.Executables) { if (exe is DtsContainer) { DtsContainer child = (DtsContainer)exe; child.LoggingMode = DTSLoggingMode.UseParentSetting; //remove existing selected log providers while (child.LoggingOptions.SelectedLogProviders != null && child.LoggingOptions.SelectedLogProviders.Count > 0) child.LoggingOptions.SelectedLogProviders.Remove(0); } if (exe is IDTSSequence) { RecurseTasksAndSetupLogging((IDTSSequence)exe); } } }
private string[] RecurseContainersAndGetVariableValidationErrors(IDTSSequence parentExecutable) { List<string> listOtherErrors = new List<string>(); listOtherErrors.AddRange(ScanDtsObjectVariablesForErrors((DtsContainer)parentExecutable)); if (parentExecutable is EventsProvider) { foreach (DtsEventHandler eh in (parentExecutable as EventsProvider).EventHandlers) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors(eh)); } } foreach (Executable e in parentExecutable.Executables) { if (e is IDTSSequence) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors((IDTSSequence)e)); } else { if (e is DtsContainer) { listOtherErrors.AddRange(ScanDtsObjectVariablesForErrors((DtsContainer)e)); } if (e is EventsProvider) { foreach (DtsEventHandler eh in (e as EventsProvider).EventHandlers) { listOtherErrors.AddRange(RecurseContainersAndGetVariableValidationErrors(eh)); } } } } return listOtherErrors.ToArray(); }
/// <summary> /// Find an executable in a package. /// </summary> /// <param name="parentExecutable">The parent sequence to search</param> /// <param name="taskId">The task to find. This can be a task name, a GUID, or a 2012-format RefId.</param> /// <returns>The task or container if found, null if it was not found.</returns> public static DtsContainer FindExecutable(IDTSSequence parentExecutable, string taskId) { string remainingPath; return(FindExecutable(parentExecutable, taskId, out remainingPath)); }
private static DtsContainer NavigateReferencePath(IDTSSequence parentExecutable, string taskId, out string remainingPath) { // This is a 2012 format path to the task / component. var pathParts = new Queue <string>(taskId.Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)); if (pathParts.Count == 0) { throw new ArgumentException( "TaskId included a backslash (\\) but was not a valid SSIS reference path.", "taskId"); } remainingPath = string.Empty; var currentSequence = parentExecutable; DtsContainer currentExecutable; do { if (currentSequence == null) { return(null); } var pathPart = pathParts.Dequeue(); if (pathPart.Equals("Package", StringComparison.Ordinal) && currentSequence is Package) { currentExecutable = currentSequence as DtsContainer; continue; } if (!currentSequence.Executables.Contains(pathPart)) { // Not found return(null); } currentExecutable = currentSequence.Executables[pathPart] as DtsContainer; currentSequence = currentExecutable as IDTSSequence; var taskHost = currentExecutable as TaskHost; if (taskHost != null && taskHost.InnerObject is MainPipe) { // This method shouldn't search past the Data Flow Task string fullPath = string.Empty; foreach (string nextPart in pathParts) { if (fullPath == string.Empty) { fullPath = nextPart; continue; } fullPath += @"\" + nextPart; } remainingPath = fullPath; return(currentExecutable); } }while (pathParts.Count > 0); return(currentExecutable); }
private void IterateContainers(DtsContainer parent, TreeNodeCollection nodes, string selectedContainerId) { TreeNode node = new TreeNode(); node.Name = parent.Name; node.Text = parent.Name; node.Tag = parent; SetNodeIcon(parent, node); nodes.Add(node); if (parent.ID == selectedContainerId) { node.TreeView.SelectedNode = node; } IDTSSequence seq = parent as IDTSSequence; if (seq != null) { foreach (Executable e in seq.Executables) { if (e is IDTSSequence || e is EventsProvider) { IterateContainers((DtsContainer)e, node.Nodes, selectedContainerId); } else { DtsContainer task = (DtsContainer)e; TreeNode childNode = new TreeNode(); childNode.Name = task.Name; childNode.Text = task.Name; childNode.Tag = task; SetNodeIcon(task, childNode); node.Nodes.Add(childNode); if (task.ID == selectedContainerId) { node.TreeView.SelectedNode = childNode; } } } } EventsProvider prov = parent as EventsProvider; if (prov != null) { foreach (DtsEventHandler p in prov.EventHandlers) { DtsContainer task = (DtsContainer)p; TreeNode childNode = new TreeNode(); childNode.Name = string.Format(CultureInfo.InvariantCulture, "{0} Event", p.Name); childNode.Text = string.Format(CultureInfo.InvariantCulture, "{0} Event", p.Name); childNode.Tag = task; SetNodeIcon(task, childNode); node.Nodes.Add(childNode); if (task.ID == selectedContainerId) { node.TreeView.SelectedNode = childNode; } } } return; }
private object LocatePropertyValue(object project, DtsObject dtsObject, string propertyPath, PropertyOperation operation, object value) { propertyPath = propertyPath.Replace("\\", "."); object returnValue = null; string firstPart = propertyPath; string restOfString = string.Empty; if (propertyPath.Contains(".")) { // Can have periods in object names (like connection manager names) // Need to verify that period is not between an index marker int delimiterIndex = propertyPath.IndexOf(".", StringComparison.Ordinal); if (delimiterIndex > propertyPath.IndexOf("[", StringComparison.Ordinal) && delimiterIndex < propertyPath.IndexOf("]", StringComparison.Ordinal)) { delimiterIndex = propertyPath.IndexOf(".", propertyPath.IndexOf("]", StringComparison.Ordinal), StringComparison.Ordinal); } if (delimiterIndex > -1) { firstPart = propertyPath.Substring(0, delimiterIndex); restOfString = propertyPath.Substring(delimiterIndex + 1, propertyPath.Length - (delimiterIndex + 1)); if (firstPart.Length == 0) { return(LocatePropertyValue(project, dtsObject, restOfString, operation, value)); } } } //\Project\ConnectionManagers[localhost.AdventureWorks2012.conmgr].Properties[ConnectionString] //\Project\Properties[ProtectionLevel] if (firstPart.ToUpper().StartsWith("PROJECT")) { if (!(project is Project)) { throw new ArgumentException("The initial object must be of type Project.", "project"); } return(LocatePropertyValue(project, (DtsObject)project, restOfString, operation, value)); } //\Project\ConnectionManagers[localhost.AdventureWorks2012.conmgr].Properties[ConnectionString] if (firstPart.ToUpper().StartsWith("CONNECTIONMANAGERS")) { string connIndex = GetSubStringBetween(firstPart, "[", "]"); ConnectionManager cm = (((Project)project).ConnectionManagerItems[connIndex]).ConnectionManager; return(LocatePropertyValue(project, cm, restOfString, operation, value)); } if (firstPart.ToUpper().StartsWith("PACKAGE")) { if (!(dtsObject is Package)) { throw new ArgumentException("The initial object must be of type Package.", "dtsObject"); } return(LocatePropertyValue(project, dtsObject, restOfString, operation, value)); } if (firstPart.ToUpper().StartsWith("VARIABLES")) { if (!(dtsObject is DtsContainer)) { throw new ArgumentException("Object must be of type DtsContainer to reference variables.", "dtsObject"); } Variables vars = null; string varName = GetSubStringBetween(firstPart, "[", "]"); DtsContainer cont = (DtsContainer)dtsObject; cont.VariableDispenser.LockOneForRead(varName, ref vars); returnValue = LocatePropertyValue(project, vars[varName], restOfString, operation, value); vars.Unlock(); return(returnValue); } // \Package.Properties[CreationDate] if (firstPart.ToUpper().StartsWith("PROPERTIES")) { string propIndex = GetSubStringBetween(firstPart, "[", "]"); if (!(dtsObject is IDTSPropertiesProvider)) { if (!(dtsObject is Project)) { throw new ArgumentException("Object must be of type Project or IDTSPropertiesProvider to reference properties.", "dtsObject"); } else { if (operation == PropertyOperation.Set) { dtsObject.GetType().GetProperty(propIndex).SetValue(dtsObject, Convert.ChangeType(value, dtsObject.GetType())); } return(dtsObject.GetType().GetProperty(propIndex).GetValue(dtsObject, null)); } } IDTSPropertiesProvider propProv = (IDTSPropertiesProvider)dtsObject; DtsProperty prop = propProv.Properties[propIndex]; if (operation == PropertyOperation.Set) { if (dtsObject is Variable) { Variable var = (Variable)dtsObject; prop.SetValue(dtsObject, Convert.ChangeType(value, var.DataType)); } else { prop.SetValue(dtsObject, Convert.ChangeType(value, propProv.Properties[propIndex].Type)); } } return(prop.GetValue(dtsObject)); } // \Package.Connections[localhost.AdventureWorksDW2008].Properties[Description] if (firstPart.ToUpper().StartsWith("CONNECTIONS")) { if (!(dtsObject is Package)) { throw new ArgumentException("Object must be of type Package to reference Connections.", "dtsObject"); } string connIndex = GetSubStringBetween(firstPart, "[", "]"); Package pkg = (Package)dtsObject; return(LocatePropertyValue(project, pkg.Connections[connIndex], restOfString, operation, value)); } // \Package.EventHandlers[OnError].Properties[Description] if (firstPart.ToUpper().StartsWith("EVENTHANDLERS")) { if (!(dtsObject is EventsProvider)) { throw new ArgumentException("Object must be of type EventsProvider to reference events.", "dtsObject"); } EventsProvider eventProvider = (EventsProvider)dtsObject; string eventIndex = GetSubStringBetween(firstPart, "[", "]"); return(LocatePropertyValue(project, eventProvider.EventHandlers[eventIndex], restOfString, operation, value)); } // First Part of string is not one of the hard-coded values - it's either a task or container if (!(dtsObject is IDTSSequence)) { throw new ArgumentException("Object must be of type IDTSSequence to reference other tasks or containers.", "dtsObject"); } IDTSSequence seq = (IDTSSequence)dtsObject; if (seq.Executables.Contains(firstPart)) { return(LocatePropertyValue(project, seq.Executables[firstPart], restOfString, operation, value)); } // \Package\Sequence Container\Script Task.Properties[Description] // \Package\Sequence Container.Properties[Description] // \Package\Execute SQL Task.Properties[Description] // \Package.EventHandlers[OnError].Variables[System::Cancel].Properties[Value] // \Package.EventHandlers[OnError]\Script Task.Properties[Description] if (restOfString.Length > 0) { returnValue = LocatePropertyValue(project, dtsObject, restOfString, operation, value); } return(returnValue); }
private void IterateContainers(DtsContainer parent, TreeNodeCollection nodes) { TreeNode node = new TreeNode(); node.Name = parent.Name; node.Text = parent.Name; node.Tag = parent.ID; node.Checked = true; node.Expand(); if (parent is EventsProvider) { EventsProvider ep = (EventsProvider)parent; if (ep.EventHandlers.Count > 0) { TreeNode eventNode = new TreeNode("Event Handlers"); foreach (DtsEventHandler eh in ep.EventHandlers) { IterateContainers((DtsContainer)eh, eventNode.Nodes); } node.Nodes.Add(eventNode); } } nodes.Add(node); IDTSSequence seq = (IDTSSequence)parent; foreach (Executable e in seq.Executables) { if (e is IDTSSequence) { IterateContainers((DtsContainer)e, node.Nodes); } else { DtsContainer task = (DtsContainer)e; TreeNode childNode = new TreeNode(); childNode.Name = task.Name; childNode.Text = task.Name; childNode.Tag = task.ID; childNode.Checked = true; if (task is EventsProvider) { EventsProvider ep = (EventsProvider)task; if (ep.EventHandlers.Count > 0) { TreeNode eventNode = new TreeNode("Event Handlers"); foreach (DtsEventHandler eh in ep.EventHandlers) { IterateContainers((DtsContainer)eh, eventNode.Nodes); } node.Nodes.Add(eventNode); } } node.Nodes.Add(childNode); } } return; }
//recursively looks in executables to find executable with the specified GUID public static Executable FindExecutable(IDTSSequence parentExecutable, string sObjectGuid) { Executable matchingExecutable = null; if (parentExecutable.Executables.Contains(sObjectGuid)) { matchingExecutable = parentExecutable.Executables[sObjectGuid]; } else { foreach (Executable e in parentExecutable.Executables) { if (e is IDTSSequence) { matchingExecutable = FindExecutable((IDTSSequence)e, sObjectGuid); if (matchingExecutable != null) return matchingExecutable; } } } return matchingExecutable; }