public override ImportRowSource CreateRowSource(IProgressObserver progress) { if (_options == null) { throw new Exception("Null or incorrect options type received!"); } ImportRowSource rowsource = null; using (var parser = new GenericParserAdapter(_options.Filename)) { parser.ColumnDelimiter = _options.Delimiter[0]; parser.FirstRowHasHeader = _options.FirstRowContainsNames; parser.TextQualifier = '\"'; parser.FirstRowSetsExpectedColumnCount = true; var service = new ImportStagingService(); var columnNames = new List <String>(); int rowCount = 0; service.BeginTransaction(); var values = new List <string>(); while (parser.Read()) { if (rowCount == 0) { for (int i = 0; i < parser.ColumnCount; ++i) { if (_options.FirstRowContainsNames) { columnNames.Add(parser.GetColumnName(i)); } else { columnNames.Add("Column" + i); } } service.CreateImportTable(columnNames); } values.Clear(); for (int i = 0; i < parser.ColumnCount; ++i) { values.Add(parser[i]); } service.InsertImportRow(values); rowCount++; } service.CommitTransaction(); rowsource = new ImportRowSource(service, rowCount); } return(rowsource); }
private void PreviewDataSet() { if (String.IsNullOrEmpty(Filename)) { return; } var builder = new BVPImportSourceBuilder(Filename); this.RowSource = builder.BuildRowSource(); // make a matrix of the data - for now all of it, but if it becomes too much, we can limit it to top 100 or so... var matrix = new DataMatrix(); var view = new GridView(); for (int i = 0; i < RowSource.ColumnCount; ++i) { String name = RowSource.ColumnName(i); matrix.Columns.Add(new MatrixColumn { Name = name }); var column = new GridViewColumn { Header = BuildColumnHeader(name), DisplayMemberBinding = new Binding(String.Format("[{0}]", i)) }; view.Columns.Add(column); } while (RowSource.MoveNext()) { var row = matrix.AddRow(); for (int i = 0; i < RowSource.ColumnCount; ++i) { row[RowSource.ColumnName(i)] = RowSource[i]; } } lvwPreview.ItemsSource = matrix.Rows; lvwPreview.View = view; }
public override ImportRowSource CreateRowSource(IProgressObserver progress) { if (_options == null) { throw new Exception("Null or incorrect options type received!"); } ImportRowSource rowsource = null; using (var parser = new GenericParserAdapter(_options.Filename)) { parser.ColumnDelimiter = _options.Delimiter[0]; parser.FirstRowHasHeader = _options.FirstRowContainsNames; parser.TextQualifier = '\"'; parser.FirstRowSetsExpectedColumnCount = true; var service = new ImportStagingService(); var columnNames = new List<String>(); int rowCount = 0; service.BeginTransaction(); var values = new List<string>(); while (parser.Read()) { if (rowCount == 0) { for (int i = 0; i < parser.ColumnCount; ++i) { if (_options.FirstRowContainsNames) { columnNames.Add(parser.GetColumnName(i)); } else { columnNames.Add("Column" + i); } } service.CreateImportTable(columnNames); } values.Clear(); for (int i = 0; i < parser.ColumnCount; ++i) { values.Add(parser[i]); } service.InsertImportRow(values); rowCount++; } service.CommitTransaction(); rowsource = new ImportRowSource(service, rowCount); } return rowsource; }