/// <summary>
        /// Compares current generated database model (from DSL scripts)
        /// and the previously created objects in database (from metadata in table Rhetos.AppliedConcept).
        /// </summary>
        public DatabaseDiff Diff()
        {
            var stopwatch = Stopwatch.StartNew();

            var oldApplications = _conceptApplicationRepository.Load();

            _performanceLogger.Write(stopwatch, "Loaded old concept applications.");

            var newApplications = ConceptApplication.FromDatabaseObjects(_databaseModel.DatabaseObjects);

            _performanceLogger.Write(stopwatch, "Got new concept applications.");

            MatchAndComputeNewApplicationIds(oldApplications, newApplications);
            _performanceLogger.Write(stopwatch, "Match new and old concept applications.");

            ConceptApplication.CheckKeyUniqueness(newApplications, "generated, after matching");
            _performanceLogger.Write(stopwatch, "Verify new concept applications' integrity.");

            newApplications = TrimEmptyApplications(newApplications);
            _performanceLogger.Write(stopwatch, "Removed unused concept applications.");

            var diff = CalculateApplicationsToBeRemovedAndInserted(oldApplications, newApplications);

            _performanceLogger.Write(stopwatch, "Analyzed differences in database structure.");
            return(diff);
        }
Esempio n. 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;
            }
        }
Esempio n. 3
0
 private void VerifyIntegrity()
 {
     try
     {
         _conceptApplicationRepository.Load();
     }
     catch (Exception ex)
     {
         throw new FrameworkException("Metadata integrity error after applying changes to database. " + ex.Message, ex);
     }
 }