Ejemplo n.º 1
0
        public async Task AppendToStream(string streamId, IEnumerable <StorageEvent> events)
        {
            var documents = events
                            .Select(
                document => DocumentDbStorageEvent.FromStorageEvent(
                    document,
                    typeMap,
                    collectionOptions.DocumentTimeToLiveSeconds))
                            .ToList();

            try
            {
                var result = await client.ExecuteStoredProcedureAsync <dynamic>(
                    appendStoredProcedureLink,
                    new RequestOptions
                {
                    PartitionKey     = new PartitionKey(streamId),
                    ConsistencyLevel = collectionOptions.ConsistencyLevel
                },
                    documents);

                loggingOptions.OnSuccess(ResponseInformation.FromWriteResponse(nameof(AppendToStream), result));
            }
            catch (DocumentClientException exception)
            {
                if (exception.Error.Message.Contains(ConcurrencyConflictErrorKey))
                {
                    throw new ConcurrencyException(exception.Error.Message, exception);
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteStream(string streamId)
        {
            while (true)
            {
                var result = await client.ExecuteStoredProcedureAsync <dynamic>(
                    deleteStoredProcedureLink,
                    new RequestOptions { PartitionKey = new PartitionKey(streamId), ConsistencyLevel = collectionOptions.ConsistencyLevel },
                    streamId);

                if ((bool)result.Response.continuation)
                {
                    continue;
                }

                loggingOptions.OnSuccess(ResponseInformation.FromWriteResponse(nameof(DeleteStream), result));

                break;
            }
        }