예제 #1
0
        async Task ResumeAfterWineFormAsync(IDialogContext context, IAwaitable <WineForm> result)
        {
            WineForm wineResult = await result;

            string message = await ProcessWineResultsAsync(wineResult);

            await context.PostAsync(message);

            context.Wait(MessageReceivedAsync);
        }
예제 #2
0
 IDialog <string> DoSearchCase()
 {
     return
         (Chain
          .From(() => FormDialog.FromForm(new WineForm().BuildForm, FormOptions.PromptInStart))
          .ContinueWith(async(ctx, res) =>
     {
         WineForm wineResult = await res;
         string message = await ProcessWineResultsAsync(wineResult);
         return Chain.Return(message);
     }));
 }
예제 #3
0
        async Task <string> ProcessWineResultsAsync(WineForm wineResult)
        {
            List[] wines =
                await new WineApi().SearchAsync(
                    (int)wineResult.WineType,
                    (int)wineResult.Rating,
                    wineResult.InStock == StockingType.InStock,
                    "");

            string message;

            if (wines.Any())
            {
                message = "Here are the top matching wines: " +
                          string.Join(", ", wines.Select(w => w.Name));
            }
            else
            {
                message = "Sorry, No wines found matching your criteria.";
            }

            return(message);
        }
예제 #4
0
        async Task DoChainLoopAsync(IDialogContext context)
        {
            IDialog <WineForm> chain =
                Chain.From(() => FormDialog.FromForm(new WineForm().BuildForm, FormOptions.PromptInStart))
                .Do(async(ctx, result) =>
            {
                try
                {
                    WineForm wineResult = await result;
                    string message      = await ProcessWineResultsAsync(wineResult);
                    await ctx.PostAsync(message);
                }
                catch (FormCanceledException fce)
                {
                    await ctx.PostAsync($"Cancelled: {fce.Message}");
                }
            })
                .Loop();

            await context.Forward(
                chain,
                ResumeAfterWineFormAsync,
                context.Activity.AsMessageActivity());
        }