Exemplo n.º 1
0
        public override object Evaluate(object value, IDataRecord sourceRecord)
        {
            if (sourceRecord == null)
            {
                throw new ArgumentNullException("sourceRecord");
            }

            var str0 = EtlValueConverter.ToString(value);
            var str1 = EtlValueTranslation.Evaluate(this.SourceFieldName, this.SourceFieldTranslation, sourceRecord, this.DefaultValue);

            if (str0 == null || str1 == null)
            {
                if (this.IgnoreNulls)
                {
                    if (str0 == null)
                    {
                        return(str1);
                    }
                    else
                    {
                        return(str0);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(string.Concat(str0, str1));
            }
        }
        public override EtlStepResult Invoke(EtlContext context, IEtlLogger logger)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            if (this.Source == null)
            {
                throw new InvalidOperationException("Source cannot be null");
            }

            if (string.IsNullOrEmpty(this.Source.ConnectionString))
            {
                throw new InvalidOperationException("ConnectionString cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.ProviderName))
            {
                throw new InvalidOperationException("ProviderName cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.ProcedureName))
            {
                throw new InvalidOperationException("ProcedureName cannot be empty");
            }

            var result             = new EtlStepResult(EtlStatus.Succeeded, null);
            var hasOutputVariables = this.OutputVariables != null && this.OutputVariables.FirstRow.Count > 0;

            using (var dbAccessor = new DBAccessor(this.Source.ConnectionString, this.Source.ProviderName))
            {
                if (hasOutputVariables)
                {
                    using (var dbReader = dbAccessor.ExecuteProcedureReader(this.Source.ProcedureName, EtlProcedureParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds))
                    {
                        if (dbReader.Read())
                        {
                            foreach (var firstRowResult in this.OutputVariables.FirstRow)
                            {
                                var firstRowResultValue = EtlValueTranslation.Evaluate(firstRowResult.SourceFieldName, firstRowResult.SourceFieldTranslation, dbReader, firstRowResult.DefaultValue);
                                result.VariableAssignments.Add(new EtlVariableAssignment(firstRowResult.VariableName, EtlValueConverter.ToString(firstRowResultValue)));
                            }
                        }
                    }
                }
                else
                {
                    dbAccessor.ExecuteProcedure(this.Source.ProcedureName, EtlProcedureParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public void CanTranslateWithNestedFunctions()
        {
            var record = new FakeDataRecord(new Dictionary <string, object>
            {
                { "Id", new Guid("506A78BC-9AB9-4DB9-9371-08334060F5C9") },
                { "Null", null },
                { "Boolean", true },
                { "Byte", 255 },
                { "DateTime", DateTime.Parse("2010-01-15") },
                { "Decimal", Decimal.Parse("79228162514264337593543950335") },
                { "Double", 100000000.1 },
                { "Guid", new Guid("00000000-0000-0000-0000-000000000000") },
                { "Int16", 32767 },
                { "Int32", 2147483638 },
                { "Int64", 9223372036854775807 },
                { "Single", 10000000 },
                { "String", "Name:A" },
            });

            var translation = new EtlValueTranslation
                              (
                new EtlValueFunction[]
            {
                new EtlParseFunction(@".*:(?<g>\w)+", "g"),
                new EtlDecodeFunction
                (
                    new EtlDecodeRule(@"A", "Name is A"),
                    new EtlDecodeRule(@"B", "Name is B")
                ),
                new EtlConcatenateFunction(null, null, ", "),
                new EtlConcatenateFunction("Byte", null, null),
                new EtlConcatenateFunction(null, null, ", "),
                new EtlConcatenateFunction
                (
                    "Id",
                    new EtlValueTranslation
                    (
                        new EtlReplaceFunction("-", "_")
                    ),
                    null
                )
            }
                              );

            var expectedResult = "Name is A, 255, 506a78bc_9ab9_4db9_9371_08334060f5c9";
            var result         = EtlValueTranslation.Evaluate("String", translation, record);

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result);
        }
        public void CanTranslateWithNestedFunctions()
        {
            var record = new FakeDataRecord(new Dictionary<string, object>
            {
                {"Id", new Guid("506A78BC-9AB9-4DB9-9371-08334060F5C9")},
                {"Null", null},
                {"Boolean", true},
                {"Byte", 255},
                {"DateTime", DateTime.Parse("2010-01-15")},
                {"Decimal", Decimal.Parse("79228162514264337593543950335")},
                {"Double", 100000000.1},
                {"Guid", new Guid("00000000-0000-0000-0000-000000000000")},
                {"Int16", 32767},
                {"Int32", 2147483638},
                {"Int64", 9223372036854775807},
                {"Single", 10000000},
                {"String", "Name:A"},
            });

            var translation = new EtlValueTranslation
            (
                new EtlValueFunction[]
                {
                    new EtlParseFunction(@".*:(?<g>\w)+", "g"),
                    new EtlDecodeFunction
                    (
                        new EtlDecodeRule(@"A", "Name is A"),
                        new EtlDecodeRule(@"B", "Name is B")
                    ),
                    new EtlConcatenateFunction(null, null, ", "),
                    new EtlConcatenateFunction("Byte", null, null),
                    new EtlConcatenateFunction(null, null, ", "),
                    new EtlConcatenateFunction
                    (
                        "Id",
                         new EtlValueTranslation
                         (
                            new EtlReplaceFunction("-", "_")
                         ),
                         null
                    )
                }
            );

            var expectedResult = "Name is A, 255, 506a78bc_9ab9_4db9_9371_08334060f5c9";
            var result = EtlValueTranslation.Evaluate("String", translation, record);
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 5
0
        public override object Evaluate(object value, IDataRecord sourceRecord)
        {
            if (sourceRecord == null)
            {
                throw new ArgumentNullException("sourceRecord");
            }

            if (_rules.Count == 0)
            {
                return(null);
            }

            var str = EtlValueConverter.ToString(value);

            foreach (var rule in _rules)
            {
                if (!string.IsNullOrEmpty(rule.Regex))
                {
                    var options = GetRegexOptions(rule);
                    var regex   = new Regex(rule.Regex, options);
                    if (regex.IsMatch(str))
                    {
                        if (rule.Result == null)
                        {
                            return(null);
                        }
                        else
                        {
                            var result = EtlValueTranslation.Evaluate(rule.Result.SourceFieldName, rule.Result.SourceFieldTranslation, sourceRecord, rule.Result.DefaultValue);
                            return(result);
                        }
                    }
                }
            }

            return(null);
        }
 public EtlConcatenateFunction(string sourceFieldName, EtlValueTranslation valueTranslation, string defaultValue)
 {
     this.SourceFieldName = sourceFieldName;
     this.SourceFieldTranslation = valueTranslation;
     this.DefaultValue = defaultValue;
 }
Exemplo n.º 7
0
 public EtlConcatenateFunction(string sourceFieldName, EtlValueTranslation valueTranslation, string defaultValue)
 {
     this.SourceFieldName        = sourceFieldName;
     this.SourceFieldTranslation = valueTranslation;
     this.DefaultValue           = defaultValue;
 }
Exemplo n.º 8
0
        public override EtlStepResult Invoke(EtlContext context, IEtlLogger logger)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            if (this.Source == null)
            {
                throw new InvalidOperationException("Source cannot be null");
            }

            if (string.IsNullOrEmpty(this.Source.ConnectionString))
            {
                throw new InvalidOperationException("Source.ConnectionString cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.ProviderName))
            {
                throw new InvalidOperationException("Source.ProviderName cannot be empty");
            }

            if (string.IsNullOrEmpty(this.Source.Text))
            {
                throw new InvalidOperationException("Source.Text cannot be empty");
            }

            var result = new EtlStepResult(EtlStatus.Succeeded, null);

            var rowCounter = (this.Counters != null && this.Counters.RowCount != null && !string.IsNullOrEmpty(this.Counters.RowCount.CounterName))
                ? new EtlCounter
            {
                EtlPackageId = context.EtlPackageId,
                EtlSessionId = context.EtlSessionId,
                EntityName   = this.Counters.RowCount.EntityName,
                CounterName  = this.Counters.RowCount.CounterName,
            }
                : null;

            var hasOutputVariables = this.OutputVariables != null && this.OutputVariables.FirstRow.Count > 0;
            var hasRowCounter      = rowCounter != null;

            using (var dbAccessor = new DBAccessor(this.Source.ConnectionString, this.Source.ProviderName))
            {
                if (hasOutputVariables || hasRowCounter)
                {
                    using (var dbReader = dbAccessor.ExecuteQuery(this.Source.Text, EtlQueryParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds))
                    {
                        if (dbReader.Read())
                        {
                            if (hasRowCounter)
                            {
                                rowCounter.CounterValue++;
                            }

                            if (hasOutputVariables)
                            {
                                foreach (var firstRowResult in this.OutputVariables.FirstRow)
                                {
                                    var firstRowResultValue = EtlValueTranslation.Evaluate(firstRowResult.SourceFieldName, firstRowResult.SourceFieldTranslation, dbReader, firstRowResult.DefaultValue);
                                    result.VariableAssignments.Add(new EtlVariableAssignment(firstRowResult.VariableName, EtlValueConverter.ToString(firstRowResultValue)));
                                }
                            }
                        }

                        if (hasRowCounter)
                        {
                            while (dbReader.Read())
                            {
                                rowCounter.CounterValue++;
                            }

                            rowCounter.DateTime    = DateTime.Now;
                            rowCounter.UtcDateTime = rowCounter.DateTime.ToUniversalTime();
                            logger.LogEtlCounter(rowCounter);
                        }
                    }
                }
                else
                {
                    dbAccessor.ExecuteNonQuery(this.Source.Text, EtlQueryParameter.ToDictionary(this.Source.Parameters), this.TimeoutMilliseconds);
                }
            }

            return(result);
        }
 public EtlMatchResult(string sourceFieldName, EtlValueTranslation valueTranslation, string defaultValue)
 {
     this.SourceFieldName = sourceFieldName;
     this.SourceFieldTranslation = valueTranslation;
     this.DefaultValue = defaultValue;
 }
Exemplo n.º 10
0
 public EtlMatchResult(string sourceFieldName, EtlValueTranslation valueTranslation, string defaultValue)
 {
     this.SourceFieldName        = sourceFieldName;
     this.SourceFieldTranslation = valueTranslation;
     this.DefaultValue           = defaultValue;
 }
Exemplo n.º 11
0
        private object MapValue(EtlFieldMapping mapping)
        {
            var mappedValue = EtlValueTranslation.Evaluate(mapping.SourceFieldName, mapping.SourceFieldTranslation, _sourceReader, mapping.DefaultValue);

            return(mappedValue);
        }