コード例 #1
0
        public int Run()
        {
            var storage = new ConnectionStorage(_options.ConfigFilePath);
            var info    = storage.Get(_arguments.ConnectionId);

            if (info == null)
            {
                Console.WriteLine("Connection with current ID is not found: " + _arguments.ConnectionId);
                return(-1);
            }

            InitConnection(info);

            Func <DatasetInfo, bool> filter = null;

            if (!string.IsNullOrEmpty(info.Tables))
            {
                var tables = info.Tables.Split(',').ToList();
                filter = (dataSet) =>
                {
                    return(tables.Contains(dataSet.Name));
                };
            }

            var exporter = new DbExporter(GetDbReader(), GetDatasetExporter(), GetPacker(), Program.LoggerFactory);

            Console.WriteLine($"Exporting database [{_arguments.ConnectionId}]...");
            exporter.Export(filter);
            Console.WriteLine($"Export completed!");

            return(0);
        }
コード例 #2
0
 public void SetUp()
 {
     mSpecificKeeperDb = new KeeperDb();
     mSpecificResult   = new DbLoadResult(mSpecificKeeperDb);
     mDbGeneralLoader  = A.Fake <IDbGeneralLoader>();
     A.CallTo(() => mDbGeneralLoader.LoadByExtension()).Returns(mSpecificResult);
     mUnderTest = new DbExporter(mDbGeneralLoader);
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: ralph00/LoLNotes
        private void ExportButton_Click(object sender, EventArgs e)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Filter           = "json files (*.json)|*.json";
                sfd.InitialDirectory = Application.StartupPath;
                sfd.RestoreDirectory = true;

                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                using (var fs = sfd.OpenFile())
                {
                    DbExporter.Export(Version, Database, fs);
                }
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: ralph00/LoLNotes
        private void ImportButton_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter           = "json files (*.json)|*.json";
                ofd.InitialDirectory = Application.StartupPath;
                ofd.RestoreDirectory = true;

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                using (var fs = ofd.OpenFile())
                {
                    DbExporter.Import(Recorder, fs);
                }
            }
        }
コード例 #5
0
        public int Run()
        {
            var storage = new ConnectionStorage(_options.ConfigFilePath);
            var info    = storage.Get(_arguments.ConnectionId);

            if (info == null)
            {
                Console.WriteLine("Connection with current ID is not found: " + _arguments.ConnectionId);
                return(-1);
            }

            InitConnection(info);

            var exporter = new DbExporter(GetDbReader(), GetDatasetExporter(), GetPacker(), Program.LoggerFactory);

            Console.WriteLine($"Exporting database [{_arguments.ConnectionId}]...");
            exporter.Export();
            Console.WriteLine($"Export completed!");

            return(0);
        }
コード例 #6
0
        public void ExportTableToDatabase(object dataSource, Connection connection, string tableName, ExportTableToDatabaseOptions options = null)
        {
            options ??= new ExportTableToDatabaseOptions();

            const string progressDescription = "Exporting table into database";

            var dataReader = ScriptHostObject.GetDataSourceReader(dataSource,
                                                                  new DataSourceParameters()
            {
                IgnoreErrors = options.IgnoreErrors, Columns = options.SelectColumns, SkipColumns = options.SkipColumns
            });

            if ((connection.DbConnection?.State ?? ConnectionState.Closed) != ConnectionState.Open)
            {
                connection.Open();
            }

            if (options.ReportProgress)
            {
                UpdateProgress(ProgressKind.Value, 0, 100, progressDescription);
            }

            if (!string.IsNullOrWhiteSpace(options.PreScript))
            {
                ExecuteScript(connection, options.PreScript, options);
            }

            var exporter = DbExporter.GetDbExporter(connection.FactoryInvariantName);

            if (exporter == null)
            {
                throw new Exception("Cannot configure DB exporter for selected connection.");
            }

            exporter.SkipAutoID = options.SkipAutoID;

            if (options.Replace)
            {
                exporter.DropTable(connection.DbConnection, options.TableSchema, tableName);
            }

            if (!string.IsNullOrWhiteSpace(options.CreateTableScript))
            {
                ExecuteScript(connection, options.CreateTableScript, options);
            }

            if (options.BatchSize.HasValue)
            {
                exporter.BatchSize = options.BatchSize.Value;
            }

            if (options.ReportProgress)
            {
                exporter.Progress += (s, e) =>
                {
                    var percent = (e.Max > 0 && e.Progress <= e.Max) ? Convert.ToInt32(Convert.ToDouble(e.Progress) / Convert.ToDouble(e.Max)) : 50;
                    percent = Utils.ValueInRange(percent, 0, 100);
                    UpdateProgress(ProgressKind.Value, percent, 100, progressDescription);
                };
            }

            try
            {
                bool needCreateTable = !options.UseExistingTable && string.IsNullOrWhiteSpace(options.CreateTableScript);
                exporter.ExportDataTable(connection.DbConnection, dataReader,
                                         options.TableSchema, tableName, needCreateTable, CancellationToken.None);
            }
            finally
            {
                if (options.ReportProgress)
                {
                    UpdateProgress(ProgressKind.Value, 0, 100, string.Empty);
                }
            }

            if (!string.IsNullOrWhiteSpace(options.PostScript))
            {
                ExecuteScript(connection, options.PostScript, options);
            }
        }