如何从Azure表格存储中获取聊天记录

问题描述:

由于我们被迫丢弃stateclient并移至自定义存储,因此在我的情况下,

Since we are forced to drop the stateclient and move to a custom storage, in my case an azure table storage. Using my storageexplorer I can see that it already saved conversation data on my azure. How can I update my ff code to get past chat history? Before I'm using a IActivityLogger class to log a conversation, but now I'm confused on how to update it.

之前的Global Asax:

Global Asax Before:

protected void Application_Start()
{
    var builder = new ContainerBuilder();
    builder.RegisterType<Logger>().AsImplementedInterfaces().InstancePerDependency();
    builder.Update(Conversation.Container);
    GlobalConfiguration.Configure(WebApiConfig.Register);
}

之后的全球Asax:

protected void Application_Start()
{
    Conversation.UpdateContainer(builder =>
    {
        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();
    });

    GlobalConfiguration.Configure(WebApiConfig.Register);
}

记录器类:

public class Logger:IActivityLogger
{
    public static ConcurrentDictionary<string, List<IActivity>> Messages = new ConcurrentDictionary<string, List<IActivity>>();

    public Task LogAsync(IActivity activity)
    {
        try
        {
            var list = new List<IActivity>() { activity };
            Messages.AddOrUpdate(activity.Conversation.Id, list, (k, v) => { v.Add(activity); return v; });
            return Task.FromResult(false);
        }
        catch (System.Exception)
        {
            throw;
        }

    }
}

这就是我的使用方式(如何更新stateclient部分并在Azure上使用我的存储空间?:

This is how i use it (how can i update the stateclient part and use my storage on azure?:

var reply = activity.CreateReply();
var storedActivities = new List<IActivity>();
var found = Logger.Messages.TryGetValue(activity.Conversation.Id, out storedActivities);
if (storedActivities != null)
{
    foreach (var storedActivity in storedActivities)
    {
        reply.Text += $" <br /> <b>{storedActivity.From.Name}:</b> {storedActivity.AsMessageActivity().Text}";
    }
    // Get any saved values
    StateClient sc = activity.GetStateClient();
    BotData userData = sc.BotState.GetPrivateConversationData(
    activity.ChannelId, activity.Conversation.Id, activity.From.Id);
    var UserEmail = userData.GetProperty<string>("Email");
    var Name = userData.GetProperty<string>("Name");
}

他们开设了一个新的tablelogger类.不幸的是我不知道如何消费它. TableLogger. cs

They gave a new tablelogger class. Unfortunately I don't know how to consume it. TableLogger.cs

Microsoft.Azure.Cosmos.Table处于维护模式,将很快弃用.

Microsoft.Azure.Cosmos.Table as it is in maintenance mode and will be deprecated soon.