public ChoKVPReader(Stream inStream, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(inStream, "Stream"); Configuration = configuration; Init(); if (inStream is MemoryStream) { _textReader = new Lazy <TextReader>(() => new StreamReader(inStream)); } else { _textReader = new Lazy <TextReader>(() => { if (Configuration.DetectEncodingFromByteOrderMarks == null) { return(new StreamReader(inStream, Configuration.GetEncoding(inStream), false, Configuration.BufferSize)); } else { return(new StreamReader(inStream, Encoding.Default, Configuration.DetectEncodingFromByteOrderMarks.Value, Configuration.BufferSize)); } }); } //_closeStreamOnDispose = true; }
public ChoKVPRecordReader(Type recordType, ChoKVPRecordConfiguration configuration) : base(recordType) { ChoGuard.ArgumentNotNull(configuration, "Configuration"); Configuration = configuration; _callbackRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyRecordRead>(recordType); _customKVPRecord = ChoMetadataObjectCache.CreateMetadataObject <IChoNotifyKVPRecordRead>(recordType); //Configuration.Validate(); }
public ChoKVPReader(Stream inStream, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(inStream, "Stream"); Configuration = configuration; Init(); _textReader = new StreamReader(inStream, Configuration.GetEncoding(inStream), false, Configuration.BufferSize); _closeStreamOnDispose = true; }
public ChoKVPReader(TextReader textReader, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(textReader, "TextReader"); Configuration = configuration; Init(); _textReader = textReader; }
internal ChoKVPReader(IEnumerable <string> lines, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(lines, "Lines"); Configuration = configuration; Init(); _lines = lines; }
public static ChoKVPReader <T> LoadLines(IEnumerable <string> inputLines, ChoKVPRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) { var r = new ChoKVPReader <T>(inputLines, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }; r._closeStreamOnDispose = true; return(r); }
public ChoKVPReader(string filePath, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath"); Configuration = configuration; Init(); _textReader = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize); _closeStreamOnDispose = true; }
private void Init() { _enumerator = new Lazy <IEnumerator <T> >(() => GetEnumerator()); if (Configuration == null) { Configuration = new ChoKVPRecordConfiguration(typeof(T)); } else { Configuration.RecordType = typeof(T); } _prevCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = Configuration.Culture; }
public ChoKVPReader(Stream inStream, ChoKVPRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(inStream, "Stream"); Configuration = configuration; Init(); if (inStream is MemoryStream) { _textReader = new Lazy <TextReader>(() => new StreamReader(inStream)); } else { _textReader = new Lazy <TextReader>(() => new StreamReader(inStream, Configuration.GetEncoding(inStream), false, Configuration.BufferSize)); } //_closeStreamOnDispose = true; }
private void Init() { _enumerator = new Lazy <IEnumerator <T> >(() => GetEnumerator()); var recordType = typeof(T).ResolveRecordType(); if (Configuration == null) { Configuration = new ChoKVPRecordConfiguration(recordType); } else { Configuration.RecordType = recordType; } Configuration.IsDynamicObject = Configuration.RecordType.IsDynamicType(); if (!ChoETLFrxBootstrap.IsSandboxEnvironment) { _prevCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = Configuration.Culture; } }
public static ChoKVPReader <T> LoadText(string inputText, Encoding encoding = null, ChoKVPRecordConfiguration configuration = null) { var r = new ChoKVPReader <T>(inputText.ToStream(encoding), configuration); r._closeStreamOnDispose = true; return(r); }
public ChoKVPReader(ChoKVPRecordConfiguration configuration = null) { Configuration = configuration; Init(); }
public ChoKVPReader(StringBuilder sb, ChoKVPRecordConfiguration configuration = null) : this(new StringReader(sb.ToString()), configuration) { }
internal static IEnumerator <object> LoadText(Type recType, string inputText, ChoKVPRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null) { ChoKVPRecordReader rr = new ChoKVPRecordReader(recType, configuration); rr.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch; return(rr.AsEnumerable(new StreamReader(inputText.ToStream(), encoding, false, bufferSize)).GetEnumerator()); }
public static ChoKVPReader <T> LoadText(string inputText, ChoKVPRecordConfiguration config, TraceSwitch traceSwitch = null) { return(LoadText(inputText, null, config, traceSwitch)); }
public static ChoKVPReader <T> LoadText(string inputText, Encoding encoding = null, ChoKVPRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) { var r = new ChoKVPReader <T>(inputText.ToStream(encoding), configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }; r._closeStreamOnDispose = true; return(r); }
internal void Validate(ChoKVPRecordConfiguration config) { try { if (FieldName.IsNullOrWhiteSpace()) { FieldName = Name; } if (FillChar != null) { if (FillChar.Value == ChoCharEx.NUL) { throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar)); } if (config.Separator.Contains(FillChar.Value)) { throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, config.Separator)); } if (config.EOLDelimiter.Contains(FillChar.Value)) { throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of EOLDelimiter characters [{1}]".FormatString(FillChar, config.EOLDelimiter)); } } if (config.Comments != null) { if ((from comm in config.Comments where comm.Contains(FillChar.ToNString(' ')) select comm).Any()) { throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed."); } if ((from comm in config.Comments where comm.Contains(config.Separator) select comm).Any()) { throw new ChoRecordConfigurationException("One of the Comments contains Delimiter. Not allowed."); } if ((from comm in config.Comments where comm.Contains(config.EOLDelimiter) select comm).Any()) { throw new ChoRecordConfigurationException("One of the Comments contains EOLDelimiter. Not allowed."); } } if (Size != null && Size.Value <= 0) { throw new ChoRecordConfigurationException("Size must be > 0."); } if (ErrorMode == null) { ErrorMode = ChoErrorMode.ReportAndContinue; // config.ErrorMode; } if (IgnoreFieldValueMode == null) { IgnoreFieldValueMode = config.IgnoreFieldValueMode; } if (QuoteField == null) { QuoteField = config.QuoteAllFields; } } catch (Exception ex) { throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex); } }