private static bool HasExpression(ConnectionManager connectionManager, List <string> listConfigPaths, out bool HasConfiguration) { IDTSPropertiesProvider dtsObject = (IDTSPropertiesProvider)connectionManager; bool returnValue = false; HasConfiguration = false; #if !DENALI && !SQL2014 //connection managers already have built-in expression highlighting in Denali, so don't run this code in Denali foreach (DtsProperty p in dtsObject.Properties) { try { if (!string.IsNullOrEmpty(dtsObject.GetExpression(p.Name))) { returnValue = true; break; } } catch { } } #endif //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in dtsObject.Properties) { string sPackagePath = p.GetPackagePath(dtsObject); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } return(returnValue); }
private void CheckForLoop(IDTSPropertiesProvider forLoop, TreeNode parent) { // Check regular properties of the loop for variables and regular property expressions ScanProperties(forLoop, parent); DtsProperty property; object propertyValue; // Check explicit expression properties as expressions, missed if we are looking for literal variables. property = forLoop.Properties["AssignExpression"]; propertyValue = property.GetValue(forLoop); if (propertyValue != null) { PropertyAsExpressionMatch(property, propertyValue.ToString(), parent); } property = forLoop.Properties["EvalExpression"]; propertyValue = property.GetValue(forLoop); if (propertyValue != null) { PropertyAsExpressionMatch(property, propertyValue.ToString(), parent); } property = forLoop.Properties["InitExpression"]; propertyValue = property.GetValue(forLoop); if (propertyValue != null) { PropertyAsExpressionMatch(property, propertyValue.ToString(), parent); } }
private void ScanProperties(IDTSPropertiesProvider provider, TreeNode parent) { if (this.CancellationPending) { return; } TreeNode properties = AddFolder("Properties", parent); TreeNode expressions = AddFolder("PropertyExpressions", parent); // New 2012 + interface implemented by Package, Sequence, DtsEventHandler, ForLoop, ForEachLoop // There are other objects that implement IDTSPropertiesProvider, and therefore support expressions, e.g. ConnectionManager, Variable // However we can use it to skip objects that have no expressions set, by using HasExpressions property bool hasExpressions = true; IDTSPropertiesProviderEx providerEx = provider as IDTSPropertiesProviderEx; if (providerEx != null) { hasExpressions = providerEx.HasExpressions; } foreach (DtsProperty property in provider.Properties) { TypeCode propertyType = property.Type; string propertyName = property.Name; #region Check property value string match; if (property.Type == TypeCode.String && property.Get) { string value = property.GetValue(provider) as string; if (!string.IsNullOrEmpty(value)) { PropertyMatch(properties, new DisplayProperty(property, value), propertyName, value); } } #endregion #region Check property expression string expression = provider.GetExpression(property.Name); if (expression == null) { continue; } // Check this for a while, before we trust it, simce it is undocumented. System.Diagnostics.Debug.Assert(hasExpressions, "HasExpressions was false, but we have an expression."); if (ExpressionMatch(expression, out match)) { VariableFoundEventArgs foundArgument = new VariableFoundEventArgs(); foundArgument.Match = match; OnRaiseVariableFound(foundArgument); AddNode(expressions, propertyName, GetImageIndex(IconKeyVariableExpression), new PropertyExpression(propertyName, expression, PackageHelper.GetTypeFromTypeCode(property.Type)), true); } #endregion } }
public SlackSingleAttachmentTaskForm(IDTSPropertiesProvider propertiesProvider, IServiceProvider serviceProvider) : this() { _propertiesProvider = propertiesProvider; this._serviceProvider = serviceProvider; _providerProperties = ExtractPropetiesFromProvider(propertiesProvider); BindTextPropertiesToForm(_providerProperties); var timeStampProperty = (DateTime)_providerProperties.Single(z => z.Item1 == "AttachmentTimeStamp").Item3; this.AttachmentTimeStampDatePicker.Value = timeStampProperty; }
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); } }
//Determine if the task has an expression private bool HasExpression(Executable executable, System.Collections.Generic.List <string> listConfigPaths, out bool HasConfiguration) { IDTSPropertiesProvider task = (IDTSPropertiesProvider)executable; bool returnValue = false; HasConfiguration = false; //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in task.Properties) { string sPackagePath = p.GetPackagePath(task); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } if (executable is ForEachLoop) { ForEachEnumeratorHost forEachEnumerator = ((ForEachLoop)executable).ForEachEnumerator; // Check the for each loop has been configured, else it won't have an enumerator yet if (forEachEnumerator == null) { return(returnValue); } if (!HasConfiguration) { //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in forEachEnumerator.Properties) { string sPackagePath = p.GetPackagePath(forEachEnumerator); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } } } return(returnValue); }
private Tuple <string, Type, object>[] ExtractPropetiesFromProvider(IDTSPropertiesProvider propertiesProvider) { //get properties with category custom attribute var properties = typeof(SlackSingleAttachmentTask).GetProperties() .Where(z => z.CustomAttributes.Any(x => x.AttributeType == typeof(CategoryAttribute))); var list = new List <Tuple <string, Type, object> >(); foreach (var propertyInfo in properties) { var prop = propertiesProvider.Properties[propertyInfo.Name]; var propValue = prop.GetValue(_propertiesProvider); list.Add(new Tuple <string, Type, object>(propertyInfo.Name, propertyInfo.PropertyType, propValue)); } return(list.ToArray()); }
private void CheckProperties(IDTSPropertiesProvider propProvider, BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } if (propProvider is DtsContainer) { DtsContainer container = (DtsContainer)propProvider; string containerKey = PackageHelper.GetContainerKey(container); string objectTypeName = container.GetType().Name; if (container is TaskHost) { if (((TaskHost)container).InnerObject is MainPipe) { objectTypeName = typeof(MainPipe).Name; // Prevents it from saying COM Object } else { objectTypeName = ((TaskHost)container).InnerObject.GetType().Name; } ScanProperties(worker, path, typeof(TaskHost), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } else if (container is ForEachLoop) { ForEachLoop loop = container as ForEachLoop; ScanProperties(worker, path, typeof(ForEachLoop), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); ScanProperties(worker, path + "\\ForEachEnumerator.", typeof(ForEachEnumerator), objectTypeName, container.ID, loop.ForEachEnumerator.ID, container.Name, loop.ForEachEnumerator, containerKey); } else { ScanProperties(worker, path, container.GetType(), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } ScanVariables(worker, path, objectTypeName, container.ID, container.Variables); } }
private bool HasExpression(TaskHost taskHost, string transformName, List <string> listConfigPaths, out bool HasConfiguration) { IDTSPropertiesProvider dtsObject = (IDTSPropertiesProvider)taskHost; bool returnValue = false; HasConfiguration = false; transformName = "[" + transformName + "]"; foreach (DtsProperty p in dtsObject.Properties) { if (p.Name.StartsWith(transformName)) { try { if (!string.IsNullOrEmpty(dtsObject.GetExpression(p.Name))) { returnValue = true; break; } } catch { } } } //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in dtsObject.Properties) { if (p.Name.StartsWith(transformName)) { string sPackagePath = p.GetPackagePath(dtsObject); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } } return(returnValue); }
private void CheckProperties(IDTSPropertiesProvider propProvider, BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } if (propProvider is DtsContainer) { DtsContainer container = (DtsContainer)propProvider; string containerKey = PackageHelper.GetContainerKey(container); string objectTypeName = container.GetType().Name; TaskHost taskHost = container as TaskHost; if (taskHost != null) { objectTypeName = CheckTaskHost(taskHost, worker, path, container, containerKey); } else if (container is ForEachLoop) { ForEachLoop loop = container as ForEachLoop; ScanProperties(worker, path, typeof(ForEachLoop), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); if (loop.ForEachEnumerator != null) { // A For Each Loop that has not been configured yet will not have an enumerator, so ensure we check ScanProperties(worker, path + "\\ForEachEnumerator.", typeof(ForEachEnumerator), objectTypeName, container.ID, loop.ForEachEnumerator.ID, container.Name, loop.ForEachEnumerator, containerKey); } } else { ScanProperties(worker, path, container.GetType(), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } ScanVariables(worker, path, objectTypeName, container.ID, container.Variables); } }
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 ScanProperties(BackgroundWorker worker, string objectPath, Type objectType, string objectTypeName, string containerID, string objectID, string objectName, IDTSPropertiesProvider provider, string containerKey) { if (worker.CancellationPending) { return; } foreach (DtsProperty property in provider.Properties) { try { string expression = provider.GetExpression(property.Name); if (expression == null) { continue; } System.Diagnostics.Debug.Assert(PackageHelper.ControlFlowInfos.ContainsKey(containerKey)); ExpressionInfo info = new ExpressionInfo(); info.ContainerID = containerID; info.ObjectID = objectID; info.Type = objectType; info.ObjectName = objectName; if (property.Name.StartsWith("[")) { info.ObjectPath = objectPath + ".Properties" + property.Name + ""; } else { info.ObjectPath = objectPath + ".Properties[" + property.Name + "]"; } info.ObjectType = objectTypeName; info.PropertyName = property.Name; info.Expression = expression; info.HasExpression = (info.Expression != null); info.Icon = PackageHelper.ControlFlowInfos[containerKey].Icon; worker.ReportProgress(0, info); } catch { } } }
private void CheckProperties(IDTSPropertiesProvider propProvider, BackgroundWorker worker, string path) { if (worker.CancellationPending) return; if (propProvider is DtsContainer) { DtsContainer container = (DtsContainer)propProvider; string containerKey = PackageHelper.GetContainerKey(container); string objectTypeName = container.GetType().Name; if (container is TaskHost) { if (((TaskHost)container).InnerObject is MainPipe) { objectTypeName = typeof(MainPipe).Name; // Prevents it from saying COM Object } else { objectTypeName = ((TaskHost)container).InnerObject.GetType().Name; } ScanProperties(worker, path, typeof(TaskHost), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } else if (container is ForEachLoop) { ForEachLoop loop = container as ForEachLoop; ScanProperties(worker, path, typeof(ForEachLoop), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); ScanProperties(worker, path + "\\ForEachEnumerator.", typeof(ForEachEnumerator), objectTypeName, container.ID, loop.ForEachEnumerator.ID, container.Name, loop.ForEachEnumerator, containerKey); } else { ScanProperties(worker, path, container.GetType(), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } ScanVariables(worker, path, objectTypeName, container.ID, container.Variables); } }
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); }
void expressionListWindow_EditExpressionSelected(object sender, EditExpressionSelectedEventArgs e) { try { Package package = null; DtsContainer container = null; if (win == null) { return; } try { package = GetCurrentPackage(); if (package == null) { return; } } catch (Exception ex) { System.Diagnostics.Debug.Assert(false, ex.ToString()); return; } // Parameters for Expression Editor Variables variables = null; VariableDispenser variableDispenser = null; string propertyName = string.Empty; Type propertyType = null; // Target objects IDTSPropertiesProvider propertiesProvider = null; Variable variable = null; PrecedenceConstraint constraint = null; // Get the container container = SSISHelpers.FindContainer(package, e.ContainerID); // Get the property details and variable objects for the editor if (e.Type == typeof(Variable)) { variable = SSISHelpers.FindVariable(container, e.ObjectID); propertyName = "Value"; propertyType = System.Type.GetType("System." + variable.DataType.ToString()); variables = container.Variables; variableDispenser = container.VariableDispenser; } else if (e.Type == typeof(PrecedenceConstraint)) { constraint = SSISHelpers.FindConstraint(container, e.ObjectID); propertyName = "Expression"; propertyType = typeof(bool); variables = container.Variables; variableDispenser = container.VariableDispenser; } else { if (e.Type == typeof(ConnectionManager)) { propertiesProvider = SSISHelpers.FindConnectionManager(package, e.ObjectID) as IDTSPropertiesProvider; } else if (e.Type == typeof(ForEachEnumerator)) { ForEachLoop forEachLoop = container as ForEachLoop; propertiesProvider = forEachLoop.ForEachEnumerator as IDTSPropertiesProvider; } else { propertiesProvider = container as IDTSPropertiesProvider; } if (propertiesProvider != null) { DtsProperty property = propertiesProvider.Properties[e.Property]; propertyName = property.Name; propertyType = PackageHelper.GetTypeFromTypeCode(property.Type); variables = container.Variables; variableDispenser = container.VariableDispenser; } else { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Expression editing not supported on this object ({0}).", e.ObjectID)); } } // Show the editor Konesans.Dts.ExpressionEditor.ExpressionEditorPublic editor = new Konesans.Dts.ExpressionEditor.ExpressionEditorPublic(variables, variableDispenser, propertyType, propertyName, e.Expression); editor.Editor.ExpressionFont = ExpressionFont; editor.Editor.ExpressionColor = ExpressionColor; editor.Editor.ResultFont = ResultFont; editor.Editor.ResultColor = ResultColor; if (editor.ShowDialog() == DialogResult.OK) { // Get expression string expression = editor.Expression; if (expression == null || string.IsNullOrEmpty(expression.Trim())) { expression = null; } // Set the new expression on the target object object objectChanged = null; if (variable != null) { if (expression == null) { variable.EvaluateAsExpression = false; } variable.Expression = expression; objectChanged = variable; } else if (constraint != null) { if (expression == null) { constraint.EvalOp = DTSPrecedenceEvalOp.Constraint; } constraint.Expression = expression; objectChanged = constraint; } else if (propertiesProvider != null) { // TaskHost, Sequence, ForLoop, ForEachLoop and ConnectionManager propertiesProvider.SetExpression(e.Property, expression); objectChanged = propertiesProvider; } expressionListWindow_RefreshExpressions(null, null); // Finish displaying expressions list before you mark the package // as dirty (which runs the expression highlighter) System.Windows.Forms.Application.DoEvents(); SetPackageAsDirty(package, expression, objectChanged); } } catch (Exception ex) { throw ex; } }
//Determine if the task has an expression private bool HasExpression(Executable executable, System.Collections.Generic.List <string> listConfigPaths, out bool HasConfiguration) { IDTSPropertiesProvider task = (IDTSPropertiesProvider)executable; bool returnValue = false; HasConfiguration = false; #if !DENALI && !SQL2014 //has built-in expression highlighting foreach (DtsProperty p in task.Properties) { try { if (!string.IsNullOrEmpty(task.GetExpression(p.Name))) { returnValue = true; break; } } catch { } } #endif //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in task.Properties) { string sPackagePath = p.GetPackagePath(task); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } if (executable is ForEachLoop) { ForEachEnumeratorHost forEachEnumerator = ((ForEachLoop)executable).ForEachEnumerator; #if !DENALI && !SQL2014 //has built-in expression highlighting if (!returnValue) { foreach (DtsProperty p in forEachEnumerator.Properties) { try { if (!string.IsNullOrEmpty(forEachEnumerator.GetExpression(p.Name))) { returnValue = true; break; } } catch { } } } #endif if (!HasConfiguration) { //check for package configurations separately so you can break out of the expensive expressions search as soon as you find one foreach (DtsProperty p in forEachEnumerator.Properties) { string sPackagePath = p.GetPackagePath(forEachEnumerator); if (listConfigPaths.Contains(sPackagePath)) { HasConfiguration = true; break; } } } } return(returnValue); }