Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        public ChoKVPReader(TextReader textReader, ChoKVPRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNull(textReader, "TextReader");

            Configuration = configuration;
            Init();

            _textReader = textReader;
        }
Exemplo n.º 5
0
        internal ChoKVPReader(IEnumerable <string> lines, ChoKVPRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNull(lines, "Lines");

            Configuration = configuration;
            Init();

            _lines = lines;
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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;
            }
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
 public ChoKVPReader(ChoKVPRecordConfiguration configuration = null)
 {
     Configuration = configuration;
     Init();
 }
Exemplo n.º 13
0
 public ChoKVPReader(StringBuilder sb, ChoKVPRecordConfiguration configuration = null) : this(new StringReader(sb.ToString()), configuration)
 {
 }
Exemplo n.º 14
0
        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());
        }
Exemplo n.º 15
0
 public static ChoKVPReader <T> LoadText(string inputText, ChoKVPRecordConfiguration config, TraceSwitch traceSwitch = null)
 {
     return(LoadText(inputText, null, config, traceSwitch));
 }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
            }
        }