Exemplo n.º 1
0
        private void Init()
        {
            var recordType = typeof(T).GetUnderlyingType();

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

            _writer              = new ChoYamlRecordWriter(recordType, Configuration);
            _writer.Writer       = this;
            _writer.RowsWritten += NotifyRowsWritten;
        }
Exemplo n.º 2
0
        internal static string ToText(object rec, ChoYamlRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as DataTable);
                }
                return(json.ToString());
            }
            else if (rec is IDataReader)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as IDataReader);
                }
                return(json.ToString());
            }

            ChoYamlRecordWriter writer = new ChoYamlRecordWriter(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());
                    }
        }