示例#1
0
        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());
                    }
        }
示例#2
0
        private void Init()
        {
            if (Configuration == null)
            {
                Configuration = new ChoCSVRecordConfiguration(typeof(T));
            }

            _writer = new ChoCSVRecordWriter(typeof(T), Configuration);
        }
示例#3
0
        private void Init()
        {
            if (Configuration == null)
            {
                Configuration = new ChoCSVRecordConfiguration(typeof(T));
            }

            _writer              = new ChoCSVRecordWriter(typeof(T), Configuration);
            _writer.RowsWritten += NotifyRowsWritten;
        }
示例#4
0
        private void Init()
        {
            var recordType = typeof(T).ResolveRecordType();

            if (Configuration == null)
            {
                Configuration = new ChoCSVRecordConfiguration(recordType);
            }

            _writer              = new ChoCSVRecordWriter(recordType, Configuration);
            _writer.RowsWritten += NotifyRowsWritten;
        }
示例#5
0
        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());
                    }
        }
示例#6
0
        public void Write(IEnumerable <T> records)
        {
            ChoCSVRecordWriter writer = new ChoCSVRecordWriter(typeof(T), Configuration);

            writer.WriteTo(_txtWriter, records).Loop();
        }