c#bot框架 - context.wait

时间:2017-04-05 15:11:49

标签: c# bots

private async Task BuildSummaryForm(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    try
    {
        var searchQuery = await result;

        var items = await this.GetSummaryAsync(searchQuery.Text);

        await context.PostAsync($"Ho trovato2 **{items.Count()}** risulati:");

        var resultMessage = context.MakeMessage();

        resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;

        resultMessage.Attachments = new List<Attachment>();

        foreach (var item in items)
        {
            HeroCard heroCard = new HeroCard()
            {
                Title = item.Title,
                Subtitle = $"{item.Subtitle}",
                Images = new List<CardImage>()
                {
                    new CardImage() { Url = item.Image }
                },
                Buttons = new List<CardAction>()
                {
                    new CardAction()
                    {
                        Title = "Seleziona",
                        Value = item.Slug,
                        Type = "imBack"
                    }
                }
            };

            resultMessage.Attachments.Add(heroCard.ToAttachment());
        }

        await context.PostAsync(resultMessage);
    }
    catch (FormCanceledException ex)
    {
        string reply;

        if (ex.InnerException == null)
        {
            reply = "You have canceled the operation. Quitting from the SearchDialog";
        }
        else
        {
            reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
        }

        await context.PostAsync(reply);
    }
    finally
    {
        context.Wait(this.ResumeAfterSummaryDialog);
        //context.Done<object>(null);
    }
}

private async Task ResumeAfterSummaryDialog(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    try
    {
        var message = await result;
        await context.PostAsync($"Hai selezionato: {message.Text}");

        System.Diagnostics.Debug.WriteLine($" ==========================> ResumeAfterOptionDialog - 00000000000001 {message.Text}");
    }
    catch (Exception ex)
    {
        await context.PostAsync($"Failed with message3: {ex.Message}");
    }
    finally
    {
        System.Diagnostics.Debug.WriteLine($" ==========================> ResumeAfterOptionDialog - 000000000000002");

        //context.Done<object>(null);

        context.Wait(this.ResumeAfterSummaryChoice);

        //context.Call(new ShowChoiceDialog(), this.ResumeAfterSummaryChoice);
    }
}

private async Task ResumeAfterSummaryChoice(IDialogContext context, IAwaitable<object> result)
{
    System.Diagnostics.Debug.WriteLine($" ==========================> ResumeAfterSummaryChoice - 999999999990");

    try
    {
        var message = await result;
    }
    catch (FormCanceledException ex)
    {
        string reply;
        if (ex.InnerException == null)
        {
            reply = "You have canceled the operation. Quitting from the SearchDialog";
        }
        else
        {
            reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
        }
        await context.PostAsync(reply);
    }
    finally
    {
        context.Done<object>(null);
    }
}

我不知道为什么但不输入ResumeAfterSummaryChoice ...

context.Wait(this.ResumeAfterSummaryChoice);

//context.Call(new ShowChoiceDialog(), this.ResumeAfterSummaryChoice);

两个字符串中的哪一个在finally块中使用是无关紧要的。有帮助吗? THX。

0 个答案:

没有答案