我有一个对话框要求连续5个附件。 (不是表格,因为AwaitableAttachment尚未发布:How to receive Attachment in Form Dialog?)
我想模仿Form Dialog的“后退”功能,当用户回复“返回”时,我想再次询问上一个问题。我现在正在做的事情有效,但感觉很笨拙。我想知道是否有更好的方法来做到这一点。
我现在拥有的是:
[Serializable]
public class MyDialog : IDialog<string>
{
private int StateId = 0; //for figuring out which dialog was called, for "going back"
public async Task StartAsync(IDialogContext context)
{
await ReceiveDocument1Async(context);
}
private async Task ReceiveDocument1Async(IDialogContext context, IAwaitable<string> result = null)
{
StateId = 1;
if (mustProcessTextMessage(message))
{
string message = await result;
await ProcessTextMessage(context, message);
}
else
{
string textPrompt = $"Please attach a copy of your **Document1**.";
context.Call(new ReceiveFileDialog(textPrompt), this.ReceiveDocument2Async);
}
}
...
string[] reservedMessages = new string[] { "QUIT", "BACK" };
string[] separators = new string[] { "|||" };
private bool mustProcessTextMessage(string message)
{
string[] messages = message.Split(separators, StringSplitOptions.None);
if (reservedMessages.Contains(messages[0]))
return true;
return false;
}
private async Task ProcessTextMessage(IDialogContext context, string message)
{
string[] messages = message.Split(separators, StringSplitOptions.None);
switch (messages[0])
{
case "QUIT":
context.Done("QUIT");
break;
case "BACK":
StateId -= 1;
switch (StateId)
{
case 0:
context.Done("QUIT");
break;
case 1:
await ReceiveDocument1Async(context);
break;
case 2:
await ReceiveDocument2Async(context);
break;
...
default:
context.Done("QUIT");
break;
}
break;
default:
break;
}
}
}