Example #1
0
 public ToStringTransform(PipelineContext context) : base(context) {
     _input = SingleInput();
     if (context.Transform.Format == string.Empty) {
         _toString = (o) => o.ToString();
     } else {
         switch (_input.Type) {
             case "int32":
             case "int":
                 _toString = (o) => ((int)o).ToString(context.Transform.Format);
                 break;
             case "double":
                 _toString = (o) => ((double)o).ToString(context.Transform.Format);
                 break;
             case "short":
             case "int16":
                 _toString = (o) => ((short)o).ToString(context.Transform.Format);
                 break;
             case "long":
             case "int64":
                 _toString = (o) => ((long)o).ToString(context.Transform.Format);
                 break;
             case "datetime":
             case "date":
                 _toString = (o) => ((DateTime)o).ToString(context.Transform.Format);
                 break;
             default:
                 _toString = (o) => o.ToString();
                 break;
         }
     }
 }
Example #2
0
 public ExpandoObject ToExpandoObject(Field[] fields) {
     var parameters = new ExpandoObject();
     var dict = ((IDictionary<string, object>)parameters);
     foreach (var field in fields) {
         dict.Add(field.FieldName(), _storage[_index(field)]);
     }
     return parameters;
 }
 static string SqlQuery(Field[] keys, IConnectionContext context, string tempTable, Field hashCode) {
     var names = string.Join(",", keys.Select(f => "k.[" + f.FieldName() + "]"));
     var table = context.Entity.OutputTableName(context.Process.Name);
     var joins = string.Join(" AND ", keys.Select(f => "o.[" + f.FieldName() + "] = k.[" + f.FieldName() + "]"));
     var sql = string.Format("SELECT {0},o.[{1}] FROM #{2} k WITH (NOLOCK) INNER JOIN [{3}] o WITH (NOLOCK) ON ({4})", names, hashCode.FieldName(), tempTable, table, joins);
     context.Debug(sql);
     return sql;
 }
Example #4
0
 public IsValidator(PipelineContext context)
       : base(context) {
       _input = SingleInput();
       if (context.Field.Type.StartsWith("bool", StringComparison.Ordinal)) {
           _canConvert = v => Constants.CanConvert()[context.Transform.Type](v);
       } else {
           _canConvert = v => Constants.CanConvert()[context.Transform.Type](v) ? string.Empty : string.Format("The value {0} can not be converted to a {1}.", v, context.Transform.Type);
       }
   }
Example #5
0
        public TimeZoneOperation(PipelineContext context) : base(context) {
            _input = SingleInput();
            _output = context.Field;

            var fromTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(context.Transform.FromTimeZone);
            _toTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(context.Transform.ToTimeZone);

            _adjustment = _toTimeZoneInfo.BaseUtcOffset - fromTimeZoneInfo.BaseUtcOffset;
            _daylightAdjustment = _adjustment.Add(new TimeSpan(0, 1, 0, 0));
        }
Example #6
0
      public ContainsValidater(PipelineContext context)
            : base(context) {

         _input = SingleInput();

         if (context.Field.Type.StartsWith("bool", StringComparison.Ordinal)) {
            _contains = s => s.Contains(context.Transform.Value);
         } else {
            _contains = s => s.Contains(context.Transform.Value) ? String.Empty : String.Format("{0} does not contain {1}.", _input.Alias, context.Transform.Value);
         }

      }
Example #7
0
        public SqlReader(IContext context, Field[] fields, ReadFrom readFrom) {

            _context = context;
            _connection = readFrom == ReadFrom.Output
                ? context.Process.Connections.First(c => c.Name == "output")
                : context.Process.Connections.First(c => c.Name == context.Entity.Connection);
            _tableOrView = readFrom == ReadFrom.Output ? context.Entity.OutputTableName(context.Process.Name) : context.Entity.Name;
            _fields = fields;
            _readFrom = readFrom;

            _rowCreator = new SqlRowCreator(context);
        }
        public SqlEntityMatchingKeysReader(IConnectionContext context, Field[] keys) {

            var tempTable = context.Entity.GetExcelName();

            _context = context;
            _keys = keys;
            _rowCapacity = context.GetAllEntityFields().Count();
            _hashCode = context.Entity.TflHashCode();
            _fields = CombineFields(keys, _hashCode);
            _create = SqlCreateKeysTable(context, tempTable);
            _insert = SqlInsertTemplate(context, tempTable, keys);
            _query = SqlQuery(keys, context, tempTable, _hashCode);
            _drop = SqlDrop(context, tempTable);
            _rowCreator = new SqlRowCreator(context);
        }
