static void BoolTest() { ChoTypeConverterFormatSpec.Instance.BooleanFormat = ChoBooleanFormatSpec.ZeroOrOne; ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1) { FieldType = typeof(int) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Salary", 3) { FieldType = typeof(ChoCurrency) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("JoinedDate", 4) { FieldType = typeof(DateTime) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Active", 5) { FieldType = typeof(bool) }); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader, config)) { writer.WriteLine(@"1,Carl,12345679,01/10/2016,0"); writer.WriteLine("2,Mark,50000,10/01/1995,1"); writer.WriteLine("3,Tom,150000,01/01/1940,1"); writer.Flush(); stream.Position = 0; object row = null; while ((row = parser.Read()) != null) { Console.WriteLine(row.ToStringEx()); } } }
static void DateTimeTest() { ChoTypeConverterFormatSpec.Instance.DateTimeFormat = "MMM dd, yyyy"; ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1) { FieldType = typeof(int) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Salary", 3) { FieldType = typeof(ChoCurrency) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("JoinedDate", 4) { FieldType = typeof(DateTime) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Active", 5) { FieldType = typeof(bool) }); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader, config)) { writer.WriteLine(@"1,Carl,12345679,""Jan 01, 2011"",0"); writer.WriteLine(@"2,Mark,50000,""Sep 23, 1995"",1"); writer.WriteLine(@"3,Tom,150000,""Apr 10, 1999"",1"); writer.Flush(); stream.Position = 0; object row = null; while ((row = parser.Read()) != null) { Console.WriteLine(row.ToStringEx()); } } }
static void EnumTest() { ChoTypeConverterFormatSpec.Instance.EnumFormat = ChoEnumFormatSpec.Description; ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1) { FieldType = typeof(int) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Salary", 3) { FieldType = typeof(ChoCurrency) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("JoinedDate", 4) { FieldType = typeof(DateTime) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("EmployeeType", 5) { FieldType = typeof(EmployeeType) }); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader, config)) { writer.WriteLine(@"1,Carl,12345679,01/10/2016,Full Time Employee"); writer.WriteLine("2,Mark,50000,10/01/1995,Temporary Employee"); writer.WriteLine("3,Tom,150000,01/01/1940,Contract Employee"); writer.Flush(); stream.Position = 0; object row = null; while ((row = parser.Read()) != null) { Console.WriteLine(row.ToStringEx()); } } }
static void UsingLinqTest() { ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); config.Culture = new System.Globalization.CultureInfo("se-SE"); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1) { FieldType = typeof(int) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Salary", 3) { FieldType = typeof(ChoCurrency) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("JoinedDate", 4) { FieldType = typeof(DateTime) }); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("EmployeeNo", 5) { FieldType = typeof(int) }); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader, config)) { writer.WriteLine(@"1,Carl,12.345679 kr,2017-10-10, 5 "); writer.WriteLine("2,Markl,50000 kr,2001-10-01, 6 "); writer.WriteLine("3,Toml,150000 kr,1996-01-25, 9 "); writer.Flush(); stream.Position = 0; object row = null; while ((row = parser.Read()) != null) { Console.WriteLine(row.ToStringEx()); } } }
static void CurrencyTest() { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader <EmployeeRecWithCurrency>(reader)) { writer.WriteLine("1,Carl,$100000"); writer.WriteLine("2,Mark,$50000"); writer.WriteLine("3,Tom,1000"); writer.Flush(); stream.Position = 0; object rec; while ((rec = parser.Read()) != null) { Console.WriteLine(rec.ToStringEx()); } } }
static void QuickTest() { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader <EmployeeRecWithCurrency>(reader).WithDelimiter(",").WithFirstLineHeader()) { writer.WriteLine("Id,Name,Salary"); writer.WriteLine("1,Carl,1000"); writer.WriteLine("2,Mark,2000"); writer.WriteLine("3,Tom,3000"); writer.Flush(); stream.Position = 0; object rec; while ((rec = parser.Read()) != null) { Console.WriteLine(rec.ToStringEx()); } } }
private void Form1_Load(object sender, EventArgs e) { UnJourTransfert ujt = new UnJourTransfert(); using (ChoCSVReader <UnJourTransfert> reader = new ChoCSVReader <UnJourTransfert>("Tension.csv")) { while ((ujt = reader.Read()) != null) { UneTension tension1 = new UneTension(ujt.sys1.ToString() + ";" + ujt.dia1.ToString() + ";" + ujt.pul1.ToString()); UneTension tension2 = new UneTension(ujt.sys2.ToString() + ";" + ujt.dia2.ToString() + ";" + ujt.pul2.ToString()); UneTension tension3 = new UneTension(ujt.sys3.ToString() + ";" + ujt.dia3.ToString() + ";" + ujt.pul3.ToString()); UneTension tension4 = new UneTension(ujt.sys4.ToString() + ";" + ujt.dia4.ToString() + ";" + ujt.pul4.ToString()); UneTension tension5 = new UneTension(ujt.sys5.ToString() + ";" + ujt.dia5.ToString() + ";" + ujt.pul5.ToString()); UneTension tension6 = new UneTension(ujt.sys6.ToString() + ";" + ujt.dia6.ToString() + ";" + ujt.pul6.ToString()); UnJour uj = new UnJour(); uj.matin1 = tension1; uj.matin2 = tension2; uj.matin3 = tension3; uj.soir1 = tension4; uj.soir2 = tension5; uj.soir3 = tension6; this.dateTimePicker1.Value = DateTime.Parse(ujt.LaDate); uj.annee = dateTimePicker1.Value.Year; uj.mois = dateTimePicker1.Value.Month; uj.jour = dateTimePicker1.Value.Day; LJ.Add(uj); ctlUneTension1.import(tension1.sys.ToString() + ";" + tension1.dia.ToString() + ";" + tension1.pul.ToString()); ctlUneTension2.import(tension2.sys.ToString() + ";" + tension2.dia.ToString() + ";" + tension2.pul.ToString()); ctlUneTension3.import(tension3.sys.ToString() + ";" + tension3.dia.ToString() + ";" + tension3.pul.ToString()); ctlUneTension4.import(tension4.sys.ToString() + ";" + tension4.dia.ToString() + ";" + tension4.pul.ToString()); ctlUneTension5.import(tension5.sys.ToString() + ";" + tension5.dia.ToString() + ";" + tension5.pul.ToString()); ctlUneTension6.import(tension6.sys.ToString() + ";" + tension6.dia.ToString() + ";" + tension6.pul.ToString()); } UpdateScrollbar(); UnJour uj1 = (UnJour)LJ[hScrollBar1.Value - 1]; } }
static void QuickDynamicTest() { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader).WithDelimiter(",").WithFirstLineHeader().WithField("Id", typeof(int)). WithField("Name", typeof(string), fieldName: "@Name $1").ColumnOrderStrict()) { writer.WriteLine("Id,@Name $1,Salary"); writer.WriteLine("1,Carl,1000"); writer.WriteLine("2,Mark,2000"); writer.WriteLine("3,Tom,3000"); writer.Flush(); stream.Position = 0; dynamic rec; while ((rec = parser.Read()) != null) { //Console.WriteLine(rec.Name); Console.WriteLine(((object)rec).ToStringEx()); } } }
private static void OldTest() { //var t = ChoTypeDescriptor.GetPropetyAttributes<ChoTypeConverterAttribute>(ChoTypeDescriptor.GetProperty<ChoTypeConverterAttribute>(typeof(EmployeeRecMeta), "Name")).ToArray(); //return; //ChoMetadataObjectCache.Default.Attach(typeof(EmployeeRec), new EmployeeRecMeta()); //string v = @"4,'123\r\n4,abc'"; //foreach (var ss in v.SplitNTrim(",", ChoStringSplitOptions.None, '\'')) // Console.WriteLine(ss + "-"); //return; ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); //config.AutoDiscoverColumns = false; config.FileHeaderConfiguration.HasHeaderRecord = true; //config.CSVFileHeaderConfiguration.FillChar = '$'; config.ThrowAndStopOnMissingField = false; //config.HasExcelSeparator = true; config.ColumnCountStrict = false; //config.MapRecordFields<EmployeeRec>(); ChoCSVRecordFieldConfiguration idConfig = new ChoCSVRecordFieldConfiguration("Id", 1); idConfig.AddConverter(new IntConverter()); config.CSVRecordFieldConfigurations.Add(idConfig); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); config.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name1", 2)); dynamic rec = new ExpandoObject(); rec.Id = 1; rec.Name = "Raj"; //using (var wr = new ChoCSVWriter("EmpOut.csv", config)) //{ // wr.Write(new List<ExpandoObject>() { rec }); //} //List<EmployeeRec> recs = new List<EmployeeRec>(); //recs.Add(new EmployeeRec() { Id = 1, Name = "Raj" }); //recs.Add(new EmployeeRec() { Id = 2, Name = "Mark" }); //using (var stream = new MemoryStream()) //using (var reader = new StreamReader(stream)) //using (var writer = new StreamWriter(stream)) //using (var parser = new ChoCSVWriter<EmployeeRec>(writer, config)) //{ // parser.Write(recs); // writer.Flush(); // stream.Position = 0; // Console.WriteLine(reader.ReadToEnd()); //} //return; //string txt = "Id, Name\r\n1, Mark"; //foreach (var e in ChoCSVReader.LoadText(txt)) // Console.WriteLine(e.ToStringEx()); //return; //dynamic row; //using (var stream = new MemoryStream()) //using (var reader = new StreamReader(stream)) //using (var writer = new StreamWriter(stream)) //using (var parser = new ChoCSVReader(reader, config)) //{ // //writer.WriteLine("Id,Name"); // writer.WriteLine("1,Carl"); // writer.WriteLine("2,Mark"); // writer.Flush(); // stream.Position = 0; // while ((row = parser.Read()) != null) // { // Console.WriteLine(row.Id); // } //} //return; //DataTable dt = new ChoCSVReader<EmployeeRec>("Emp.csv").AsDataTable(); //var z = dt.Rows.Count; //return; foreach (var item in new ChoCSVReader <EmployeeRec>("Emp.csv")) { Console.WriteLine(item.ToStringEx()); } return; //var reader = new ChoCSVReader<EmployeeRec>("Emp.csv"); //var rec = (object)null; //while ((rec = reader.Read()) != null) // Console.WriteLine(rec.ToStringEx()); //var config = new ChoCSVRecordConfiguration(typeof(EmployeeRec)); //var e = new ChoCSVReader("Emp.csv", config); //dynamic i; //while ((i = e.Read()) != null) // Console.WriteLine(i.Id); ChoETLFramework.Initialize(); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader <EmployeeRec>(reader)) { writer.WriteLine("Id,Name"); writer.WriteLine("1,Carl"); writer.WriteLine("2,Mark"); writer.Flush(); stream.Position = 0; //var dr = parser.AsDataReader(); //while (dr.Read()) //{ // Console.WriteLine(dr[0]); //} object row1 = null; //parser.Configuration.ColumnCountStrict = true; while ((row1 = parser.Read()) != null) { Console.WriteLine(row1.ToStringEx()); } } }
static void PullMatches(string displayedDate) { var reader = new ChoCSVReader("27612-precipitation-data.csv").WithFirstLineHeader(); dynamic rec; while ((rec = reader.Read()) != null) { if (rec.DATE != null && rec.PRCP != null) { string dataDate = rec.DATE; dataDate = dataDate.Substring(0, dataDate.Length - 4); if (dataDate == displayedDate) { int count = 0; string date = rec.DATE; string prcp = rec.PRCP; if (DatesSeen.Contains(date)) { int combine = DatesSeen.IndexOf(date); string checkAmount = Convert.ToString(combine); if (DupeValues.Count != 0) { int primaryCount = DupeValues.Count; for (int dupeCounter = 0; dupeCounter < DupeValues.Count; dupeCounter++) { if (DupeValues[dupeCounter].Contains(checkAmount)) { string dupeString = DupeValues[dupeCounter]; string[] valuesArray = new string[2]; valuesArray = dupeString.Split(","); int dupeNumber = Convert.ToInt32(valuesArray[1]); dupeNumber = dupeNumber + 1; valuesArray[1] = Convert.ToString(dupeNumber); dupeString = string.Join(",", valuesArray); DupeValues[dupeCounter] = dupeString; int finalCount = DupeValues.Count; if (finalCount > primaryCount) { int subtractAmount = finalCount - primaryCount; DupeValues.RemoveAt(subtractAmount - 1); } } else { string dupeString = $"{checkAmount}, 1"; DupeValues.Add(dupeString); } } } else { string dupeString = $"{checkAmount}, 1"; DupeValues.Add(dupeString); } string recordedPrcp = RainSeen[combine]; double oldValue = Convert.ToDouble(recordedPrcp); double newValue = Convert.ToDouble(prcp); double rainTotal = oldValue + newValue; string newRain = Convert.ToString(rainTotal); RainSeen[combine] = newRain; } else { DatesSeen.Add(date); RainSeen.Add(prcp); } count = DatesSeen.Count - 1; } } } return; }
static void Main(string[] args) { //string v = @"4,'123\r\n4,abc'"; //foreach (var ss in v.SplitNTrim(",", ChoStringSplitOptions.None, '\'')) // Console.WriteLine(ss + "-"); //return; dynamic rec = new ExpandoObject(); rec.Id = 1; rec.Name = "Raj"; using (var wr = new ChoCSVWriter("EmpOut.csv")) { wr.Write(new List <ExpandoObject>() { rec }); } return; ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); //config.AutoDiscoverColumns = false; config.CSVFileHeaderConfiguration.HasHeaderRecord = true; config.ThrowAndStopOnMissingField = true; //config.MapRecordFields<EmployeeRec>(); //config.RecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1)); //config.RecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); //dynamic row; //using (var stream = new MemoryStream()) //using (var reader = new StreamReader(stream)) //using (var writer = new StreamWriter(stream)) //using (var parser = new ChoCSVReader(reader, config)) //{ // writer.WriteLine("Id,Name"); // writer.WriteLine("1,Carl"); // writer.WriteLine("2,Mark"); // writer.Flush(); // stream.Position = 0; // while ((row = parser.Read()) != null) // { // Console.WriteLine(row.Id); // } //} //return; //DataTable dt = new ChoCSVReader<EmployeeRec>("Emp.csv").AsDataTable(); //var z = dt.Rows.Count; //return; foreach (var e in new ChoCSVReader <EmployeeRec>("Emp.csv")) { Console.WriteLine(e.ToStringEx()); } return; //var reader = new ChoCSVReader<EmployeeRec>("Emp.csv"); //var rec = (object)null; //while ((rec = reader.Read()) != null) // Console.WriteLine(rec.ToStringEx()); //var config = new ChoCSVRecordConfiguration(typeof(EmployeeRec)); //var e = new ChoCSVReader("Emp.csv", config); //dynamic i; //while ((i = e.Read()) != null) // Console.WriteLine(i.Id); ChoETLFramework.Initialize(); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader <EmployeeRec>(reader)) { writer.WriteLine("Id,Name"); writer.WriteLine("1,Carl"); writer.WriteLine("2,Mark"); writer.Flush(); stream.Position = 0; //var dr = parser.AsDataReader(); //while (dr.Read()) //{ // Console.WriteLine(dr[0]); //} object row = null; //parser.Configuration.ColumnCountStrict = true; while ((row = parser.Read()) != null) { Console.WriteLine(row.ToStringEx()); } } }
static void Main(string[] args) { ChoCSVRecordConfiguration config = new ChoCSVRecordConfiguration(); config.RecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Id", 1)); config.RecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration("Name", 2)); dynamic row; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader(reader, config)) { writer.WriteLine("1,Carl"); writer.WriteLine("2,Mark"); writer.Flush(); stream.Position = 0; while ((row = parser.Read()) != null) { Console.WriteLine(row.Name); } } return; //DataTable dt = new ChoCSVReader<EmployeeRec>("Emp.csv").AsDataTable(); //var z = dt.Rows.Count; //return; //foreach (var e in new ChoCSVReader<EmployeeRec>("Emp.csv")) // Console.WriteLine(e.ToStringEx()); //var reader = new ChoCSVReader<EmployeeRec>("Emp.csv"); //var rec = (object)null; //while ((rec = reader.Read()) != null) // Console.WriteLine(rec.ToStringEx()); //var config = new ChoCSVRecordConfiguration(typeof(EmployeeRec)); //var e = new ChoCSVReader("Emp.csv", config); //dynamic i; //while ((i = e.Read()) != null) // Console.WriteLine(i.Id); ChoETLFramework.Initialize(); using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVReader <EmployeeRec>(reader)) { //writer.WriteLine("Id,Name"); writer.WriteLine("1,Carl"); writer.WriteLine("2,Mark"); writer.Flush(); stream.Position = 0; var dr = parser.AsDataReader(); while (dr.Read()) { Console.WriteLine(dr[0]); } //object row = null; //parser.Configuration.ColumnCountStrict = true; //while ((row = parser.Read()) != null) //{ // Console.WriteLine(row.ToStringEx()); //} } }