尝试在此代码中设置用户数据并保持返回“抱歉,我的机器人代码存在问题”
internal static IDialog<SandwichOrder> MakeRootDialog()
{
return Chain.From(() => FormDialog.FromForm(SandwichOrder.BuildForm))
.Do(async (context, order) =>
{
try
{
var activity = context.Activity;
var channelId = activity.ChannelId;
var fromId = activity.From.Id;
var stateClient = activity.GetStateClient();
**var userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
// modify a property within user data
userData.SetProperty<string>("SerialNumber", "");
// save updated user data
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);**
var completed = await order;
// Actually process the sandwich order...
await context.PostAsync("Defect data submitted!");
}
catch (HttpOperationException err)
{
// handle error with HTTP status code 412 Precondition Failed
}
catch (FormCanceledException<SandwichOrder> e)
{
string reply;
if (e.InnerException == null)
{
reply = $"You quit on {e.Last}--maybe you can finish next time!";
}
else
{
reply = "Sorry, I've had a short circuit. Please try again.";
}
await context.PostAsync(reply);
}
});
}
它实际上正在工作并清除属性,但我不想再看到该错误消息
答案 0 :(得分:1)
使用对话框上下文的方法来操作对话框方法中的状态,而不是使用activity.GetStateClient()。
正在发生的事情是加载对话框时反序列化状态,并在对话框完成时自动保存。如果在对话框中手动创建状态客户端并操纵状态,则在发生自动保存时会发生冲突。
编辑: 这符合预期。
在控制器中:
GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 2);
recyclerView.setLayoutManager(gridLayoutManager);
表格:
RecyclerView