예제 #1
0
 private SeparatedValueReader(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema, bool ownsStream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (hasSchema && schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     reader = new RecordReader(stream, options.Encoding, options.RecordSeparator, ownsStream);
     regex  = buildRegex(options.Separator);
     if (hasSchema)
     {
         if (options.IsFirstRecordSchema)
         {
             readNextRecord();  // 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);
         }
     }
 }
예제 #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(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
                }
            };
        }
예제 #3
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;
            }
        }
 public SeparatedValueRecordWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options)
 {
     this.writer            = writer;
     this.schema            = schema;
     this.options           = options.Clone();
     this.quoteString       = String.Empty + options.Quote;
     this.doubleQuoteString = String.Empty + options.Quote + options.Quote;
 }
예제 #5
0
 private SeparatedValueComplexColumn(string columnName, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
     : base(columnName)
 {
     if (hasSchema && schema == null)
     {
         throw new ArgumentNullException(nameof(schema));
     }
     this.schema = schema;
     Options     = options;
 }
 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();
 }
예제 #7
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();
 }
예제 #9
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();
 }
예제 #10
0
 private SeparatedValueWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (hasSchema && schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         options = new SeparatedValueOptions();
     }
     this.recordWriter = new SeparatedValueRecordWriter(writer, schema, options);
 }
예제 #11
0
 /// <summary>
 /// Initializes a new SeparatedValueWriter with the given schema.
 /// </summary>
 /// <param name="writer">A writer over the separated value document.</param>
 /// <param name="injector">The schema injector to use to determine the schema.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="ArgumentNullException">The writer is null.</exception>
 /// <exception cref="ArgumentNullException">The schema injector is null.</exception>
 public SeparatedValueWriter(TextWriter writer, SeparatedValueSchemaInjector injector, SeparatedValueOptions options = null)
 {
     if (writer == null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     if (injector == null)
     {
         throw new ArgumentNullException(nameof(injector));
     }
     if (options == null)
     {
         options = new SeparatedValueOptions();
     }
     recordWriter = new SeparatedValueRecordWriter(writer, injector, options);
 }
예제 #12
0
        //[Benchmark]
        public void FlatFilesCsv()
        {
            var tr   = TestData.GetTextReader();
            var opts = new FlatFiles.SeparatedValueOptions()
            {
                IsFirstRecordSchema = true
            };
            var dr = new FlatFiles.FlatFileDataReader(new FlatFiles.SeparatedValueReader(tr, opts));

            while (dr.Read())
            {
                for (int i = 0; i < dr.FieldCount; i++)
                {
                    var s = dr.GetValue(i);
                }
            }
        }
예제 #13
0
 private SeparatedValueWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (hasSchema && schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         options = new SeparatedValueOptions();
     }
     this.recordWriter = new SeparatedValueRecordWriter(writer, schema, options);
     this.isFirstLine = true;
 }
예제 #14
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);
                }
            }
        }
예제 #15
0
 private SeparatedValueWriter(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options, bool ownsStream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     this.writer              = new StreamWriter(stream, options.Encoding ?? Encoding.Default);
     this.ownsStream          = ownsStream;
     this.schema              = schema;
     this.isFirstRecordSchema = options.IsFirstRecordSchema;
     this.separator           = options.Separator;
     this.recordSeparator     = options.RecordSeparator;
     this.isFirstLine         = true;
 }
 private SeparatedValueWriter(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options, bool ownsStream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     this.writer = new StreamWriter(stream, options.Encoding ?? Encoding.Default);
     this.ownsStream = ownsStream;
     this.schema = schema;
     this.isFirstRecordSchema = options.IsFirstRecordSchema;
     this.separator = options.Separator;
     this.recordSeparator = options.RecordSeparator;
     this.isFirstLine = true;
 }
