async Task <BotData> IBotDataStore <BotData> .LoadAsync(IAddress key, BotStoreType botStoreType, CancellationToken cancellationToken) { var entityKey = BotDataEntity.GetEntityKey(key, botStoreType); var result = await this.Table.ExecuteAsync(TableOperation.Retrieve <BotDataEntity>(entityKey.PartitionKey, entityKey.RowKey)); BotDataEntity entity = (BotDataEntity)result.Result; if (entity == null) { // empty record ready to be saved return(new BotData(eTag: String.Empty, data: null)); } // return botdata return(new BotData(entity.ETag, entity.GetData())); }
async Task IBotDataStore <BotData> .SaveAsync(IAddress key, BotStoreType botStoreType, BotData botData, CancellationToken cancellationToken) { var entityKey = BotDataEntity.GetEntityKey(key, botStoreType); BotDataEntity entity = new BotDataEntity(key.BotId, key.ChannelId, key.ConversationId, key.UserId, botData.Data) { ETag = botData.ETag }; entity.PartitionKey = entityKey.PartitionKey; entity.RowKey = entityKey.RowKey; if (String.IsNullOrEmpty(entity.ETag)) { await this.Table.ExecuteAsync(TableOperation.Insert(entity)); } else if (entity.ETag == "*") { if (botData.Data != null) { await this.Table.ExecuteAsync(TableOperation.InsertOrReplace(entity)); } else { await this.Table.ExecuteAsync(TableOperation.Delete(entity)); } } else { if (botData.Data != null) { await this.Table.ExecuteAsync(TableOperation.Replace(entity)); } else { await this.Table.ExecuteAsync(TableOperation.Delete(entity)); } } }