コード例 #1
0
ファイル: ChoCSVWriter.cs プロジェクト: jhrendon/ChoETL
        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
ファイル: ChoCSVWriter.cs プロジェクト: shivanan/ChoETL
        private void Init()
        {
            if (Configuration == null)
            {
                Configuration = new ChoCSVRecordConfiguration(typeof(T));
            }

            _writer              = new ChoCSVRecordWriter(typeof(T), Configuration);
            _writer.RowsWritten += NotifyRowsWritten;
        }
コード例 #4
0
ファイル: ChoCSVWriter.cs プロジェクト: jhrendon/ChoETL
        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
ファイル: ChoCSVWriter.cs プロジェクト: shivanan/ChoETL
        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
ファイル: ChoCSVWriter.cs プロジェクト: tablesmit/ChoETL
        public void Write(IEnumerable <T> records)
        {
            ChoCSVRecordWriter writer = new ChoCSVRecordWriter(typeof(T), Configuration);

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