public DisplayProperty(DtsProperty property, object value) { this.Name = property.Name; this.Value = value; this.Type = PackageHelper.GetTypeFromTypeCode(property.Type); this.Get = property.Get; this.Set = property.Set; }
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)) { if (PropertyMatch(propertyName, value, out match)) { VariableFoundEventArgs foundArgument = new VariableFoundEventArgs(); foundArgument.Match = match; OnRaiseVariableFound(foundArgument); AddNode(properties, propertyName, GetImageIndex(IconKeyProperty), new DisplayProperty(property, value), true); } } } #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 } }
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; } }
private void ExpressionMatchProperty(TreeNode expressions, DtsProperty property, string propertyName, string expression) { foreach (string match in expressionCandidateMatches.Where(matchCandidate => expression.Contains(matchCandidate)).ToList()) { VariableFoundEventArgs foundArgument = new VariableFoundEventArgs(); foundArgument.Match = match; OnRaiseVariableFound(foundArgument); AddNode(expressions, propertyName, GetImageIndex(IconKeyVariableExpression), new PropertyExpression(propertyName, expression, PackageHelper.GetTypeFromTypeCode(property.Type)), true); } }