Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 public DateTime GetLastModifiedDateTimeUtc()
 {
     return(OrderedConversationEntity.ToDateTime(TicksRowKey));
 }