本文整理汇总了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;
}
}