internal static string ToText(object rec, ChoCSVRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null) { if (rec is DataTable) { StringBuilder csv = new StringBuilder(); configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(rec as DataTable); return(csv.ToString()); } else if (rec is IDataReader) { StringBuilder csv = new StringBuilder(); configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(rec as IDataReader); return(csv.ToString()); } ChoCSVRecordWriter writer = new ChoCSVRecordWriter(rec.GetType(), configuration); writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize)) { writer.WriteTo(sw, new object[] { rec }).Loop(); sw.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }
private void Init() { if (Configuration == null) { Configuration = new ChoCSVRecordConfiguration(typeof(T)); } _writer = new ChoCSVRecordWriter(typeof(T), Configuration); }
private void Init() { if (Configuration == null) { Configuration = new ChoCSVRecordConfiguration(typeof(T)); } _writer = new ChoCSVRecordWriter(typeof(T), Configuration); _writer.RowsWritten += NotifyRowsWritten; }
private void Init() { var recordType = typeof(T).ResolveRecordType(); if (Configuration == null) { Configuration = new ChoCSVRecordConfiguration(recordType); } _writer = new ChoCSVRecordWriter(recordType, Configuration); _writer.RowsWritten += NotifyRowsWritten; }
internal static string ToText(object rec, ChoCSVRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null) { ChoCSVRecordWriter writer = new ChoCSVRecordWriter(rec.GetType(), configuration); writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize)) { writer.WriteTo(sw, new object[] { rec }).Loop(); sw.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }
public void Write(IEnumerable <T> records) { ChoCSVRecordWriter writer = new ChoCSVRecordWriter(typeof(T), Configuration); writer.WriteTo(_txtWriter, records).Loop(); }