public DialogContextFactory(IDialogContextStore store, IFrameFactory frames, IBotToUser botToUser, IBotData botData)
 {
     SetField.NotNull(out this.store, nameof(store), store);
     SetField.NotNull(out this.frames, nameof(frames), frames);
     SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser);
     SetField.NotNull(out this.botData, nameof(botData), botData);
 }
Exemple #2
0
        /// <summary>
        /// Post an item to the dialog context and poll the dialog context for any work to be done.
        /// </summary>
        /// <typeparam name="R">The type of the root dialog.</typeparam>
        /// <typeparam name="T">The type of the item.</typeparam>
        /// <param name="store">The dialog context store.</param>
        /// <param name="toBot">The item to be sent to the bot.</param>
        /// <param name="MakeRoot">The factory method for the root dialog.</param>
        /// <param name="token">An optional cancellation token.</param>
        /// <returns>A task representing the post operation.</returns>
        public static async Task PostAsync <T, R>(this IDialogContextStore store, T toBot, Func <IDialog <R> > MakeRoot, CancellationToken token = default(CancellationToken))
        {
            var context = await LoadAsync(store, MakeRoot);

            IPostToBot postToBot = context;
            await postToBot.PostAsync(toBot, token);

            store.Save(context);
        }
        /// <summary>
        /// Load or create the dialog context from the store.
        /// </summary>
        /// <typeparam name="R">The type of the root dialog.</typeparam>
        /// <param name="store">The dialog context store.</param>
        /// <param name="MakeRoot">The factory method for the root dialog.</param>
        /// <param name="token">An optional cancellation token.</param>
        /// <returns>A task representing the dialog context load operation.</returns>
        public static async Task <IDialogContextInternal> LoadAsync <R>(this IDialogContextStore store, Func <IDialog <R> > MakeRoot, CancellationToken token = default(CancellationToken))
        {
            IDialogContextInternal context;

            if (!store.TryLoad(out context))
            {
                var root = MakeRoot();
                var loop = root.Loop();
                context.Call(loop, null);
                await context.PollAsync();
            }

            return(context);
        }
        /// <summary>
        /// Post an item to the dialog context and poll the dialog context for any work to be done.
        /// </summary>
        /// <typeparam name="R">The type of the root dialog.</typeparam>
        /// <typeparam name="T">The type of the item.</typeparam>
        /// <param name="store">The dialog context store.</param>
        /// <param name="toBot">The item to be sent to the bot.</param>
        /// <param name="MakeRoot">The factory method for the root dialog.</param>
        /// <param name="token">An optional cancellation token.</param>
        /// <returns>A task representing the post operation.</returns>
        public static async Task PostAsync <T, R>(this IDialogContextStore store, T toBot, Func <IDialog <R> > MakeRoot, CancellationToken token = default(CancellationToken))
        {
            IDialogContextInternal context;

            if (MakeRoot != null)
            {
                context = await LoadAsync(store, MakeRoot);
            }
            else
            {
                if (!store.TryLoad(out context))
                {
                    throw new InvalidOperationException("Cannot resume on an empty call stack!");
                }
            }

            IPostToBot postToBot = context;
            await postToBot.PostAsync(toBot, token);

            store.Save(context);
        }
 public ErrorResilientDialogContextStore(IDialogContextStore store)
 {
     SetField.NotNull(out this.store, nameof(store), store);
 }
        /// <summary>
        /// Poll the dialog context for any work to be done.
        /// </summary>
        /// <typeparam name="R">The type of the root dialog.</typeparam>
        /// <param name="store">The dialog context store.</param>
        /// <param name="MakeRoot">The factory method for the root dialog.</param>
        /// <param name="token">An optional cancellation token.</param>
        /// <returns>A task representing the poll operation.</returns>
        public static async Task PollAsync <R>(this IDialogContextStore store, Func <IDialog <R> > MakeRoot, CancellationToken token = default(CancellationToken))
        {
            var context = await LoadAsync(store, MakeRoot);

            store.Save(context);
        }
 /// <summary>
 /// <see cref="PostAsync{T, R}(IDialogContextStore, T, Func{IDialog{R}}, CancellationToken)"/>
 /// </summary>
 /// <remarks>
 /// This function trys to resume the conversation based on the call stack.
 /// It throws <see cref="InvalidOperationException"/> if loading the call stack from context store fails.
 /// </remarks>
 /// <typeparam name="T"> The type of the item.</typeparam>
 /// <param name="store"> The dialog context store.</param>
 /// <param name="toBot"> The item to be sent to the bot.</param>
 /// <param name="token"> An optional cancellation token.</param>
 /// <returns> A task representing the post operation.</returns>
 public static async Task PostAsync <T>(this IDialogContextStore store, T toBot, CancellationToken token = default(CancellationToken))
 {
     await store.PostAsync <T, object>(toBot, null, token);
 }