public void Test_Csv_To_Fixed() { using (var reader = new CsvAdapter()) { reader.FileName = Path.Combine(this.testDataPath, @"cd-Daten.txt"); reader.Enclosure = "\""; reader.Separator = ";"; using (var writer = new FixedTextAdapter()) { writer.FileName = Path.Combine(this.resultPath, "cd-Daten-Fixed.txt"); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); } } // check var targetlineCount = File.ReadLines(this.resultPath + @"cd-Daten-Fixed.txt").Count(); Assert.AreEqual(97, targetlineCount); }
public static void Sample_String_To_Sqlite() { string data = @"Name;Address;Gpnr John;Main Road; 4711 Jeffrey;;4712 Mike;Hauptstr.1;4713"; string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (Stream stream = StreamUtil.CreateStream(data)) { using (var reader = new CsvAdapter(stream)) { reader.Separator = ";"; using (var writer = new SqliteAdapter()) { writer.FileName = sampleDataPath + @"stringdata.sqlite"; writer.CreateNewFile(); writer.TableName = "Tabelle1"; if (!writer.Connect()) { throw new Exception("No connection"); } watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } } }
public static void Sample_DateFormats_Converted() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new CsvAdapter()) { reader.FileName = sampleDataPath + @"DataFormats.txt"; reader.Enclosure = "\""; reader.Separator = ";"; reader.ReadConverter.CountryColumnName = "CountryCode"; reader.ReadConverter.DefaultCulture = CultureInfo.CurrentCulture; reader.ReadConverter.ConverterDefinitions.Add(new ValueConverterDefinition("ReverseDate", typeof(DateTimeFormatConverter), "yyyyMMddHHmmss")); using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(Path.GetDirectoryName(reader.FileName), "DataFormats-Converted.txt"); writer.Enclosure = "\""; writer.Separator = ";"; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine(x.ToString()); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x, false)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }