public void ReadAsDataTable1() { DelimitedClassBuilder cb = new DelimitedClassBuilder("ImportContact", ","); cb.IgnoreEmptyLines = true; cb.GenerateProperties = true; cb.AddField("FirstName", typeof(string)); cb.LastField.TrimMode = FileHelpers.TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("LastName", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("StreetNumber", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("StreetAddress", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("Unit", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("City", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("State", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("Zip", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; engine = new FileHelperEngine(cb.CreateRecordClass()); string source = "Alex & Jen,Bouquet,1815,Bell Rd,, Batavia,OH,45103" + Environment.NewLine + "Mark & Lisa K ,Arlinghaus,1817,Bell Rd,, Batavia,OH,45103" + Environment.NewLine + "Ed & Karen S ,Craycraft,1819,Bell Rd,, Batavia,OH,45103" + Environment.NewLine; DataTable contactData = engine.ReadStringAsDT(source); Assert.AreEqual(3, contactData.Rows.Count); Assert.AreEqual(8, contactData.Columns.Count); Assert.AreEqual("Alex & Jen", contactData.Rows[0][0].ToString()); Assert.AreEqual("Mark & Lisa K", contactData.Rows[1][0].ToString()); // new DelimitedClassBuilder("", ","); }
/// <summary> /// Read the file as a data table /// </summary> private void cmdRun_Click(object sender, EventArgs e) { FileHelperEngine engine = new FileHelperEngine(typeof(CustomersFixed)); DataGridDatos.DataSource = engine.ReadStringAsDT(txtData.Text); ; }
private void RunTest() { try { string classStr = mLastCode; var selected = cboClassLanguage.SelectedItem as NetLanguageList.LanguageType; Type mType = ClassBuilder.ClassFromString(classStr, selected.Language); try { FileHelperEngine engine = new FileHelperEngine(mType); DataTable dt = engine.ReadStringAsDT(txtInput.Text); dgPreview.DataSource = dt; lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void ReadFile() { Type t = ClassBuilder.ClassFromSourceFile(TestCommon.GetPath("Classes", "ClassFromFile.cs")); var engine = new FileHelperEngine(t); DataTable dt = engine.ReadStringAsDT(""); Assert.AreEqual(0, dt.Rows.Count); }
public void ReadFile() { Type t = ClassBuilder.ClassFromSourceFile(TestCommon.GetPath("Classes", "ClassFromFile.cs")); var engine = new FileHelperEngine(t); DataTable dt = engine.ReadStringAsDT(""); Assert.AreEqual(0, dt.Rows.Count); }
public void ReadAsDataTable1() { DelimitedClassBuilder cb = new DelimitedClassBuilder("ImportContact", ","); cb.IgnoreEmptyLines = true; cb.GenerateProperties = true; cb.AddField("FirstName", typeof(string)); cb.LastField.TrimMode = FileHelpers.TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("LastName", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("StreetNumber", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("StreetAddress", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("Unit", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("City", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("State", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; cb.AddField("Zip", typeof(string)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.FieldQuoted = false; var engine = new FileHelperEngine(cb.CreateRecordClass()); string source = "Alex & Jen,Bouquet,1815,Bell Rd,, Batavia,OH,45103" + Environment.NewLine + "Mark & Lisa K ,Arlinghaus,1817,Bell Rd,, Batavia,OH,45103" + Environment.NewLine + "Ed & Karen S ,Craycraft,1819,Bell Rd,, Batavia,OH,45103" + Environment.NewLine; DataTable contactData = engine.ReadStringAsDT(source); Assert.AreEqual(3, contactData.Rows.Count); Assert.AreEqual(8, contactData.Columns.Count); Assert.AreEqual("Alex & Jen", contactData.Rows[0][0].ToString()); Assert.AreEqual("Mark & Lisa K", contactData.Rows[1][0].ToString()); // new DelimitedClassBuilder("", ","); }
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 PasteFromClip() { DelimitedClassBuilder classBuilder = ExamineGridForColumnOrder("\t"); try { FileHelperEngine engine = new FileHelperEngine(classBuilder.CreateRecordClass()); DataTable dt = engine.ReadStringAsDT(Clipboard.GetText()); PasteDataTable(dt); } catch (Exception ex) { throw ex; //addInBase.MessageService.LogMessage(new ApplicationMessage(ex, ApplicationMessageType.ErrorNoPopup)); } }
private static void Main(string[] args) { var cb = new DelimitedClassBuilder("Customer", ","); cb.AddField("SomeField", typeof(String)); cb.LastField.Converter.TypeName = typeof(OtherNameSpace.MyConverter).ToString(); Type recordClass = cb.CreateRecordClass(); var engine = new FileHelperEngine(recordClass); var records = engine.ReadStringAsDT("aaa"); Assert.AreEqual("aaa", records.Rows[0].Field <string>(0)); Console.WriteLine("All OK"); Console.ReadKey(); }
private void RunTest() { try { string classStr = mLastCode; var selected = cboClassLanguage.SelectedItem is NetLanguage ? (NetLanguage)cboClassLanguage.SelectedItem : NetLanguage.CSharp; var type = ClassBuilder.ClassFromString(classStr, selected); FileHelperEngine engine = new FileHelperEngine(type); engine.ErrorMode = ErrorMode.SaveAndContinue; DataTable dt = engine.ReadStringAsDT(txtInput.Text); if (engine.ErrorManager.Errors.Length > 0) { dt = new DataTable(); dt.Columns.Add("LineNumber"); dt.Columns.Add("ExceptionInfo"); dt.Columns.Add("RecordString"); dt.Columns.Add("RecordTypeName"); foreach (var e in engine.ErrorManager.Errors) { dt.Rows.Add(e.LineNumber, e.ExceptionInfo.Message, e.RecordString, e.RecordTypeName); } dgPreview.DataSource = dt; 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 cmdReadTest_Click(object sender, EventArgs e) { try { string classStr = sdClassOut.Text; Type mType = null; switch (cboClassLeng.SelectedIndex) { case 0: mType = ClassBuilder.ClassFromString(classStr, NetLanguage.CSharp); break; case 1: mType = ClassBuilder.ClassFromString(classStr, NetLanguage.VbNet); break; default: break; } try { FileHelperEngine engine = new FileHelperEngine(mType); DataTable dt = engine.ReadStringAsDT(txtInput.Text); dgPreview.DataSource = dt; lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmdReadTest_Click(object sender, EventArgs e) { try { string classStr = sdClassOut.Text; Type mType = null; switch (cboClassLeng.SelectedIndex) { case 0: mType = ClassBuilder.ClassFromString(classStr, NetLanguage.CSharp); break; case 1: mType = ClassBuilder.ClassFromString(classStr, NetLanguage.VbNet); break; default: break; } try { FileHelperEngine engine = new FileHelperEngine(mType); DataTable dt = engine.ReadStringAsDT(txtInput.Text); dgPreview.DataSource = dt; lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Read the file as a data table /// </summary> private void cmdRun_Click(object sender, EventArgs e) { FileHelperEngine engine = new FileHelperEngine(typeof (CustomersFixed)); DataGridDatos.DataSource = engine.ReadStringAsDT(txtData.Text);; }
private void RunTest() { try { string classStr = mLastCode; var selected = cboClassLanguage.SelectedItem as NetLanguageList.LanguageType; Type mType = ClassBuilder.ClassFromString(classStr, selected.Language); try { FileHelperEngine engine = new FileHelperEngine(mType); DataTable dt = engine.ReadStringAsDT(txtInput.Text); dgPreview.DataSource = dt; lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RunTest() { try { string classStr = mLastCode; var selected = cboClassLanguage.SelectedItem is NetLanguage ? (NetLanguage) cboClassLanguage.SelectedItem : NetLanguage.CSharp; var type = ClassBuilder.ClassFromString(classStr, selected); FileHelperEngine engine = new FileHelperEngine (type); engine.ErrorMode = ErrorMode.SaveAndContinue; DataTable dt = engine.ReadStringAsDT (txtInput.Text); 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); } dgPreview.DataSource = dt; 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); } }