Exemplo n.º 1
0
        public TflField GetField(string expression = null)
        {
            var field = new TflField().GetDefaultOf <TflField>(f => { f.Name = "Test"; });

            if (expression != null)
            {
                field.T = expression;
            }
            return(field);
        }
        private static FieldType GetFieldType(TflField element, bool isMaster)
        {
            FieldType fieldType;

            if (element.PrimaryKey)
            {
                fieldType = isMaster ? FieldType.MasterKey : FieldType.PrimaryKey;
            }
            else
            {
                fieldType = FieldType.NonKey;
            }
            return(fieldType);
        }
Exemplo n.º 3
0
        public void TwoMethodsShorter()
        {
            var field = new TflField().GetDefaultOf <TflField>(f => {
                f.Name = "test";
                f.T    = "left(10).right(2)";
            });

            GetFactory().ExpandShortHandTransforms(field);

            Assert.AreEqual(2, field.Transforms.Count);
            Assert.AreEqual("left", field.Transforms[0].Method);
            Assert.AreEqual(10, field.Transforms[0].Length);
            Assert.AreEqual("right", field.Transforms[1].Method);
            Assert.AreEqual(2, field.Transforms[1].Length);
        }
Exemplo n.º 4
0
        public ShortHandFactory GetFactory(TflField field = null)
        {
            var process = new TflRoot().GetDefaultOf <TflProcess>(p => {
                p.Name     = "Test";
                p.Entities = new List <TflEntity> {
                    new TflEntity().GetDefaultOf <TflEntity>(e => { e.Name = "Test"; })
                };
            });

            if (field != null)
            {
                process.Entities.First().Fields.Add(field);
            }
            return(new ShortHandFactory(process));
        }
Exemplo n.º 5
0
        public Field Read(TflField element, FieldType fieldType = FieldType.NonKey)
        {
            var alias = Common.GetAlias(element, _usePrefix, _entity.Prefix);

            var field = new Field(element.Type, element.Length, fieldType, element.Output, element.Default)
            {
                Process           = _process.Name,
                Entity            = _entity.Alias,
                EntityIndex       = _entity.Index,
                EntityOutputName  = _entity.OutputName(),
                Index             = element.Index,
                Schema            = _entity.Schema,
                Name              = element.Name,
                Alias             = alias,
                Precision         = element.Precision,
                Scale             = element.Scale,
                Input             = element.Input,
                NodeType          = element.NodeType,
                ReadInnerXml      = element.ReadInnerXml,
                Unicode           = element.Unicode.Equals("[default]") ? _entity.Unicode : Convert.ToBoolean(element.Unicode),
                VariableLength    = element.VariableLength.Equals("[default]") ? _entity.VariableLength : Convert.ToBoolean(element.VariableLength),
                Aggregate         = element.Aggregate,
                Sort              = element.Sort,
                Label             = element.Label,
                DefaultBlank      = element.DefaultBlank,
                DefaultWhiteSpace = element.DefaultWhiteSpace,
                QuotedWith        = element.QuotedWith,
                Optional          = element.Optional,
                Raw       = element.Raw,
                Delimiter = element.Delimiter,
                Distinct  = element.Distinct
            };

            FieldSearchTypesLoader(field, element);

            foreach (var keyField in new[] { "TflKey", "TflUpdate", "TflBatchId", "TflFileName", "TflDeleted", "TflAction" })
            {
                if (field.Alias.Equals(keyField, IC) && field.Input)
                {
                    _process.Logger.EntityWarn(_entity.Name, "{0}, defined in {1}, is a reserved field name.  Please alias this field.", field.Alias, field.Entity);
                }
            }

            return(field);
        }
Exemplo n.º 6
0
        private void FieldSearchTypesLoader(Field field, TflField element)
        {
            var searchTypes = element.SearchTypes;

            if (searchTypes.Count > 0)
            {
                foreach (var st in searchTypes.Where(st => _process.SearchTypes.ContainsKey(st.Name)))
                {
                    field.SearchTypes.Add(InheritType(_process.SearchTypes[st.Name], field));
                }
                return;
            }

            var searchType = element.SearchType.ToLower();

            if (_process.SearchTypes.Any())
            {
                if (_process.SearchTypes.ContainsKey(searchType))
                {
                    field.SearchTypes.Add(InheritType(_process.SearchTypes[searchType], field));
                }
            }
        }
Exemplo n.º 7
0
 public FieldBuilder CalculatedField(string name) {
     var calculatedField = new TflField {Name = name}.WithDefaults();
     _entity.CalculatedFields.Add(calculatedField);
     return new FieldBuilder(this, calculatedField);
 }
Exemplo n.º 8
0
 public FieldBuilder Field(string name) {
     var field = new TflField { Name = name }.WithDefaults();
     _entity.Fields.Add(field);
     return new FieldBuilder(this, field);
 }
Exemplo n.º 9
0
 public FieldBuilder(IFieldHolder fieldHolder, TflField field) {
     _fieldHolder = fieldHolder;
     _field = field;
 }
Exemplo n.º 10
0
 public FieldBuilder CalculatedField(string name) {
     var cf = new TflField { Name = name }.WithDefaults();
     _process.CalculatedFields.Add(cf);
     return new FieldBuilder(this, cf);
 }
Exemplo n.º 11
0
 public static string GetAlias(TflField element, bool usePrefix, string prefix)
 {
     return(usePrefix && element.Alias.Equals(element.Name) && !String.IsNullOrEmpty(prefix) ? prefix + element.Name : element.Alias);
 }
Exemplo n.º 12
0
 public FieldBuilder(IFieldHolder fieldHolder, TflField field)
 {
     _fieldHolder = fieldHolder;
     _field       = field;
 }