예제 #17
0
 public SeparatedValueRecordWriter(TextWriter writer, SeparatedValueSchemaInjector injector, SeparatedValueOptions options)
     : this(writer, (SeparatedValueSchema)null, options)
 {
     this.injector = injector;
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueWriter.
 /// </summary>
 /// <param name="fileName">The name of the file to write to.</param>
 /// <param name="schema">The schema to use to build the output.</param>
 /// <param name="options">The options to use to format the output.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 public SeparatedValueWriter(string fileName, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(File.OpenWrite(fileName), schema, options, true)
 {
 }
예제 #19
0
 /// <summary>
 /// Initializes a new SeparatedValueWriter without a schema.
 /// </summary>
 /// <param name="writer">A writer over the separated value document.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="ArgumentNullException">The writer is null.</exception>
 public SeparatedValueWriter(TextWriter writer, SeparatedValueOptions options = null)
     : this(writer, null, options, false)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="fileName">The path of the file containing the records to extract.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The options object is null.</exception>
 public SeparatedValueReader(string fileName, SeparatedValueOptions options)
     : this(File.OpenRead(fileName), null, options, false, true)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="stream">A stream containing the records to parse.</param>
 /// <param name="schema">The predefined schema for the records.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueReader(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(stream, schema, options, true, false)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueWriter.
 /// </summary>
 /// <param name="stream">The stream to write the output to.</param>
 /// <param name="schema">The schema to use to build the output.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueWriter(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(stream, schema, options, false)
 {
 }
예제 #23
0
 /// <summary>
 /// Initializes a new SeparatedValueComplexColumn with no schema.
 /// </summary>
 /// <param name="columnName">The name of the column.</param>
 /// <param name="options">The options to use when parsing the embedded data.</param>
 public SeparatedValueComplexColumn(string columnName, SeparatedValueOptions options = null)
     : this(columnName, null, options, false)
 {
 }
예제 #24
0
 public SeparatedValueRecordWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options)
 {
     this.writer   = writer;
     this.metadata = new SeparatedValueMetadata()
     {
         Schema  = schema,
         Options = options.Clone()
     };
     this.quoteString       = String.Empty + options.Quote;
     this.doubleQuoteString = String.Empty + options.Quote + options.Quote;
 }
예제 #25
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="stream">A stream containing the records to parse.</param>
 /// <param name="schema">The predefined schema for the records.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueReader(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(stream, schema, options, true, false)
 {
 }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="fileName">The path of the file containing the records to extract.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The options object is null.</exception>
 public SeparatedValueReader(string fileName, SeparatedValueOptions options)
     : this(File.OpenRead(fileName), null, options, false, true)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueWriter.
 /// </summary>
 /// <param name="fileName">The name of the file to write to.</param>
 /// <param name="schema">The schema to use to build the output.</param>
 /// <param name="options">The options to use to format the output.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 public SeparatedValueWriter(string fileName, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(File.OpenWrite(fileName), schema, options, true)
 {
 }
