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;

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

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

            Assert.AreEqual(4, dt.Rows.Count);
            Assert.AreEqual(4, mEngine.TotalRecords);
            Assert.AreEqual(0, mEngine.ErrorManager.ErrorCount);
        }
        private void CreateFixedLengthFields(string[][] data, FixedLengthClassBuilder builder)
        {
            List<FixedColumnInfo> res = null;

            foreach (string[] 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));
            }
        }
Пример #3
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;
        }
Пример #4
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);
        }
Пример #5
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);
        }