Exemplo n.º 1
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(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
                }
            };
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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;
 }
Exemplo n.º 12
0
 public RetryState(RetryReader reader)
 {
     this.reader = reader;
     this.retry  = reader.retry;
 }
Exemplo n.º 13
0
 public ReaderState(RetryReader reader)
 {
     this.reader     = reader;
     this.textReader = reader.reader;
 }
Exemplo n.º 14
0
 public TwoCharacterSeparatorMatcher(RetryReader reader, char first, char second)
 {
     this.reader = reader;
     this.first  = first;
     this.second = second;
 }
Exemplo n.º 15
0
 public OneCharacterSeparatorMatcher(RetryReader reader, char first)
 {
     this.reader = reader;
     this.first  = first;
 }
Exemplo n.º 16
0
 public DefaultSeparatorMatcher(RetryReader reader)
 {
     this.reader = reader;
 }