예제 #28
0
 /// <summary>
 /// Initializes a new SeparatedValueComplexColumn with the given schema and options.
 /// </summary>
 /// <param name="columnName">The name of the column.</param>
 /// <param name="schema">The schema of the data embedded in the column.</param>
 /// <param name="options">The options to use when parsing the embedded data.</param>
 public SeparatedValueComplexColumn(string columnName, SeparatedValueSchema schema, SeparatedValueOptions options = null)
     : this(columnName, schema, options, true)
 {
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="fileName">The path of the file containing the records to extract.</param>
 /// <param name="schema">The predefined schema for the records.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options object is null.</exception>
 public SeparatedValueReader(string fileName, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(File.OpenRead(fileName), schema, options, true, true)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="stream">A stream containing the records to parse.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueReader(Stream stream, SeparatedValueOptions options)
     : this(stream, null, options, false, false)
 {
 }
예제 #31
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="stream">A stream containing the records to parse.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueReader(Stream stream, SeparatedValueOptions options)
     : this(stream, null, options, false, false)
 {
 }
 private SeparatedValueReader(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema, bool ownsStream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (hasSchema && schema == null)
     {
         throw new ArgumentNullException("schema");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     reader = new RecordReader(stream, options.Encoding, options.RecordSeparator, ownsStream);
     regex = buildRegex(options.Separator);
     if (hasSchema)
     {
         if (options.IsFirstRecordSchema)
         {
             readNextRecord();  // 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);
         }
     }
 }
예제 #33
0
 /// <summary>
 /// Initializes a new SeparatedValueWriter with the given schema.
 /// </summary>
 /// <param name="writer">A writer over the separated value document.</param>
 /// <param name="schema">The schema of the separated value document.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="ArgumentNullException">The writer is null.</exception>
 /// <exception cref="ArgumentNullException">The schema is null.</exception>
 public SeparatedValueWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options = null)
     : this(writer, schema, options, true)
 {
 }
 /// <summary>
 /// Initializes a new instance of a SeparatedValueParser.
 /// </summary>
 /// <param name="fileName">The path of the file containing the records to extract.</param>
 /// <param name="schema">The predefined schema for the records.</param>
 /// <param name="options">The options for configuring the parser's behavior.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options object is null.</exception>
 public SeparatedValueReader(string fileName, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(File.OpenRead(fileName), schema, options, true, true)
 {
 }
예제 #35
0
 /// <summary>
 /// Initializes a new SeparatedValueReader with no schema.
 /// </summary>
 /// <param name="reader">A reader over the separated value document.</param>
 /// <param name="options">The options controlling how the separated value document is read.</param>
 /// <exception cref="ArgumentNullException">The reader is null.</exception>
 public SeparatedValueReader(TextReader reader, SeparatedValueOptions options = null)
     : this(reader, null, options, false)
 {
 }
예제 #36
0
 /// <summary>
 /// Initializes a new SeparatedValueWriter with the given schema.
 /// </summary>
 /// <param name="writer">A writer over the separated value document.</param>
 /// <param name="schema">The schema of the separated value document.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="ArgumentNullException">The writer is null.</exception>
 /// <exception cref="ArgumentNullException">The schema is null.</exception>
 public SeparatedValueWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options = null)
     : this(writer, schema, options, true)
 {
 }
예제 #37
0
 /// <summary>
 /// Initializes a new SeparatedValueReader with the given schema.
 /// </summary>
 /// <param name="reader">A reader over the separated value document.</param>
 /// <param name="schema">The schema of the separated value document.</param>
 /// <param name="options">The options controlling how the separated value document is read.</param>
 /// <exception cref="ArgumentNullException">The reader is null.</exception>
 /// <exception cref="ArgumentNullException">The schema is null.</exception>
 public SeparatedValueReader(TextReader reader, SeparatedValueSchema schema, SeparatedValueOptions options = null)
     : this(reader, schema, options, true)
 {
 }
예제 #38
0
 /// <summary>
 /// Initializes a new instance of a SeparatedValueWriter.
 /// </summary>
 /// <param name="stream">The stream to write the output to.</param>
 /// <param name="schema">The schema to use to build the output.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="System.ArgumentNullException">The schema is null.</exception>
 /// <exception cref="System.ArgumentNullException">The options is null.</exception>
 public SeparatedValueWriter(Stream stream, SeparatedValueSchema schema, SeparatedValueOptions options)
     : this(stream, schema, options, false)
 {
 }
예제 #39
0
 /// <summary>
 /// Initializes a new SeparatedValueReader with the given schema.
 /// </summary>
 /// <param name="reader">A reader over the separated value document.</param>
 /// <param name="schemaSelector">The schema selector configured to determine the schema dynamically.</param>
 /// <param name="options">The options controlling how the separated value document is read.</param>
 /// <exception cref="ArgumentNullException">The reader is null.</exception>
 /// <exception cref="ArgumentNullException">The schema selector is null.</exception>
 public SeparatedValueReader(TextReader reader, SeparatedValueSchemaSelector schemaSelector, SeparatedValueOptions options = null)
     : this(reader, null, options, false)
 {
     this.schemaSelector = schemaSelector ?? throw new ArgumentNullException(nameof(schemaSelector));
 }
예제 #40
0
 /// <summary>
 /// Initializes a new SeparatedValueWriter without a schema.
 /// </summary>
 /// <param name="writer">A writer over the separated value document.</param>
 /// <param name="options">The options used to format the output.</param>
 /// <exception cref="ArgumentNullException">The writer is null.</exception>
 public SeparatedValueWriter(TextWriter writer, SeparatedValueOptions options = null)
     : this(writer, null, options, false)
 {
 }
예제 #41
0
 public SeparatedValueRecordWriter(TextWriter writer, SeparatedValueSchema schema, SeparatedValueOptions options)
 {
     this.writer = writer;
     Metadata    = new SeparatedValueRecordContext()
     {
         ExecutionContext = new SeparatedValueExecutionContext()
         {
             Schema  = schema,
             Options = options.Clone()
         }
     };
     quoteString       = String.Empty + options.Quote;
     doubleQuoteString = String.Empty + options.Quote + options.Quote;
 }