Esempio n. 1
0
 /// <summary>
 /// Регистрация секции базы данных.
 /// </summary>
 /// <param name="info">Информация о цекции бд.</param>
 /// <returns>Элемент управления секцией бд. </returns>
 public DbSectionProxy RegisterDbSection(DbSectionInfo info)
 {
     if (info == null) throw new ArgumentNullException("info");
     var fullSectionInfo = new DbSection(info, () => Resolve(info.DbSectionId));
     //if already registered: return registered proxy.
     if (!_dbSections.TryAdd(info.DbSectionId, fullSectionInfo))
     {
         DbSection dbSection;
         if (_dbSections.TryGetValue(info.DbSectionId, out dbSection))
         {
             return dbSection.Proxy;
         }
     }
     return fullSectionInfo.Proxy;
 }
Esempio n. 2
0
 private void UpdateDbSection(DbSection section)
 {
     var updateScripts = GetUpdateScripts(section.DbSectionInfo.RequiredVersion,
                                  section.CurrentDbSectionState.SectionVersion, section.DbSectionInfo.DbScripts.UpdateScripts);
     _dbProvider.TryUpdateSection(section.DbSectionInfo.DbSectionId, updateScripts);
 }
Esempio n. 3
0
 private void CreateDbSection(DbSection section)
 {
     _dbProvider.TryCreateSection(section.DbSectionInfo.DbSectionId, section.DbSectionInfo.DbScripts.CreateScript);
 }
Esempio n. 4
0
 /// <summary>
 /// Попытка разрешить конфликтов секции бд.
 /// </summary>
 /// <param name="section">Инфорация о секции</param>
 private void ResolveSection(DbSection section)
 {
     switch (section.CurrentDbSectionState.DbSectionStatus)
     {
         case DbSectionStatus.Ok:
         case DbSectionStatus.Newer:
         case DbSectionStatus.Unknown:
         case DbSectionStatus.Error:
             break;
         case DbSectionStatus.NotExists:
             CreateDbSection(section);
             break;
         case DbSectionStatus.Outdated:
             UpdateDbSection(section);
             break;
         default:
             LogManager.ExceptionLog.Error("Wrong Section State");
             break;
     }
 }
Esempio n. 5
0
 private void UpdateDataBase(DbSection section)
 {
     var baseStructureScripts = _dbProvider.GetDbSchemaScripts();
     var updateScripts = GetUpdateScripts(_dbControllerVersion, section.CurrentDbSectionState.DbState.Version, baseStructureScripts.UpdateScripts);
     _dbProvider.TryUpdate(updateScripts);
 }
Esempio n. 6
0
 private void DoResolve(DbSection sectionInfo)
 {
     switch (sectionInfo.CurrentDbSectionState.DbState.Status)
     {
         case DbStatus.Unknown:
         case DbStatus.NotAvailable:
         case DbStatus.Invalid:
             break;
         case DbStatus.Outdated:
             UpdateDataBase(sectionInfo);
             break;
         case DbStatus.NoSchema:
             CreateDbSchema();
             break;
         case DbStatus.Ok:
             ResolveSection(sectionInfo);
             break;
         case DbStatus.NotExists:
             CreateDataBase();
             break;
         default:
             LogManager.ExceptionLog.Error("wrong Db State");
             break;
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Создать элемент управления секцией БД.
 /// </summary>
 /// <param name="resolveAction">Метод, вызываемый при попытке разрешить конфликт с бд.</param>
 /// <param name="getStateFunc">Метод для получения состояния.</param>
 /// <param name="dbSection">Секцияя бд, которой управляет данный элемент. </param>
 internal DbSectionProxy(Action resolveAction, Func<DbSectionState> getStateFunc, DbSection dbSection)
 {
     _resolveAction = resolveAction;
     _getStateFunc = getStateFunc;
     dbSection.DbSectionStateChanged+=OnDbSectionStateChanged;
 }