当前位置: 首页>>代码示例>>C#>>正文


C# IMigrationContext.Rollback方法代码示例

本文整理汇总了C#中IMigrationContext.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# IMigrationContext.Rollback方法的具体用法?C# IMigrationContext.Rollback怎么用?C# IMigrationContext.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMigrationContext的用法示例。


在下文中一共展示了IMigrationContext.Rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyPatch

        /// <summary>
        /// Apply a single patch.
        /// </summary>
        /// <param name="context">
        /// the context the patch will need during application
        /// </param>
        /// <param name="task">
        /// the application task to carry out
        /// </param>
        /// <param name="broadcast">
        /// whether to broadcast to listeners that the patch applied
        /// </param>
        /// <exception cref="MigrationException">if the patch application fails </exception>
        public virtual void ApplyPatch(IMigrationContext context, IMigrationTask task, bool broadcast)
        {
            String label = GetTaskLabel(task);

            if (broadcast)
            {
                if (MigrationStarted != null)
                {
                    MigrationStarted(task, context, null);
                    //broadcaster.notifyListeners(task, context, MigrationBroadcaster.TASK_START);
                    //log.Debug("broadcaster has " + broadcaster.Listeners.Count + " listeners");
                }
            }

            log.Info("Running migration task \"" + label + "\"...");
            //Console.WriteLine("Running migration task \"" + label + "\"...");

            try
            {
                long startTime = DateTime.Now.Ticks;
                MigrateTask(context, task);
                long duration = (DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond;
                log.Info("Finished migration task \"" + label + "\" (" + duration + " millis.)");
                //Console.WriteLine("Finished migration task \"" + label + "\" (" + duration + " millis.)");

                if (broadcast)
                {
                    if (MigrationSuccessful != null)
                    {
                        MigrationSuccessful(task, context, null);
                        //broadcaster.notifyListeners(task, context, MigrationBroadcaster.TASK_SUCCESS);
                    }
                }

                context.Commit();
            }
            catch (MigrationException e)
            {
                if (broadcast)
                {
                    if (MigrationFailed != null)
                    {
                        MigrationFailed(task, context, e);
                        //broadcaster.notifyListeners(task, context, e, MigrationBroadcaster.TASK_FAILED);
                    }
                }

                try
                {
                    context.Rollback();
                    log.Info("Migration failed; rollback successful");
                    //Console.WriteLine("Migration failed; rollback successful");
                }
                catch (MigrationException me)
                {
                    log.Info("Migration failed; COULD NOT ROLL BACK TRANSACTION", me);
                    //Console.WriteLine("Migration failed; COULD NOT ROLL BACK TRANSACTION");
                }

                throw e;
            }
        }
开发者ID:easel,项目名称:autopatch,代码行数:75,代码来源:MigrationProcess.cs


注:本文中的IMigrationContext.Rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。