私は再開クッキーを使って積極的なボットを行っています。シングルトンクラスのボットフレーム
私はオブジェクトのリストである1つのシングルトンクラスを持っています。私は次のように定義されたシングルトンた場所:
public static MyObj instance = new MyObj();
public List<Objects> thename = null;
public int count { get; set; }
public static MyObj Instance
{
get
{
return instance;
}
}
はその後、私はconversationStarterクラスを持っている:
public class ConversationStarter
{
public static string resumptionCookie;
public static async Task Resume()
{
var message = ResumptionCookie.GZipDeserialize(resumptionCookie).GetMessage();
var client = new ConnectorClient(new Uri(message.ServiceUrl));
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
var botData = scope.Resolve<IBotData>();
await botData.LoadAsync(CancellationToken.None);
var task = scope.Resolve<IDialogTask>();
//interrupt the stack
var dialog = new AlarmDialog();
task.Call(dialog.Void<object, IMessageActivity>(), null);
task.PollAsync(CancellationToken.None);
//flush dialog stack
await botData.FlushAsync(CancellationToken.None);
}
}
}
}
RootDialogから私はx秒ごとに新しいダイアログを呼び出すタイマーを持っています。ラインで
Microsoft.Bot.Builder.Internals.Fibers.InvalidNeedException: 'invalid need: expected Wait, have None'
:
task.PollAsync(CancellationToken.None);
私はNewDialogにこのmyobjのインスタンスにアクセスするとき
[Serializable]
public class NewDialog : IDialog<object>
{
public Myobj objList;
public async Task StartAsync(IDialogContext context)
{
objList= Myobj.Instance;
PromptDialog.Choice(context, this.AfterSelectOption,
new string[] { "Stay in this survey", "Get back to where I was" },
"Hello, you're in the survey dialog. Please pick one of these options");
}
private async Task AfterSelectOption(IDialogContext context, IAwaitable<string> result)
{
if ((await result) == "Get back to where I was")
{
await context.PostAsync("Great, back to the original conversation!");
context.Done(String.Empty); //Finish this dialog
}
else
{
await context.PostAsync("I'm still on the survey until you tell me to stop");
PromptDialog.Choice(context, this.AfterSelectOption, new string[] { "Stay in this survey", "Get back to where I was" }, "Hello, you're in the survey dialog. Please pick one of these options");
}
}
}
}
私は次の例外int型ConversationStarterを取得しています:私はそのダイアログで
シングルトンクラスにアクセスしようとしないと、すべてがスムーズに進みます。このようなシングルトンクラスを使用することはできませんか?
シングルトンクラスはシリアライズ可能ですか? –
シリアル化可能です – JoaoFilipeClementeMartins
このサンプルはチェックしましたか:https://github.com/MicrosoftDX/botFramework-proactiveMessages –