使用 Azure table 存储 Tablelogger.cs

Consuming Azure table storage Tablelogger.cs

大家好我正在关注这个tutorial on how to consume and log the conversation history using the tablelogger.cs

它在 global.asax 上使用此代码,使用 tablelogger 实现来编写对话历史记录。

var tableName = ConfigurationManager.AppSettings["TableName"].ToString();
    var account = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

    //Azure StateData
    Conversation.UpdateContainer(
        builder =>
        {
            //azure botdata
            builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
            var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            builder.Register(c => store)
               .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
               .AsSelf()
               .SingleInstance();
            //azure conversation history
            account.CreateCloudTableClient().GetTableReference(tableName).DeleteIfExists();
            builder.RegisterModule(new TableLoggerModule(account, tableName));
        });

它工作得很好,但是我注意到当我尝试 运行 并在 VS 上调试我的代码时,它会放弃整个对话 table。这是导致它删除 table 的原因吗?

account.CreateCloudTableClient().GetTableReference(tableName).DeleteIfExists();

如果是,那我怎样才能防止它掉落?我可以简单地删除 deleteifexist() 方法吗?我担心 table 会在其他用户仍在与机器人对话时被删除。

如果您查看 GitHub 上用于 Table 存储的 "official" 示例,您会发现您指定的行不是必需的:https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Samples/AzureTable/Global.asax.cs

要设置数据存储:

var store = new TableBotDataStore(CloudStorageAccount.DevelopmentStorageAccount);
builder.Register(c => store)
    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
    .AsSelf()
    .SingleInstance();

设置Table记录器:

builder.RegisterModule(new TableLoggerModule(account, tableName));

评论里说了,一定是你用的教程制作人的特殊需要,你应该去掉。

看起来有关删除的行来自测试:https://github.com/Microsoft/BotBuilder-Azure/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Azure.Tests/LoggerTests.cs