public async Task Calculate_Script_Scorable_As_Action_Reset_Stack()
        {
            var echo = Chain.PostToChain().Select(msg => $"echo: {msg.Text}").PostToUser().Loop();

            var scorable = Actions
                           .Bind(async(string expression, IDialogStack stack, IMessageActivity activity, CancellationToken token) =>
            {
                var dialog    = new CalculatorDialog();
                activity.Text = expression;
                stack.Reset();
                await stack.Forward(dialog.Loop(), null, activity, token);
            })
                           .When(new Regex(@".*calculate\s*(?<expression>.*)"))
                           .Normalize();

            echo = echo.WithScorable(scorable);

            using (var container = Build(Options.ResolveDialogFromContainer))
            {
                var builder = new ContainerBuilder();
                builder
                .RegisterInstance(echo)
                .As <IDialog <object> >();
                builder.Update(container);

                await AssertScriptAsync(container,
                                        "hello",
                                        "echo: hello",
                                        "calculate 2 + 3",
                                        "5",
                                        "2 + 2",
                                        "4"
                                        );
            }
        }
示例#2
0
        protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var dialog = new CalculatorDialog();

            // let's strip off the prefix in favor of the actual arithmetic expression
            var message = (IMessageActivity)item;
            message.Text = state;

            await this.stack.Forward(dialog.Void(this.stack), null, message, token);
        }
示例#3
0
        async Task IScorable <double> .PostAsync <Item>(IPostToBot inner, Item item, object state, CancellationToken token)
        {
            var dialog = new CalculatorDialog();

            // let's strip off the prefix in favor of the actual arithmetic expression
            var message = (Message)(object)item;

            message.Text = (string)state;

            await this.stack.Forward(dialog.Void <double, Message>(), null, item, token);

            await this.stack.PollAsync(token);
        }