예제 #1
0
        public void SaveLoadXmlFileFixed2()
        {
            var cb = new FixedLengthClassBuilder("Customers");

            cb.AddField("Field1", 8, typeof(DateTime));
            cb.LastField.Converter.Kind = ConverterKind.Date;
            cb.LastField.Converter.Arg1 = "ddMMyyyy";
            cb.LastField.FieldNullValue = DateTime.Now;

            cb.AddField("FieldSecond", 3, typeof(string));
            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = ' ';

            cb.AddField("Field33", 3, typeof(int));

            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = '0';
            cb.LastField.TrimMode  = TrimMode.Both;

            cb.SaveToXml(@"runtime.xml");

            engine = new FileHelperEngine(ClassBuilder.ClassFromXmlFile("runtime.xml"));

            Assert.AreEqual("Customers", engine.RecordType.Name);
            Assert.AreEqual(3, engine.RecordType.GetFields().Length);
            Assert.AreEqual("Field1", engine.RecordType.GetFields()[0].Name);
        }
    private static void Main(string[] args)
    {
        var cb = new FixedLengthClassBuilder("Customer");

        cb.AddField("BirthDate", 8, typeof(DateTime));
        cb.LastField.Converter.Kind = ConverterKind.Date;
        cb.LastField.Converter.Arg1 = "ddMMyyyy";
        cb.LastField.FieldNullValue = DateTime.Now;
        cb.AddField("Name", 3, typeof(string));
        cb.AddField("Age", 3, typeof(int));
        cb.LastField.TrimMode = TrimMode.Both;
        Type recordClass = cb.CreateRecordClass();
        var  dataTable   = new DataTable("Customer");

        dataTable.Columns.Add("BirthDate", typeof(DateTime));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Columns.Add("Age", typeof(int));
        dataTable.Rows.Add(new DateTime(1972, 8, 14), "Joe", 42);
        dataTable.Rows.Add(new DateTime(1971, 9, 15), "Tine", 43);
        var list   = dataTable.DataTableToList(recordClass);
        var engine = new FileHelperEngine(recordClass);

        engine.WriteFile(filename, list);
        Console.ReadKey();
    }
예제 #3
0
        public void FullClassBuildingFixed()
        {
            var cb = new FixedLengthClassBuilder("Customers");

            cb.AddField("Field1", 8, typeof(DateTime));
            cb.LastField.Converter.Kind = ConverterKind.Date;
            cb.LastField.Converter.Arg1 = "ddMMyyyy";
            cb.LastField.FieldNullValue = DateTime.Now;


            cb.AddField("Field2", 3, typeof(string));
            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = ' ';

            cb.AddField("Field3", 3, typeof(int));

            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = '0';
            cb.LastField.TrimMode  = TrimMode.Both;

            engine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable dt = engine.ReadFileAsDT(FileTest.Good.Test1.Path);

            Assert.AreEqual(4, dt.Rows.Count);
            Assert.AreEqual(4, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);
        }
예제 #4
0
        static void RunTimeRecordsFixed()
        {
            Console.WriteLine("Run Time Records now =) ...");
            Console.WriteLine();

            FixedLengthClassBuilder cb = new FixedLengthClassBuilder("Customer", FixedMode.ExactLength);

            cb.AddField("CustId", 5, typeof(Int32));
            cb.AddField("Name", 20, typeof(string));
            cb.AddField("Balance", 8, typeof(Decimal));
            cb.AddField("AddedDate", 8, typeof(DateTime));
            cb.LastField.Converter.Kind = ConverterKind.Date;
            cb.LastField.Converter.Arg1 = "ddMMyyyy";


            // Estas dos lineas son el uso de la librería
            FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable dt = engine.ReadFileAsDT(@"..\Data\CustomersFixedLength.txt");

            // Aqui es donde ustedes agregan su código
            foreach (DataRow dr in dt.Rows)
            {
                Console.WriteLine("Customer: " + dr[0].ToString() + " - " + dr[1].ToString());
            }
        }
예제 #5
0
    private void Read()
    {
        FixedLengthClassBuilder classBuilder = new FixedLengthClassBuilder("PessoaFixo");

        classBuilder.AddField("id", 4, typeof(int));
        classBuilder.AddField("name", 10, typeof(string));
        classBuilder.AddField("value", 8, typeof(decimal));
        classBuilder.LastField.Converter.TypeName = typeof(DecimalConverter).ToString();
        FileHelperEngine fhe = new FileHelperEngine(classBuilder.CreateRecordClass());
        var reg = fhe.ReadFile(@"C:\File.txt");
    }
