Esempio n. 1
0
        private void Data_Migration_Click(object sender, RoutedEventArgs e)
        {
            var npgsqlLocalConnection  = new NpgsqlConnection(LocalPostgreConnectionString);
            var vanguardConnection     = new SqlConnection(SqlConnectionString);
            var npgsqlDockerConnection = new NpgsqlConnection(DockerPostgresConnectionString);

            try
            {
                npgsqlLocalConnection.Open();
                vanguardConnection.Open();
                npgsqlDockerConnection.Open();
                var totalCount = _postgresConnect.GetCountOfHistoricData(npgsqlLocalConnection);
                while (totalCount > 0)
                {
                    _logger.WriteLog(LogLevel.Info, "Get historic data from (Postgres) \n");
                    var historicalOcrData = _postgresConnect.GetPostgresHistoricData(npgsqlLocalConnection, _limit);
                    _logger.WriteLog(LogLevel.Info, "Get matching documents paths \n");
                    var historicalDocsToMigrate = historicalOcrData
                                                  .Select(i => _help.ReplaceUnsupportedCharacters(i.FullFilePath, "/", "\\")).ToList();
                    var resultXmlString  = _help.ConvertStringsToXml(historicalDocsToMigrate);
                    var vanguardDocsData = _sqlConnect.GetVanguardDocuments(vanguardConnection, resultXmlString);
                    _logger.WriteLog(LogLevel.Info, "Update documents in (Vanguard) \n");
                    _sqlConnect.UpdateDM_OCR_PROCESS(vanguardConnection, vanguardDocsData);
                    _logger.WriteLog(LogLevel.Info, "Insert data in (Postgres) \n");
                    historicalOcrData = _postgresConnect.RemoveUnmatchingHistoricData(historicalOcrData, vanguardDocsData);
                    _postgresConnect.InsertOcr(npgsqlDockerConnection, historicalOcrData, vanguardDocsData);
                    _logger.WriteLog(LogLevel.Info, "Delete data from historical_ocr (Postgres) \n");
                    _postgresConnect.RemoveHistoricalData(npgsqlLocalConnection, historicalOcrData);
                    totalCount -= _limit;
                    _logger.WriteLog(LogLevel.Info, $"{totalCount} left \n");
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLog(LogLevel.Error,
                                 "Error while trying to open connection strings. Error details: \n" + ex.Message + "\n");
            }
            finally
            {
                npgsqlLocalConnection.Close();
                npgsqlDockerConnection.Close();
                vanguardConnection.Close();
            }
        }