Example #9
0
        public Field AsField(Process process) {
            if (_loadedField != null)
                return _loadedField;

            if (string.IsNullOrEmpty(Entity)) {
                _loadedField = process.GetAllFields().FirstOrDefault(f => f.Alias == Field) ?? process.GetAllFields().FirstOrDefault(f => f.Name == Field);
                return _loadedField;
            }

            Entity entity;
            if (process.TryGetEntity(Entity, out entity)) {
                if (entity.TryGetField(Field, out _loadedField)) {
                    return _loadedField;
                }
            }
            return null;
        }
Example #10
0
        private static string DefaultValue(Field field) {

            if (field.Default == null)
                return "NULL";

            var d = field.Default == Constants.DefaultSetting ? Constants.StringDefaults()[field.Type] : field.Default;

            if (SqlConstants.StringTypes.Any(t => t == field.Type)) {
                return SqlConstants.T + d + SqlConstants.T;
            }

            if (field.Type.StartsWith("bool")) {
                return d.Equals("true", StringComparison.OrdinalIgnoreCase) ? "1" : "0";
            }

            return d;
        }
Example #11
0
        public FromXmlTransform(PipelineContext context)
            : base(context) {
            _input = SingleInputForMultipleOutput();
            var output = MultipleOutput();

            foreach (var f in output) {
                if (f.NodeType.Equals("attribute", IC)) {
                    _attributes[f.Name] = f;
                } else {
                    _elements[f.Name] = f;
                }
            }

            _searchAttributes = _attributes.Count > 0;
            _total = _elements.Count + _attributes.Count;

        }
Example #12
0
      public MapTransform(PipelineContext context, IMapReader mapReader) : base(context) {
         _input = SingleInput();
         foreach (var item in mapReader.Read(context)) {
            var from = _input.Convert(item.From);
            if (item.To == string.Empty) {
               var field = context.Entity.GetField(item.Parameter);
               _map[from] = (r) => r[field];
            } else {
               var to = context.Field.Convert(item.To);
               _map[from] = (r) => to;
            }
         }
         if (!_map.ContainsKey(CATCH_ALL)) {
            var value = context.Field.Convert(context.Field.Default);
            _map[CATCH_ALL] = (r) => value;
         }

      }
Example #13
0
 public Row Create(IDataReader reader, int rowCapacity, Field[] fields) {
     var row = new Row(rowCapacity, _context.Entity.IsMaster);
     for (var i = 0; i < reader.FieldCount; i++) {
         var field = fields[i];
         if (field.Type == "string") {
             if (reader.GetFieldType(i) == typeof(string)) {
                 row.SetString(field, reader.IsDBNull(i) ? null : reader.GetString(i));
             } else {
                 TypeMismatch(field, reader, i);
                 var value = reader.GetValue(i);
                 row[field] = value == DBNull.Value ? null : value;
             }
         } else {
             var value = reader.GetValue(i);
             row[field] = value == DBNull.Value ? null : value;
         }
     }
     return row;
 }
Example #14
0
 public PipelineContext(
     IPipelineLogger logger,
     Process process,
     Entity entity = null,
     Field field = null,
     Transform transform = null
 ) {
     ForLog = new object[5];
     Logger = logger;
     Activity = PipelineActivity.Transform;
     Process = process;
     Entity = entity ?? process.GetValidatedOf<Entity>(e => { e.Name = string.Empty; });
     Field = field ?? process.GetValidatedOf<Field>(f => { f.Name = string.Empty; });
     Transform = transform ?? process.GetDefaultOf<Transform>(t => { t.Method = string.Empty; });
     ForLog[0] = process.Name.PadRight(process.LogLimit, ' ').Left(process.LogLimit);
     ForLog[1] = Entity.Alias.PadRight(process.EntityLogLimit, ' ').Left(process.EntityLogLimit);
     ForLog[2] = ' ';
     ForLog[3] = Field.Alias.PadRight(process.FieldLogLimit, ' ').Left(process.FieldLogLimit);
     ForLog[4] = Transform.Method.PadRight(process.TransformLogLimit, ' ').Left(process.TransformLogLimit);
 }
