public void OneColumnNonFixed() { var detector = new SmartFormatDetector(); RecordFormatInfo[] formats = detector.DetectFileFormat(FileTest.Detection.OnColumnNonFixed.Path); Assert.AreEqual(0, formats.Length); }
static void ReadDelimitedFile() { var detector = new SmartFormatDetector(); detector.FileHasHeaders = hasHeaders; detector.MaxSampleLines = 100; var formats = detector.DetectFileFormat(FilePath); if (formats.Length == 0) { return; } string FileInput = File.ReadAllText(FilePath); try { ClassBuilder sb = ClassBuilder.LoadFromXml(xmlTrasfertaClassPath); var type = ClassBuilder.ClassFromString(sb.GetClassSourceCode(NetLanguage.CSharp), NetLanguage.CSharp); FileHelperEngine engine = new FileHelperEngine(type); engine.ErrorMode = ErrorMode.SaveAndContinue; DataTable dt = engine.ReadStringAsDT(FileInput); if (engine.ErrorManager.Errors.Length > 0) { dt = new DataTable(); dt.Columns.Add("LineNumber"); dt.Columns.Add("ExceptionInfo"); dt.Columns.Add("RecordString"); foreach (var e in engine.ErrorManager.Errors) { dt.Rows.Add(e.LineNumber, e.ExceptionInfo.Message, e.RecordString); } MessageBox.Show("Error Parsing the Sample Data", "Layout errors detected", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //dgPreview.DataSource = dt; //lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AssertDelimitedFormat(string file, string delimiter, int fields, int confidence, int numFormats) { var detector = new SmartFormatDetector(); RecordFormatInfo[] formats; detector.MaxSampleLines = 10; formats = detector.DetectFileFormat(file); AssertFormat(formats, delimiter, fields, confidence, numFormats); detector.MaxSampleLines = 20; formats = detector.DetectFileFormat(file); AssertFormat(formats, delimiter, fields, confidence, numFormats); detector.MaxSampleLines = 50; formats = detector.DetectFileFormat(file); AssertFormat(formats, delimiter, fields, confidence, numFormats); detector.MaxSampleLines = 100; formats = detector.DetectFileFormat(file); AssertFormat(formats, delimiter, fields, confidence, numFormats); }
public void OneColumnFixed() { var detector = new SmartFormatDetector(); var formats = detector.DetectFileFormat(FileTest.Detection.OnColumnFixed.Path); Assert.AreEqual(1, formats.Length); Assert.IsTrue(formats[0].ClassBuilder is FixedLengthClassBuilder); Assert.AreEqual(100, formats[0].Confidence); Assert.AreEqual(1, formats[0].ClassBuilder.FieldCount); var builder = (FixedLengthClassBuilder)formats[0].ClassBuilder; Assert.AreEqual(10, builder.Fields[0].FieldLength); }
public void FixedLength() { var detector = new SmartFormatDetector(); var formats = detector.DetectFileFormat(FileTest.Detection.CustomersFixed.Path); Assert.AreEqual(1, formats.Length); Assert.IsTrue(formats[0].ClassBuilder is FixedLengthClassBuilder); Assert.AreEqual(100, formats[0].Confidence); Assert.AreEqual(7, formats[0].ClassBuilder.FieldCount); var builder = formats[0].ClassBuilder as FixedLengthClassBuilder; Assert.AreEqual(11, builder.Fields[0].FieldLength); Assert.AreEqual(38, builder.Fields[1].FieldLength); Assert.AreEqual(22, builder.Fields[2].FieldLength); Assert.AreEqual(38, builder.Fields[3].FieldLength); Assert.AreEqual(41, builder.Fields[4].FieldLength); Assert.AreEqual(18, builder.Fields[5].FieldLength); Assert.AreEqual(15, builder.Fields[6].FieldLength); }
public void FixedLength() { SmartFormatDetector detector = new SmartFormatDetector(); RecordFormatInfo[] formats = detector.DetectFileFormat(Common.TestPath(@"Detection\CustomersFixed.txt")); Assert.AreEqual(1, formats.Length); Assert.IsTrue(formats[0].ClassBuilder is FixedLengthClassBuilder); Assert.AreEqual(100, formats[0].Confidence); Assert.AreEqual(7, formats[0].ClassBuilder.FieldCount); FixedLengthClassBuilder builder = formats[0].ClassBuilder as FixedLengthClassBuilder; Assert.AreEqual(11, builder.Fields[0].FieldLength); Assert.AreEqual(38, builder.Fields[1].FieldLength); Assert.AreEqual(22, builder.Fields[2].FieldLength); Assert.AreEqual(38, builder.Fields[3].FieldLength); Assert.AreEqual(41, builder.Fields[4].FieldLength); Assert.AreEqual(18, builder.Fields[5].FieldLength); Assert.AreEqual(15, builder.Fields[6].FieldLength); }