Beispiel #1
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);
        }
Beispiel #2
0
 private IDbWriter GetDbSeeder()
 {
     return(DbBridgeFactory.Create(_connection));
 }
 private IDbReader GetDbReader()
 {
     return(DbBridgeFactory.Create(_connection));
 }