Example #15
0
 public static string SqlGetOutputMaxVersion(this OutputContext c, Field version) {
     var sql = $"SELECT MAX([{version.Alias}]) FROM [{c.Entity.OutputViewName(c.Process.Name)}] WITH (NOLOCK);";
     c.Debug(sql);
     return sql;
 }
Example #16
0
 public static string SqlSelectInputWithMinAndMaxVersion(this IContext c, Field[] fields) {
     var coreSql = SqlSelectInputWithMaxVersion(c, fields);
     var sql = $"{coreSql} AND [{c.Entity.GetVersionField().Name}] >= @MinVersion";
     c.Debug(sql);
     return sql;
 }
Example #17
0
 public static string SqlSelectInputWithMaxVersion(this IContext c, Field[] fields) {
     var coreSql = SqlSelectInput(c, fields);
     var hasWhere = coreSql.Contains(" WHERE ");
     var sql = $@"{coreSql} {(hasWhere ? " AND " : " WHERE ")} [{c.Entity.GetVersionField().Name}] <= @MaxVersion";
     c.Debug(sql);
     return sql;
 }
Example #18
0
 public static string SqlSelectInput(this IContext c, Field[] fields) {
     var fieldList = string.Join(",", fields.Select(f => "[" + f.Name + "]"));
     var noLock = c.Entity.NoLock ? "WITH (NOLOCK) " : string.Empty;
     var sql = $"SELECT {fieldList} FROM {SqlSchemaPrefix(c)}[{c.Entity.Name}] {noLock}";
     if (c.Entity.Filter.Any()) {
         sql += " WHERE " + c.ResolveFilter();
     }
     c.Debug(sql);
     return sql;
 }
Example #19
0
 public bool TryGetField(string aliasOrName, out Field field) {
     field = GetField(aliasOrName);
     return field != null;
 }
Example #20
0
 public ToLowerTransform(PipelineContext context) : base(context) {
    _input = SingleInput();
 }
Example #21
0
 public FromSplitTransform(PipelineContext context)
     : base(context) {
     _input = SingleInputForMultipleOutput();
     _output = MultipleOutput();
     _separator = context.Transform.Separator.ToCharArray();
 }
Example #22
0
 public SqlInputReader(InputContext input, Field[] fields) {
     _input = input;
     _fields = fields;
     _rowCreator = new SqlRowCreator(input);
 }
 public DecompressTransform(PipelineContext context) : base(context) {
     _input = SingleInput();
     _output = context.Field;
 }
Example #24
0
 public PadLeftTransform(PipelineContext context)
     : base(context) {
     _input = SingleInput();
 }
 public SplitLengthTransform(PipelineContext context)
     : base(context) {
     _input = SingleInput();
     _separator = context.Transform.Separator.ToCharArray();
 }
Example #26
0
 public IEnumerable<object> ToEnumerable(Field[] fields) {
     return fields.Select(f => _storage[_index(f)]);
 }
Example #27
0
 public TrimTransform(PipelineContext context)
     : base(context) {
     _input = SingleInput();
     _trimChars = Context.Transform.TrimChars.ToCharArray();
 }
Example #28
0
 public bool Match(Field[] fields, Row other) {
     return fields.Length > 1 ?
         fields.Select(f => this[f]).SequenceEqual(fields.Select(f => other[f])) :
         this[fields[0]].Equals(other[fields[0]]);
 }
 static Field[] CombineFields(Field[] keys, Field hashCode) {
     var fields = new List<Field>(keys);
     fields.Add(hashCode);
     return fields.ToArray();
 }
Example #30
0
 public void TypeMismatch(Field field, IDataReader reader, int index) {
     var key = HashcodeTransform.GetHashCode(field.Name, field.Type);
     if (_errors.Add(key)) {
         _context.Error("Type mismatch for {0}. Expected {1}, but read {2}.", field.Name, field.Type, reader.GetFieldType(index));
     }
 }