Esempio n. 1
0
        /// <summary>
        /// 当某个迁移操作升级完成后,为它添加相应的历史记录。
        /// </summary>
        /// <param name="database"></param>
        /// <param name="migration"></param>
        /// <returns></returns>
        internal Result AddAsExecuted(string database, DbMigration migration)
        {
            var history = new HistoryItem()
            {
                IsGenerated = false,
                TimeId = migration.TimeId,
                Description = migration.Description,
                MigrationClass = migration.GetType().AssemblyQualifiedName,
            };

            if (migration.MigrationType == MigrationType.AutoMigration)
            {
                history.IsGenerated = true;
                history.MigrationContent = SerializationHelper.XmlSerialize(migration);
            }

            return this.AddHistoryCore(database, history);
        }
Esempio n. 2
0
        protected override Result AddHistoryCore(string database, HistoryItem history)
        {
            var item = new DbMigrationHistory();

            item.Database = database;

            item.TimeId = history.TimeId.Ticks;
            item.Description = history.Description;
            item.IsGenerated = history.IsGenerated;
            item.MigrationClass = history.MigrationClass;
            item.MigrationContent = history.MigrationContent;

            try
            {
                this._historyRepo.Save(item);
                return true;
            }
            catch (Exception ex)
            {
                return "添加数据库更新日志 时出错:" + ex.Message;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 从历史记录中还原迁移对象
        /// </summary>
        /// <param name="history"></param>
        /// <returns></returns>
        internal DbMigration TryRestore(HistoryItem history)
        {
            Type type = null;
            try
            {
                type = Type.GetType(history.MigrationClass);
            }
            catch (TypeLoadException)
            {
                //如果当前这个类已经不存在了,无法还原,则直接返回 null,跳过该项。
                return null;
            }

            //如果这个类型已经被变更了,或者找不到,则直接返回 null
            if (type == null) { return null; }

            DbMigration migration = null;

            if (history.IsGenerated)
            {
                migration = SerializationHelper.XmlDeserialize(type, history.MigrationContent).CastTo<DbMigration>();

                (migration as MigrationOperation).RuntimeTimeId = history.TimeId;
            }
            else
            {
                migration = Activator.CreateInstance(type, true).CastTo<DbMigration>();
            }

            return migration;
        }
Esempio n. 4
0
 internal Result Remove(string database, HistoryItem history)
 {
     return this.RemoveHistoryCore(database, history);
 }
Esempio n. 5
0
 /// <summary>
 /// 为指定数据库删除某条历史记录。
 /// </summary>
 /// <param name="database"></param>
 /// <param name="history"></param>
 /// <returns></returns>
 protected abstract Result RemoveHistoryCore(string database, HistoryItem history);
Esempio n. 6
0
 /// <summary>
 /// 为指定数据库删除某条历史记录。
 /// </summary>
 /// <param name="database"></param>
 /// <param name="history"></param>
 /// <returns></returns>
 protected abstract Result RemoveHistoryCore(string database, HistoryItem history);
Esempio n. 7
0
 internal Result Remove(string database, HistoryItem history)
 {
     return(this.RemoveHistoryCore(database, history));
 }
Esempio n. 8
0
        protected override Result RemoveHistoryCore(string database, HistoryItem history)
        {
            var item = history.DataObject.CastTo<DbMigrationHistory>();

            item.PersistenceStatus = PersistenceStatus.Deleted;

            try
            {
                this._historyRepo.Save(item);
                return true;
            }
            catch (Exception ex)
            {
                return "添加数据库更新日志 时出错:" + ex.Message;
            }
        }