예제 #6
0
        public FileFixedExtract(AbstractConnection connection, Entity entity, int top = 0)
        {
            var fileInfo = new FileInfo(connection.File);

            _entity    = entity;
            _top       = top;
            _fields    = _entity.Fields.WithInput().ToArray();
            _fullName  = fileInfo.FullName;
            _name      = fileInfo.Name;
            _errorMode = connection.ErrorMode;
            int ignoreFirstLines = connection.Start - 1;

            _classBuilder = new FixedLengthClassBuilder("Tfl" + _entity.Alias)
            {
                IgnoreEmptyLines = true,
                IgnoreFirstLines = ignoreFirstLines
            };
            foreach (var field in _fields)
            {
                var length  = field.Length.Equals("max", IC) ? int.MaxValue : Convert.ToInt32(field.Length.Equals(string.Empty) ? "64" : field.Length);
                var builder = new FixedFieldBuilder(field.Alias, length, typeof(string))
                {
                    FieldNullValue = new String(' ', length)
                };
                _classBuilder.AddField(builder);
            }
        }
예제 #7
0
        private Type GetDynamicDetailType()
        {
            var detailCb = new FixedLengthClassBuilder("Customers");

            detailCb.AddField("Field1", 8, typeof(DateTime));
            detailCb.LastField.Converter.Kind = ConverterKind.Date;
            detailCb.LastField.Converter.Arg1 = "ddMMyyyy";

            detailCb.AddField("Field2", 10, typeof(string));
            //detailCb.LastField.AlignMode = AlignMode.Right;
            //detailCb.LastField.AlignChar = ' ';

            detailCb.AddField("Field3", 10, typeof(int));
            //detailCb.LastField.AlignMode = AlignMode.Right;
            //detailCb.LastField.AlignChar = '0';
            //detailCb.LastField.TrimMode = TrimMode.Both;

            return(detailCb.CreateRecordClass());
        }
예제 #8
0
        public void SaveLoadXmlFileFixed()
        {
            var cb = new FixedLengthClassBuilder("Customers");

            cb.FixedMode = FixedMode.ExactLength;
            cb.AddField("Field1", 8, typeof(DateTime));
            cb.LastField.Converter.Kind = ConverterKind.Date;
            cb.LastField.Converter.Arg1 = "ddMMyyyy";
            cb.LastField.FieldNullValue = DateTime.Now;

            cb.AddField("FieldSecond", 3, typeof(string));
            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = ' ';

            cb.AddField("Field33", 3, typeof(int));

            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = '0';
            cb.LastField.TrimMode  = TrimMode.Both;

            cb.SaveToXml(@"runtime.xml");

            var loaded = (FixedLengthClassBuilder)ClassBuilder.LoadFromXml(@"runtime.xml");

            Assert.AreEqual("Field1", loaded.FieldByIndex(0).FieldName);
            Assert.AreEqual("FieldSecond", loaded.FieldByIndex(1).FieldName);
            Assert.AreEqual("Field33", loaded.FieldByIndex(2).FieldName);

            Assert.AreEqual("System.DateTime", loaded.FieldByIndex(0).FieldType);
            Assert.AreEqual("System.String", loaded.FieldByIndex(1).FieldType);
            Assert.AreEqual("System.Int32", loaded.FieldByIndex(2).FieldType);

            Assert.AreEqual(ConverterKind.Date, loaded.FieldByIndex(0).Converter.Kind);
            Assert.AreEqual("ddMMyyyy", loaded.FieldByIndex(0).Converter.Arg1);

            Assert.AreEqual(AlignMode.Right, loaded.FieldByIndex(1).AlignMode);
            Assert.AreEqual(' ', loaded.FieldByIndex(1).AlignChar);

            Assert.AreEqual(FixedMode.ExactLength, loaded.FixedMode);
        }
예제 #9
0
        public ClassBuilder CommonCreate()
        {
            var cb = new FixedLengthClassBuilder("Customers");

            cb.AddField("Field1", 8, typeof(DateTime));
            cb.LastField.Converter.Kind = ConverterKind.Date;
            cb.LastField.Converter.Arg1 = "ddMMyyyy";
            cb.LastField.FieldNullValue = DateTime.Now;

            cb.AddField("Field2", 3, typeof(string));

            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = ' ';

            cb.AddField("Field3", 3, typeof(int));

            cb.LastField.AlignMode = AlignMode.Right;
            cb.LastField.AlignChar = '0';
            cb.LastField.TrimMode  = TrimMode.Both;

            return(cb);
        }
        private void CreateFixedLengthFields(string[][] data, FixedLengthClassBuilder builder)
        {
            List <FixedColumnInfo> res = null;

            foreach (var dataFile in data)
            {
                List <FixedColumnInfo> candidates = CreateFixedLengthCandidates(dataFile);
                res = JoinFixedColCandidates(res, candidates);
            }

            for (int i = 0; i < res.Count; i++)
            {
                FixedColumnInfo col = res[i];
                builder.AddField("Field" + i.ToString().PadLeft(4, '0'), col.Length, typeof(string));
            }
        }