private SeparatedValueReader(TextReader reader, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (hasSchema && schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }
            if (options == null)
            {
                options = new SeparatedValueOptions();
            }
            if (options.RecordSeparator == options.Separator)
            {
                throw new ArgumentException(Resources.SameSeparator, nameof(options));
            }
            RetryReader retryReader = new RetryReader(reader);

            parser   = new SeparatedValueRecordParser(retryReader, options);
            metadata = new SeparatedValueRecordContext()
            {
                ExecutionContext = new SeparatedValueExecutionContext()
                {
                    Schema  = hasSchema ? schema : null,
                    Options = parser.Options
                }
            };
        }
Beispiel #2
0
        private SeparatedValueReader(TextReader reader, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (hasSchema && schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }
            if (options == null)
            {
                options = new SeparatedValueOptions();
            }
            if (options.RecordSeparator == options.Separator)
            {
                throw new ArgumentException(SharedResources.SameSeparator, nameof(options));
            }
            RetryReader retryReader = new RetryReader(reader);

            this.parser = new SeparatedValueRecordParser(retryReader, options);
            if (hasSchema)
            {
                this.schema = schema;
            }
        }
Beispiel #3
0
 public SeparatedValueRecordParser(RetryReader reader, SeparatedValueOptions options)
 {
     this.reader            = reader;
     Options                = options.Clone();
     separatorMatcher       = SeparatorMatcher.GetMatcher(reader, options.Separator);
     recordSeparatorMatcher = SeparatorMatcher.GetMatcher(reader, options.RecordSeparator);
     if (options.RecordSeparator != null && options.RecordSeparator.StartsWith(options.Separator))
     {
         string postfix = options.RecordSeparator.Substring(options.Separator.Length);
         postfixMatcher = SeparatorMatcher.GetMatcher(reader, postfix);
     }
     separatorLength = Math.Max(Options.RecordSeparator?.Length ?? 2, Options.Separator.Length);
 }
 public SeparatedValueRecordParser(RetryReader reader, SeparatedValueOptions options)
 {
     this.reader                 = reader;
     this.options                = options.Clone();
     this.separatorMatcher       = getMatcher(options.Separator);
     this.recordSeparatorMatcher = getMatcher(options.RecordSeparator);
     if (options.RecordSeparator.StartsWith(options.Separator))
     {
         string postfix = options.RecordSeparator.Substring(options.Separator.Length);
         this.postfixMatcher = getMatcher(postfix);
     }
     this.token = new StringBuilder();
 }
Beispiel #5
0
 public SeparatedValueRecordParser(RetryReader reader, SeparatedValueOptions options)
 {
     this.reader                 = reader;
     this.options                = options.Clone();
     this.separatorMatcher       = SeparatorMatcher.GetMatcher(reader, options.Separator);
     this.recordSeparatorMatcher = SeparatorMatcher.GetMatcher(reader, options.RecordSeparator);
     if (options.RecordSeparator != null && options.RecordSeparator.StartsWith(options.Separator))
     {
         string postfix = options.RecordSeparator.Substring(options.Separator.Length);
         this.postfixMatcher = SeparatorMatcher.GetMatcher(reader, postfix);
     }
     this.separatorLength = Math.Max(this.options.RecordSeparator?.Length ?? 2, this.options.Separator.Length);
     this.tokens          = new List <string>();
     this.token           = new StringBuilder();
 }
Beispiel #6
0
 public static ISeparatorMatcher GetMatcher(RetryReader reader, string separator)
 {
     if (separator == null)
     {
         return(new DefaultSeparatorMatcher(reader));
     }
     else if (separator.Length == 1)
     {
         return(new OneCharacterSeparatorMatcher(reader, separator[0]));
     }
     else if (separator.Length == 2)
     {
         return(new TwoCharacterSeparatorMatcher(reader, separator[0], separator[1]));
     }
     else
     {
         return(new StringSeparatorMatcher(reader, separator));
     }
 }
Beispiel #7
0
        private SeparatedValueReader(TextReader reader, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (hasSchema && schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (options == null)
            {
                options = new SeparatedValueOptions();
            }
            if (options.RecordSeparator == options.Separator)
            {
                throw new ArgumentException(SharedResources.SameSeparator, "options");
            }
            RetryReader retryReader = new RetryReader(reader);

            this.parser = new SeparatedValueRecordParser(retryReader, options);
            if (hasSchema)
            {
                if (options.IsFirstRecordSchema)
                {
                    skip();  // skip header record
                }
                this.schema = schema;
            }
            else if (options.IsFirstRecordSchema)
            {
                string[] columnNames = readNextRecord();
                this.schema = new SeparatedValueSchema();
                foreach (string columnName in columnNames)
                {
                    StringColumn column = new StringColumn(columnName);
                    this.schema.AddColumn(column);
                }
            }
        }
Beispiel #8
0
 public SeparatorRecordReader(TextReader reader, string separator)
 {
     this.reader  = new RetryReader(reader);
     this.matcher = SeparatorMatcher.GetMatcher(this.reader, separator);
     this.builder = new StringBuilder();
 }
 public Matcher(RetryReader reader, string separator)
 {
     this.reader    = reader;
     this.separator = separator;
 }
 public Matcher2(RetryReader reader, char first, char second)
 {
     this.reader = reader;
     this.first  = first;
     this.second = second;
 }
 public Matcher1(RetryReader reader, char first)
 {
     this.reader = reader;
     this.first  = first;
 }
Beispiel #12
0
 public RetryState(RetryReader reader)
 {
     this.reader = reader;
     this.retry  = reader.retry;
 }
Beispiel #13
0
 public ReaderState(RetryReader reader)
 {
     this.reader     = reader;
     this.textReader = reader.reader;
 }
Beispiel #14
0
 public TwoCharacterSeparatorMatcher(RetryReader reader, char first, char second)
 {
     this.reader = reader;
     this.first  = first;
     this.second = second;
 }
Beispiel #15
0
 public OneCharacterSeparatorMatcher(RetryReader reader, char first)
 {
     this.reader = reader;
     this.first  = first;
 }
Beispiel #16
0
 public DefaultSeparatorMatcher(RetryReader reader)
 {
     this.reader = reader;
 }