结合来自Chain的Forms的结果

时间:2017-08-16 15:36:43

标签: c# botframework

如何将Forms的结果合并到一个结果中并将结果发布给用户? 我需要从Chain设置Declaration属性并将完成的SupportRequest发布给用户。 在文档中,我看到了Chain.Fold方法,但我不知道如何使用它https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-dialogs

我的代码:

public enum SystemSelection { SharePoint, BizTalk, Azure, Office365 };
public enum RequestType { Bug, SupportRequest, Question };
public enum Importance { Blocking, High, Medium, Low };

[Serializable]
class Declaration
{
    public string Type;
    public string Amount;
    public string Date;

    public static IForm<Declaration> BuildForm()
    {
        return new FormBuilder<Declaration>()
                .Message("Add a declaration")
                .Build();
    }
}

[Serializable]
class SupportRequest
{
    public SystemSelection? SystemSelection;
    public RequestType? RequestType;
    public Importance? Importance;
    //need to setup this property
    public Declaration Declaration;

    public static IForm<SupportRequest> BuildForm()
    {
        return new FormBuilder<SupportRequest>()
                .Message("Welcome to the simple support bot!")
                .AddRemainingFields()
                .Build();
    }

    internal static IDialog<SupportRequest> MakeRootDialog()
    {
        var dlg = from x in FormDialog.FromForm(SupportRequest.BuildForm)
                  from y in FormDialog.FromForm(Declaration.BuildForm)
                  select x;
        return dlg;
    }

    internal static IDialog<Declaration> MakeRootDialog2()
    {
        SupportRequest t = null;
        var dlg = Chain.From(() => FormDialog.FromForm(SupportRequest.BuildForm))
        .ContinueWith<SupportRequest, Declaration>(async (ctx, sr) =>
        {
            t = await sr;
            return FormDialog.FromForm(Declaration.BuildForm);
        });

        return dlg;
    }
}

0 个答案:

没有答案