private async Task AddConversationForUser(string username, Conversation conversation) { var conversationOrderEntity = new OrderedConversationEntity(username, conversation.Id, conversation.Participants, conversation.LastModifiedDateUtc); var conversationEntity = new ConversationEntity(username, conversation.Id, conversation.Participants, conversationOrderEntity.RowKey); TableBatchOperation batchInsert = new TableBatchOperation { TableOperation.Insert(conversationEntity), TableOperation.Insert(conversationOrderEntity) }; try { await table.ExecuteBatchAsync(batchInsert); } catch (StorageException e) { // Do nothing if the conversation already exists. // The client should list all conversations periodically or based on events and will get // the latest list of conversations. if (e.RequestInformation.HttpStatusCode != 409) { throw new StorageErrorException("Failed to reach storage", e); } } }
private async Task UpdateConversationModifiedDateForUser(string username, string conversationId, Message message) { ConversationEntity conversationEntity = await RetrieveConversationEntity(username, conversationId); var newOrderedConversationEntity = new OrderedConversationEntity( username, conversationId, conversationEntity.GetParticipants(), message.UtcTime); string oldTicksRowKey = conversationEntity.TicksRowKey; string newTicksRowKey = newOrderedConversationEntity.RowKey; conversationEntity.TicksRowKey = newTicksRowKey; TableBatchOperation batchOperation = new TableBatchOperation { TableOperation.Replace(conversationEntity), // will fail if entity has changed since we retrieved it (ETAG) TableOperation.Delete(new TableEntity(partitionKey: username, rowKey: oldTicksRowKey) { ETag = "*" }), // delete old conversation order entity TableOperation.Insert(newOrderedConversationEntity) // will fail if another entity with the same ticks exists }; try { await table.ExecuteBatchAsync(batchOperation); } catch (StorageException e) { throw new StorageErrorException("Failed to update conversation modified time", e); } }
public DateTime GetLastModifiedDateTimeUtc() { return(OrderedConversationEntity.ToDateTime(TicksRowKey)); }