Exemple #1
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);
        }
    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();
    }
Exemple #3
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());
            }
        }
Exemple #4
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");
    }
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            Logger.Info("Reading Fixed {0}", _name);

            if (_top > 0)
            {
                using (var file = new FluentFile(_classBuilder.CreateRecordClass()).From(_fullName).OnError(_errorMode)) {
                    foreach (var obj in file)
                    {
                        var row = Row.FromObject(obj);
                        row["TflFileName"] = _fullName;
                        if (_counter < _top)
                        {
                            Interlocked.Increment(ref _counter);
                            yield return(row);
                        }
                        else
                        {
                            yield break;
                        }
                    }
                    HandleErrors(file);
                }
            }
            else
            {
                using (var file = new FluentFile(_classBuilder.CreateRecordClass()).From(_fullName).OnError(_errorMode)) {
                    foreach (var obj in file)
                    {
                        var row = Row.FromObject(obj);
                        row["TflFileName"] = _fullName;
                        yield return(row);
                    }
                    HandleErrors(file);
                }
            }
        }
Exemple #6
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());
        }