Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FormFlow:使用重复出现的问题添加多个实体_C#_Recursion_Bots_Botframework_Formflow - Fatal编程技术网

C# FormFlow:使用重复出现的问题添加多个实体

C# FormFlow:使用重复出现的问题添加多个实体,c#,recursion,bots,botframework,formflow,C#,Recursion,Bots,Botframework,Formflow,我一直在玩机器人框架,并创建了一个聊天机器人,让你详细了解你的家庭成员/宠物 在用户满意之前,是否有办法重复同一组问题?示例代码如下: [Prompt("What is your family name?")] public string familyName{ get; set; } [Prompt("What is your postcode?")] public string postcode { get; set; } [Prompt("Wou

我一直在玩机器人框架,并创建了一个聊天机器人,让你详细了解你的家庭成员/宠物

在用户满意之前,是否有办法重复同一组问题?示例代码如下:

    [Prompt("What is your family name?")]
    public string familyName{ get; set; }

    [Prompt("What is your postcode?")]
    public string postcode { get; set; }

    [Prompt("Would you like to add a family member? {||}")]
    public bool AddPerson { get; set; }

    [Prompt("What is their name?")]
    public string PersonName { get; set; }

    [Prompt("How old are they?")]
    public string PersonAge{ get; set; }

    [Prompt("How are they related to you?")]
    public string PersonRelation{ get; set; }

    [Prompt("Would you like to add another family member? {||}")]
    public bool addAnotherPerson { get; set; }

 public IForm<Family> BuildForm()
    {
        return new FormBuilder<GetQuoteDialog>()
            .Field(nameof(familyName))
            .Field(nameof(postcode))

            //Choose to add a person to the family
            .Field(nameof(AddPerson))

            //Details of that person.
            .Field(new FieldReflector<Family>(nameof(PersonName))
            .SetActive((state) => state.AddPerson== true))
            .Field(new FieldReflector<Family>(nameof({PersonAge))
            .SetActive((state) => state.AddPerson== true))
            .Field(new FieldReflector<Family>(nameof({PersonRelation))
            .SetActive((state) => state.AddPerson== true))

            //Prompts the user to add another if they wish
            //Recurs to the PersonName field and lets them go through the 
            //process of adding another member
            .Field(new FieldReflector<Family>(nameof({AddAnotherMember))
            .SetActive((state) => state.AddPerson== true))


            .Confirm("Is this your family? {*}")
            .Build();
    }
}
[提示(“您姓什么?”)]
公共字符串familyName{get;set;}
[提示(“您的邮政编码是什么?”)]
公共字符串邮政编码{get;set;}
[提示(“是否要添加家庭成员?{|}”)]
公共bool AddPerson{get;set;}
[提示(“他们叫什么名字?”)]
公共字符串PersonName{get;set;}
[提示(“他们几岁了?”)]
公共字符串人物{get;set;}
[提示(“他们与您的关系如何?”)]
公共字符串PersonRelation{get;set;}
[提示(“是否要添加其他家庭成员?{|}”)]
公共bool addAnotherPerson{get;set;}
公共格式BuildForm()
{
返回新的FormBuilder()
.字段(姓名(家庭名称))
.字段(姓名(邮政编码))
//选择将一个人添加到家庭中
.字段(姓名(添加人))
//那个人的详细情况。
.Field(新的FieldReflector(姓名)(人名))
.SetActive((state)=>state.AddPerson==true))
.Field(新FieldReflector(姓名({人物))
.SetActive((state)=>state.AddPerson==true))
.Field(新的FieldReflector(名称({PersonRelation))
.SetActive((state)=>state.AddPerson==true))
//如果用户愿意,提示用户添加另一个
//递归到PersonName字段,让他们通过
//添加其他成员的过程
.Field(新的FieldReflector(名称({AddAnotherMember))
.SetActive((state)=>state.AddPerson==true))
.确认(“这是你的家人吗?{*}”)
.Build();
}
}
有人对如何实现这一点有想法吗

我这样称呼formflow:

public async Task confirmAdd(IDialogContext context, IAwaitable<bool> result)
    {
        if (await result)
        {
            // builds and calls the form from here
            var myform = new FormDialog<BuildFamily>(new BuildFamily(), BuildForm, FormOptions.PromptInStart, null);
            context.Call<BuildFamily>(myform, End);
        }
    }

    private async Task End(IDialogContext context, IAwaitable<BuildFamily> result)
    {
        BuildFamily data = null;
        try
        {
            data = await result;
            await context.PostAsync("Nice family you got there :)");
        }
        catch (OperationCanceledException)
        {
            await context.PostAsync("You canceled the form!");
            return;
        }
    }
[Serializable]
    public class AddFamilyMembersDialog : IDialog<object>
    {
        List<Family> _familyMembers = new List<Family>();

        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            PromptAddMembers(context);
        }

        private void PromptAddMembers(IDialogContext context)
        {
            PromptDialog.Text(context, AfterPromptAdd, "Would you like to add more family members?", null, 1);
        }

        private async Task AfterPromptAdd(IDialogContext context, IAwaitable<string> result)
        {
            var yesno = await result;

            if (yesno.ToLower() == "yes")
            {
                await context.Forward(FormDialog.FromForm(Family.BuildForm), AfterAdded, null, CancellationToken.None);
            }
            else
            {
                //_familyMembers contains everyone the user wanted to add
                context.Done(true);
            }
        }

        private async Task AfterAdded(IDialogContext context, IAwaitable<Family> result)
        {
            var member = await result;
            if (member != null)
                _familyMembers.Add(member);

            PromptAddMembers(context);
        }

        [Serializable]
        public class Family
        {
            [Prompt("What is their name?")]
            public string PersonName { get; set; }

            [Prompt("How old are they?")]
            public string PersonAge { get; set; }

            [Prompt("How are they related to you?")]
            public string PersonRelation { get; set; }

            public static IForm<Family> BuildForm()
            {
                return new FormBuilder<Family>()
                .AddRemainingFields()
                .Build();
            }
        }

    }
public异步任务confirmAdd(IDialogContext上下文,IAwaitable结果)
{
如果(等待结果)
{
//从这里生成并调用表单
var myform=new FormDialog(new BuildFamily(),BuildForm,FormOptions.PromptInStart,null);
调用(myform,End);
}
}
专用异步任务结束(IDialogContext上下文,IAwaitable结果)
{
BuildFamily data=null;
尝试
{
数据=等待结果;
等待上下文;
}
捕获(操作取消异常)
{
wait context.PostAsync(“您取消了表单!”);
返回;
}
}
我不知道如何在FormFlow对话框中“重复同一组问题,直到用户满意为止”。但是,您可以问用户“是否要添加更多家庭成员?”在调用对话框中,实现相同类型的对话流。删除PostalCode和FamilyName类型的问题,并将它们放在单独的对话框中。然后,在添加家庭成员对话框中执行以下操作:

public async Task confirmAdd(IDialogContext context, IAwaitable<bool> result)
    {
        if (await result)
        {
            // builds and calls the form from here
            var myform = new FormDialog<BuildFamily>(new BuildFamily(), BuildForm, FormOptions.PromptInStart, null);
            context.Call<BuildFamily>(myform, End);
        }
    }

    private async Task End(IDialogContext context, IAwaitable<BuildFamily> result)
    {
        BuildFamily data = null;
        try
        {
            data = await result;
            await context.PostAsync("Nice family you got there :)");
        }
        catch (OperationCanceledException)
        {
            await context.PostAsync("You canceled the form!");
            return;
        }
    }
[Serializable]
    public class AddFamilyMembersDialog : IDialog<object>
    {
        List<Family> _familyMembers = new List<Family>();

        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            PromptAddMembers(context);
        }

        private void PromptAddMembers(IDialogContext context)
        {
            PromptDialog.Text(context, AfterPromptAdd, "Would you like to add more family members?", null, 1);
        }

        private async Task AfterPromptAdd(IDialogContext context, IAwaitable<string> result)
        {
            var yesno = await result;

            if (yesno.ToLower() == "yes")
            {
                await context.Forward(FormDialog.FromForm(Family.BuildForm), AfterAdded, null, CancellationToken.None);
            }
            else
            {
                //_familyMembers contains everyone the user wanted to add
                context.Done(true);
            }
        }

        private async Task AfterAdded(IDialogContext context, IAwaitable<Family> result)
        {
            var member = await result;
            if (member != null)
                _familyMembers.Add(member);

            PromptAddMembers(context);
        }

        [Serializable]
        public class Family
        {
            [Prompt("What is their name?")]
            public string PersonName { get; set; }

            [Prompt("How old are they?")]
            public string PersonAge { get; set; }

            [Prompt("How are they related to you?")]
            public string PersonRelation { get; set; }

            public static IForm<Family> BuildForm()
            {
                return new FormBuilder<Family>()
                .AddRemainingFields()
                .Build();
            }
        }

    }
[可序列化]
公共类AddFamilyMembersDialog:IDialog
{
列表_familyMembers=新列表();
公共任务StartSync(IDialogContext上下文)
{
Wait(MessageReceivedAsync);
返回Task.CompletedTask;
}
专用异步任务消息ReceivedAsync(IDialogContext上下文,IAwaitable结果)
{
承诺成员(上下文);
}
私有void PromptAddMembers(IDialogContext上下文)
{
Text(上下文,AfterPromptAdd,“是否要添加更多家庭成员?”,null,1);
}
PrompTadd后的专用异步任务(IDialogContext上下文,IAwaitable结果)
{
var yesno=等待结果;
如果(yesno.ToLower()=“yes”)
{
wait context.Forward(FormDialog.FromForm(Family.BuildForm),AfterAdded,null,CancellationToken.None);
}
其他的
{
//_familyMembers包含用户要添加的所有成员
上下文。完成(true);
}
}
添加后的专用异步任务(IDialogContext上下文,IAwaitable结果)
{
var成员=等待结果;
如果(成员!=null)
_家庭成员。添加(成员);
承诺成员(上下文);
}
[可序列化]
公营家庭
{
[提示(“他们叫什么名字?”)]
公共字符串PersonName{get;set;}
[提示(“他们几岁了?”)]
公共字符串人物{get;set;}
[提示(“他们与您的关系如何?”)]
公共字符串PersonRelation{get;set;}
公共静态表单BuildForm()
{
返回新的FormBuilder()
.AddRemainingFields()
.Build();
}
}
}

您是否介意发布您的全部代码,以便我们了解您是如何调用它的?添加了调用formflow的代码和一些额外的代码,以澄清对话框的工作方式。理想情况下,我想找到一种方法,使它保持在同一个formflow中,而不必调用“mini”formflow每次我想添加一个家庭成员时,尽管我认识到这是一个选项如果不可能在同一个流中进行,您会建议什么是实现这种递归的最佳方法?问题更多的是,在用户需要在simi中添加多个条目的表单中,该功能是否经常存在lar布局如我给出的示例所示。您的答案是正确的,我将这样标记。这是为了查看表单中是否有这样做的方法。尽管我会使用:PromptDialog.Confirm(上下文,AfterPromptAddd,$“Add family member?”);如果允许的话