async Task IDialogStack.Forward <R, T>(IDialog <R> child, ResumeAfter <R> resume, T item, CancellationToken token) { IDialogStack stack = this; stack.Call(child, resume); await stack.PollAsync(token); await(this as IPostToBot).PostAsync(item, token); }
public static async Task StartSurvey(ResumptionCookie cookie, CancellationToken token) { var container = WebApiApplication.FindContainer(); // the ResumptionCookie has the "key" necessary to resume the conversation var message = cookie.GetMessage(); // we instantiate our dependencies based on an IMessageActivity implementation using (var scope = DialogModule.BeginLifetimeScope(container, message)) { // find the bot data interface and load up the conversation dialog state var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(token); // resolve the dialog stack IDialogStack stack = stack = scope.Resolve <IDialogStack>(); // make a dialog to push on the top of the stack var child = scope.Resolve <SurveyDialog>(); // wrap it with an additional dialog that will restart the wait for // messages from the user once the child dialog has finished var interruption = child.Void <object, IMessageActivity>(); try { // put the interrupting dialog on the stack stack.Call(interruption, null); // start running the interrupting dialog await stack.PollAsync(token); } finally { // save out the conversation dialog state await botData.FlushAsync(token); } } }
async Task IPostToBot.PostAsync <T>(T item, CancellationToken token) { this.fiber.Post(item); IDialogStack stack = this; await stack.PollAsync(token); }
/// <summary> /// Interrupt the waiting dialog with a new dialog /// </summary> /// <typeparam name="T">The type of result expected from the dialog.</typeparam> /// <typeparam name="R">The type of the item posted to dialog.</typeparam> /// <param name="stack">The dialog stack.</param> /// <param name="dialog">The new interrupting dialog.</param> /// <param name="item">The item to foward to the new interrupting dialog.</param> /// <param name="token">The cancellation token.</param> /// <returns>A task that represents the interruption operation.</returns> public static async Task InterruptAsync <T, R>(this IDialogStack stack, IDialog <T> dialog, R item, CancellationToken token) { await stack.Forward(dialog.Void <T, R>(), null, item, token); await stack.PollAsync(token); }