Ejemplo n.º 1
0
        /// <summary>
        /// This method parses a friendly Derived Columns expression entered by the user into a Lineage-ID based
        /// expression which is required by SSIS, using a regular-expression based parser.
        /// Additionally, it will set the Input Column Usage for any columns found in the expression.
        /// </summary>
        /// <param name="expression">Expression to be parsed.</param>
        /// <param name="transformation">Transformation to use for evaluating the lineage IDs</param>
        /// <param name="vi">Transformation Virtual Input used to search for input columns.</param>
        /// <param name="inputColumnUsageType">DTSUsageType for columns mapped in this expression.</param>
        /// <returns>Expression struct with the pre-processed and post-processed expression.</returns>
        public static Expression ExpressionCleanerAndInputMapBuilder(string expression, Transformation transformation, IDTSVirtualInput100 vi, DTSUsageType inputColumnUsageType)
        {
            Expression exp = new Expression();
            exp.OriginalExpression = expression;
            exp.ProcessedExpression = expression;
            exp.FriendlyExpression = expression;
            exp.ContainsId = false;

            foreach (IDTSVirtualInputColumn100 vcol in vi.VirtualInputColumnCollection)
            {
                string regexString = String.Format(CultureInfo.CurrentCulture, "(\"(?:[^\"]|(?<=\\\\)\")*\")|(?<vCol>(?<!@\\[?|:)\\[?\\b{0}\\b\\]?)", Regex.Escape(vcol.Name));
                var regex = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                int groupNumber = regex.GroupNumberFromName("vCol");

                var processedEme = new ExpressionMatchEvaluatorStruct(groupNumber, "#" + vcol.LineageID, transformation, vi, inputColumnUsageType, vcol);
                var friendlyEme = new ExpressionMatchEvaluatorStruct(groupNumber, vcol.Name, null, null, DTSUsageType.UT_IGNORED, null);

                exp.ProcessedExpression = regex.Replace(exp.ProcessedExpression, new MatchEvaluator(processedEme.EvaluateMatch));
                exp.FriendlyExpression = regex.Replace(exp.FriendlyExpression, new MatchEvaluator(friendlyEme.EvaluateMatch));
            }

            if (exp.ProcessedExpression != exp.OriginalExpression)
            {
                exp.ContainsId = true;
            }

            return exp;
        }
Ejemplo n.º 2
0
 public ExpressionMatchEvaluatorStruct(
     int groupNum,
     string text,
     Transformation trans,
     IDTSVirtualInput100 vi,
     DTSUsageType inputColumnUsageType,
     IDTSVirtualInputColumn100 vcol)
 {
     this.groupNum = groupNum;
     this.text = text;
     this.trans = trans;
     this.vi = vi;
     this.inputColumnUsageType = inputColumnUsageType;
     this.vcol = vcol;
 }