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);
        }
示例#2
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);
        }