Esempio n. 1
0
        /// <summary>
        /// Interrupt a dialog stack with a new dialog, following rules for sending interrupt and resume events.
        /// </summary>
        public static async Task InterruptAsync <T>(this IDialogSystem system, IDialogStack stack, IDialog <T> dialog, CancellationToken token)
        {
            if (!system.DialogTasks.Contains(stack))
            {
                throw new ArgumentOutOfRangeException(nameof(stack));
            }

            // send the interruption event
            system.Post(MakeEvent(new InterruptDialogEvent()));
            await system.PollAsync(token);

            var interrupter =
                // when the dialog is done
                dialog
                // task boundary: catch all exceptions
                .DefaultIfException()
                // task boundary: catch all events
                .WithEventIgnore();

            // Chain.PostToChain is two frames - yuck?
            if (stack.Frames.Count > 2)
            {
                // post the resume dialog event to the queue
                interrupter = interrupter.PostEvent(new ResumeDialogEvent());
            }

            // ignore/void the result, and then resume the interrupted wait
            var voided = interrupter.Void(stack);

            // start the interrupting dialog
            stack.Call(voided, null);
            // run the task until the next wait
            await system.PollAsync(token);
        }
Esempio n. 2
0
        protected override Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var message      = item as IMessageActivity;
            var dialog       = new AccountSelectDialog();
            var interruption = dialog.Void(_stack);

            _stack.Call(interruption, null);
            return(Task.CompletedTask);
        }
        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();

            ConnectorClient client = new ConnectorClient(new Uri(message.ServiceUrl));

            try
            {
                var conversation = await client.Conversations.CreateDirectConversationAsync(message.Recipient, message.From);

                message.Conversation.Id = conversation.Id;
            }
            catch (HttpOperationException ex)
            {
                var reply = message.CreateReply();
                reply.Text = ex.Message;

                await client.Conversations.SendToConversationAsync(reply);

                return;
            }

            // 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);
                }
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        protected override Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var activity     = item as IMessageActivity;
            var dialog       = new ScorableSupportDialog();
            var interruption = dialog.Void(DialogStackObject);

            DialogStackObject.Call(interruption, null);
            return(Task.CompletedTask);
        }
        protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var message = item as IMessageActivity;

            var dialog = new HelpDialog((Activity)message);

            var interruption = dialog.Void(stack);

            stack.Call(interruption, null);
        }
Esempio n. 7
0
        // Actions to be performed
        protected override Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var message      = item as IMessageActivity;
            var dialog       = new ScorableWhoamiDialog();
            var interruption = dialog.Void(stack);

            stack.Call(interruption, null);
            return(Task.CompletedTask);

            //context.Call(new EchoCounter(), this.ResumeAfterEchoCounterDialog);
        }
Esempio n. 8
0
        async Task IDialogStack.Forward <R, T>(IDialog <R> child, ResumeAfter <R> resume, T item, CancellationToken token)
        {
            // put the child on the stack
            IDialogStack stack = this;

            stack.Call(child, resume);
            // run the loop
            IEventLoop loop = this;
            await loop.PollAsync(token);

            // forward the item
            this.fiber.Post(item);
            // run the loop again
            await loop.PollAsync(token);
        }
Esempio n. 9
0
        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);
                }
            }
        }
Esempio n. 10
0
        private void Authenticate(IDialogStack context, bool retry)
        {
            var dialog = retry ? FormDialog.FromForm(BuildRetryForm, FormOptions.PromptInStart) : FormDialog.FromForm(BuildForm, FormOptions.PromptInStart);

            context.Call(dialog, ResumeAfterAutentication);
        }
Esempio n. 11
0
 /// <summary>
 /// Call this dialog by interrupting the stack.
 /// </summary>
 /// <remarks>
 /// This method helps us avoid a closure with environment capture in <see cref="WithConfirmOnResume"/>.
 /// </remarks>
 public async Task Action(ResumeDialogEvent @event, IDialogStack stack, CancellationToken token)
 {
     stack.Call(this.Void(stack), null);
 }