private async Task handleSchemaAsync() { if (recordCount != 0) { return; } if (!parser.Options.IsFirstRecordSchema) { return; } if (schema != null) { await skipAsync(); return; } string[] columnNames = await readNextRecordAsync(); schema = new SeparatedValueSchema(); foreach (string columnName in columnNames) { StringColumn column = new StringColumn(columnName); schema.AddColumn(column); } }
private IEnumerable <string> formatValues(object[] values) { if (metadata.Schema == null) { StringColumn column = new StringColumn("a"); return(values.Select(v => column.Format(v))); } else { return(metadata.Schema.FormatValues(metadata, values)); } }
private ExcelReader(string fileName, ExcelSchema schema, ExcelOptions options, bool hasSchema) { if (!File.Exists(fileName)) { throw new FileNotFoundException(Resources.FileNotFound, fileName); } if (hasSchema && schema == null) { throw new ArgumentNullException("schema"); } if (options == null) { throw new ArgumentNullException("options"); } this.options = options; string connectionString = ExcelHelpers.GetConnectionString(fileName); connection = new OleDbConnection(connectionString); connection.Open(); command = connection.CreateCommand(); command.CommandText = ExcelHelpers.GetSelectCommandText(schema, options); dataReader = command.ExecuteReader(); if (hasSchema) { if (options.IsFirstRecordSchema) { dataReader.Read(); // skip header record } this.schema = schema; } else if (options.IsFirstRecordSchema && dataReader.Read()) { object[] values = new object[dataReader.FieldCount]; dataReader.GetValues(values); int startingIndex = ExcelHelpers.GetExcelColumnIndex(options.StartingColumn ?? "A"); this.schema = new ExcelSchema(); for (int valueIndex = 0; valueIndex != values.Length; ++valueIndex) { object value = values[valueIndex]; string columnName = getColumnName(startingIndex + valueIndex, value); StringColumn column = new StringColumn(columnName); this.schema.AddColumn(column); } } }
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); } } }
private void handleSchema() { if (metadata.RecordCount != 0) { return; } if (!parser.Options.IsFirstRecordSchema) { return; } if (schemaSelector != null || metadata.Schema != null) { skip(); return; } string[] columnNames = readNextRecord(); metadata.Schema = new SeparatedValueSchema(); foreach (string columnName in columnNames) { StringColumn column = new StringColumn(columnName); metadata.Schema.AddColumn(column); } }
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); } } }