Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public RowEditorWindow(ImportStagingService service, int rowId, List<ImportFieldMapping> mappings, DataRowView row)
        {
            InitializeComponent();
            this.Service = service;
            this.RowID = rowId;
            this.Row = row;
            this.Mappings = mappings;

            int rowIndex = 0;
            foreach (ImportFieldMapping mapping in mappings) {

                gridFields.RowDefinitions.Add(CreateRowDefinition());

                var lbl = new Label();
                lbl.SetValue(Grid.RowProperty, rowIndex);
                lbl.Content = mapping.SourceColumn;
                gridFields.Children.Add(lbl);

                var txt = new Extensibility.TextBox();
                txt.SetValue(Grid.ColumnProperty, 1);
                txt.SetValue(Grid.RowProperty, rowIndex);
                txt.Height = 23;
                var objValue = row[mapping.SourceColumn];
                var strValue = (objValue == null ? "" : objValue.ToString());

                var value = new FieldValue(mapping.TargetColumn, strValue);

                var binding = new Binding("Value");
                binding.Source = value;
                binding.ValidatesOnDataErrors = true;

                txt.SetBinding(TextBox.TextProperty, binding);

                // txt.Text = strValue;

                var fieldMapping = mapping; // need to keep a copy of this mapping so its captured in the closure

                txt.TextChanged += new TextChangedEventHandler((source, e) => {

                    var textbox = source as TextBox;
                    if (textbox.Text != strValue) {
                        _changeMap[fieldMapping.SourceColumn] = textbox.Text;
                    } else {
                        if (_changeMap.ContainsKey(fieldMapping.SourceColumn)) {
                            _changeMap.Remove(fieldMapping.SourceColumn);
                        }
                    }
                });

                gridFields.Children.Add(txt);

                rowIndex++;
            }
        }
Ejemplo n.º 3
0
        public override List<string> GetColumnNames()
        {
            var service = new ImportStagingService(_options.Filename);
            var mappings = service.GetMappings();
            service.Dispose();
            _columnNames = new List<string>(mappings.Select((mapping) => {
                return mapping.SourceColumn;
            }));

            return _columnNames;
        }
Ejemplo n.º 4
0
        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;
        }
        public ErrorDatabaseImportOptionsWindow(ErrorDatabaseImporterOptions options, ImportWizardContext context)
        {
            InitializeComponent();
            _service = new ImportStagingService(options.Filename);
            Options = options;
            Context = context;

            _mappings = _service.GetMappings();

            dataGrid.AutoGenerateColumns = false;

            foreach (ImportFieldMapping mapping in _mappings) {
                dataGrid.Columns.Add(CreateColumn(mapping));
            }

            var ds = _service.GetErrorsDataSet();
            dataGrid.ItemsSource = ds.Tables[0].DefaultView;
            dataGrid.IsReadOnly = true;
            dataGrid.MouseDoubleClick += new MouseButtonEventHandler(dataGrid_MouseDoubleClick);
        }
Ejemplo n.º 6
0
        public override ImportRowSource CreateRowSource(IProgressObserver progress)
        {
            var errorSource = new ImportStagingService(_options.Filename);

            var service = new ImportStagingService();
            service.CreateImportTable(_columnNames);
            int rowcount = 0;
            var reader = errorSource.GetErrorReader();

            while (reader.Read()) {
                var values = new List<String>();
                for (int i = 0; i < reader.FieldCount - 1; ++i) {
                    var val = reader[i];
                    values.Add(val == null ? null : val.ToString());
                }
                service.InsertImportRow(values);
                rowcount++;
            }

            return new ImportRowSource(service, rowcount);
        }
Ejemplo n.º 7
0
 public BVPImportSourceBuilder(String filename)
 {
     this.Filename = filename;
     this.Service  = new ImportStagingService();
 }
Ejemplo n.º 8
0
        public override ImportRowSource CreateRowSource(IProgressObserver progress)
        {
            if (_options == null) {
                throw new Exception("Null or incorrect options type received!");
            }

            ImportRowSource rowsource = null;

            var columnNames = GetColumnNames();
            var service = new ImportStagingService();
            service.CreateImportTable(columnNames);

            if (WithWorksheetDataTable(_options.Filename, string.Format("SELECT * FROM [{0}]", _options.Worksheet), (dt) => {

                service.BeginTransaction();
                var values = new List<string>();
                int rowcount = 0;
                foreach (DataRow row in dt.Rows) {
                    values.Clear();
                    foreach (DataColumn col in dt.Columns) {
                        var value = row[col];
                        values.Add((value == null ? "" : value.ToString()));
                    }
                    service.InsertImportRow(values);
                    rowcount++;
                }

                service.CommitTransaction();

                rowsource = new ImportRowSource(service, rowcount);

            })) {
                return rowsource;
            }

            return null;
        }
Ejemplo n.º 9
0
        public override ImportRowSource CreateRowSource(IProgressObserver progress)
        {
            if (_options == null) {
                throw new Exception("Null or incorrect options type received!");
            }

            ImportRowSource rowsource = null;
            var service = new ImportStagingService();
            int rowCount = 0;
            var values = new List<string>();

            if (progress != null) {
                progress.ProgressMessage(String.Format("Importing data - Stage 1 Connecting to input source...", rowCount));
            }

            WithExcelWorksheetRows(_options.Filename, _options.Worksheet, 0, row => {
                if (rowCount == 0) {
                    var columnNames = new List<String>();
                    foreach (DataColumn column in row.Table.Columns) {
                        columnNames.Add(column.ColumnName);
                    }
                    service.CreateImportTable(columnNames);
                    service.BeginTransaction();
                }
                values.Clear();
                foreach (DataColumn col in row.Table.Columns) {
                    var value = row[col];
                    values.Add((value == null ? "" : value.ToString()));
                }
                service.InsertImportRow(values);
                if (++rowCount % 1000 == 0) {
                    if (progress != null) {
                        progress.ProgressMessage(String.Format("Importing data - Stage 1 {0} rows copied to staging database...", rowCount));
                    }
                };
            });

            service.CommitTransaction();
            rowsource = new ImportRowSource(service, rowCount);
            return rowsource;
        }
Ejemplo n.º 10
0
 public ImportRowSource(ImportStagingService service, int? rowcount)
 {
     this.Reader = service.GetImportReader();
     this.RowCount = rowcount;
     this.Service = service;
 }