/// <summary> /// Called when the dialog is ending. /// </summary> /// <param name="turnContext">The context object for this turn.</param> /// <param name="instance">State information associated with the instance of this component /// dialog on its parent's dialog stack.</param> /// <param name="reason">Reason why the dialog ended.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <remarks>When this method is called from the parent dialog's context, the component dialog /// cancels all of the dialogs on its inner dialog stack before ending.</remarks> /// <seealso cref="OnEndDialogAsync(ITurnContext, DialogInstance, DialogReason, CancellationToken)"/> /// <seealso cref="DialogContext.EndDialogAsync(object, CancellationToken)"/> public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken)) { // Forward cancel to inner dialogs if (reason == DialogReason.CancelCalled) { var innerDc = new DialogContext(_dialogs, turnContext, GetDialogState(instance)); await innerDc.CancelAllDialogsAsync(cancellationToken).ConfigureAwait(false); } await OnEndDialogAsync(turnContext, instance, reason, cancellationToken).ConfigureAwait(false); }
public static void Fail(this DialogContext dc, Exception ex) { dc.PostAsync(ex.Message).Wait(); dc.CancelAllDialogsAsync().Wait(); }