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);
        }
        public int Run()
        {
            var connectionId = _connectionIdArg.Value;
            var tables       = _tablesArg.Value;
            var storage      = new ConnectionStorage(_options.ConfigFilePath);
            var connection   = storage.Get(connectionId);

            if (connection is null)
            {
                Console.WriteLine($"Connection not found: {connectionId}");
                return(-1);
            }

            connection.Tables = tables;
            storage.AddUpdate(connectionId, connection);

            storage.SaveChanges();

            if (!string.IsNullOrEmpty(tables))
            {
                Console.WriteLine($"The connection [{connectionId}] is now filtered by tables: " + tables);
            }
            else
            {
                Console.WriteLine($"The connection's ({connectionId}) filter has been cleared");
            }

            return(0);
        }
Example #3
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);
        }
Example #4
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 dbSeeder   = GetDbSeeder();
            var unpacker   = GetUnpacker();
            var dsImported = GetDatasetImporter();

            Console.WriteLine($"Importing data to [{_arguments.ConnectionId}]...");
            new DbImporter(dbSeeder, dsImported, unpacker).Import();
            Console.WriteLine("Import completed!");

            return(0);
        }
Example #5
0
        public int Run()
        {
            var connectionId = _connectionIdArg.Value;
            var storage      = new ConnectionStorage(_options.ConfigFilePath);
            var info         = storage.Get(connectionId);

            if (info == null)
            {
                Console.WriteLine("Connection not found: " + 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 bridgeSelect = DbBridgeFactory.Create(_connection);
            var bridgeUpdate = DbBridgeFactory.Create(ConnectionFactory.Create(info));

            var tableNameDate  = _columnDateArg.Value.Substring(0, _columnDateArg.Value.IndexOf('.'));
            var columnNameDate = _columnDateArg.Value.Substring(_columnDateArg.Value.IndexOf('.') + 1);

            var dataSets    = bridgeSelect.GetDatasets();
            var mainDataSet = dataSets.First(ds => ds.Name.Equals(tableNameDate, StringComparison.InvariantCultureIgnoreCase));

            var reader = bridgeSelect.GetDataReaderForSql($"SELECT MAX({bridgeSelect.GetFormattedColumnName(columnNameDate)}) FROM {bridgeSelect.GetFormattedTableName(mainDataSet)}");

            reader.Read();
            var maxDate = reader.GetDateTime(0);

            reader.Close();

            var deltaYear = DateTime.Now.Year - maxDate.Year;

            Console.WriteLine("Delta year: " + deltaYear);

            if (deltaYear < 0)
            {
                return(0);
            }

            foreach (var dataSet in dataSets)
            {
                if (!(filter is null || filter(dataSet)))
                {
                    continue;
                }

                var count = 0;
                try {
                    Console.WriteLine($"Updating: {dataSet.Name}...");
                    bridgeUpdate.StartUpdating(dataSet);
                    using (reader = bridgeSelect.GetDataReaderForTable(dataSet)) {
                        while (reader.Read())
                        {
                            var record = new DataRecord();
                            FillDataRecord(record, reader, deltaYear);
                            bridgeUpdate.UpdateRecord(record);
                            count++;
                        }
                    }
                }
                finally {
                    Console.WriteLine("Updated: " + count);
                    bridgeUpdate.FinishUpdating();
                }
            }

            return(0);
        }