Пример #1
0
 public DatabaseGenerator(
     ISqlExecuter sqlExecuter,
     IDslModel dslModel,
     IPluginsContainer<IConceptDatabaseDefinition> plugins,
     ConceptApplicationRepository conceptApplicationRepository,
     ILogProvider logProvider)
 {
     _sqlExecuter = sqlExecuter;
     _dslModel = dslModel;
     _plugins = plugins;
     _conceptApplicationRepository = conceptApplicationRepository;
     _logger = logProvider.GetLogger("DatabaseGenerator");
     _performanceLogger = logProvider.GetLogger("Performance");
 }
Пример #2
0
        public void UpdateDatabaseStructure()
        {
            if (DatabaseUpdated) // performance optimization
            {
                _deployPackagesLogger.Trace("Database already updated.");
            }

            lock (_databaseUpdateLock)
            {
                if (DatabaseUpdated)
                {
                    _deployPackagesLogger.Trace("Database already updated.");
                }

                _logger.Trace("Updating database structure.");
                var stopwatchTotal = Stopwatch.StartNew();
                var stopwatch      = Stopwatch.StartNew();

                var oldApplications = _conceptApplicationRepository.Load();
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Loaded old concept applications.");

                var newApplications = CreateNewApplications(oldApplications);
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Created new concept applications.");
                ConceptApplicationRepository.CheckKeyUniqueness(newApplications, "created");
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Verify new concept applications' integrity.");
                newApplications = TrimEmptyApplications(newApplications);
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Removed unused concept applications.");

                List <ConceptApplication>    toBeRemoved;
                List <NewConceptApplication> toBeInserted;
                CalculateApplicationsToBeRemovedAndInserted(oldApplications, newApplications, out toBeRemoved, out toBeInserted);
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Analyzed differences in database structure.");

                ApplyChangesToDatabase(oldApplications, newApplications, toBeRemoved, toBeInserted);
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Applied changes to database.");

                VerifyIntegrity();
                _performanceLogger.Write(stopwatch, "DatabaseGenerator: Verified integrity of saved concept applications metadata.");

                _performanceLogger.Write(stopwatchTotal, "DatabaseGenerator.UpdateDatabaseStructure");
                DatabaseUpdated = true;
            }
        }