Пример #1
0
        public static void Main(string[] args)
        {
            try {
                if (!ReadSettings(args))
                {
                    Console.ReadKey();
                    return;
                }

                string[] tableNames = Parameters.Singleton.Tables;

                /*new[] {
                 * "ce1bp01.2016", "ce1bp01.2017", "ce2bp01.2016", "ce2bp01.2017", "cobk.2016_001", "cobk.2017_001", "coep.2016_001", "coep.2017_001",
                 * "faglflexa.2016_001", "faglflexa.2017_001", "faglflext.2016", "faglflext.2017",
                 * "tvkot", "tvtwt", "tvkbt", "tvgrt", "t171t", "tbrct", "t179t", "t001w", "csks", "cskst", "t001", "t001b", "cska", "csku", "skat",
                 * "cepct", "setheader", "setheadert", "setnode", "setleaf", "fagl_011pc", "fagl_011zc", "fagl_011sc", "fagl_011qt", "aufk", "mara"
                 * };*/
                IOutputWriter writer = new SingleFileWriter(Parameters.Singleton.CreateFileName, Parameters.Singleton.InsertFileName);
                foreach (string tableName in tableNames)
                {
                    Console.WriteLine($"Processing file {tableName}");
                    string tableDefinition = CreateTableDefinition(tableName);
                    string formatFile;
                    string bulkInsert;
                    string create;
                    using (DataSourceFactory factory = new DataSourceFactory()) {
                        ITableDataSource        source        = factory.GetDataSourceForTable(tableName);
                        List <ColumnDefinition> colDefinition = ColumnDefinitionFactory.GetColumnDefinitionsForTable(tableDefinition)
                                                                .Where(col => source.UsesColumn(col)).ToList();
                        List <ColumnDefinition> sourceOrderedColumnDefinitions = source.Reorder(colDefinition);
                        CreateGenerator         createGenerator = new CreateGenerator(tableDefinition, colDefinition);
                        create = createGenerator.BuildCreate(out formatFile, source.IsQuoteEnclosed);
                        IInsertGenerator insertGenerator = new BulkInsertGenerator(tableDefinition, source, tableName);
                        if (source is ExcelTableDataSource)
                        {
                            insertGenerator = new InlineInsertGenerator(tableDefinition, source, colDefinition, sourceOrderedColumnDefinitions);
                        }
                        bulkInsert = insertGenerator.BuildInsert();
                    }

                    writer.TableName        = tableName;
                    writer.TableDefinition  = tableDefinition;
                    writer.CreateScript     = create;
                    writer.Format           = formatFile;
                    writer.BulkInsertScript = bulkInsert;
                    writer.Write();
                }
                Console.WriteLine("Completed all tables successfully");
            } catch (Exception e) {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }