示例#1
0
        public void BuildIdWorksAsExpected()
        {
            var guid1 = new Guid("23c9125d-24ba-4c1b-b740-5b765437c30e");
            var guid2 = new Guid("f048be07-3cbe-4345-a1e8-f528738adf1d");

            Assert.AreEqual("A|SomeId", DocumentWrap <A> .BuildId("SomeId"));
            Assert.AreEqual("A|B|SomeId", DocumentWrap <B> .BuildId("SomeId"));
            Assert.AreEqual("A|B|C|SomeId", DocumentWrap <C> .BuildId("SomeId"));
            Assert.AreEqual("A|B|C|SomeId|AnotherPartOfTheId", DocumentWrap <C> .BuildId("SomeId", "AnotherPartOfTheId"));
            Assert.AreEqual("A|B|C|23c9125d24ba4c1bb7405b765437c30e|f048be073cbe4345a1e8f528738adf1d", DocumentWrap <C> .BuildId(guid1, guid2));
        }
示例#2
0
        public async Task Delete(T item)
        {
            await EnsureInitialized();

            var itemId = item.Id.ToString("D");
            DocumentWrap <T> existing = null;

            var queryADone = false;

            while (!queryADone)
            {
                try
                {
                    existing = _client
                               //.AsReliable(_retryStrategy)
                               .CreateDocumentQuery <DocumentWrap <T> >(_collection.DocumentsLink, new FeedOptions {
                        EnableCrossPartitionQuery = true
                    })
                               .Where(i => i.Id == itemId).AsEnumerable().SingleOrDefault();
                    queryADone = true;
                }
                catch (DocumentClientException documentClientException)
                {
                    handleDocumentClientException(documentClientException);
                }
                catch (AggregateException aggregateException)
                {
                    handleAggregateException(aggregateException);
                }
            }


            var queryBDone = false;

            if (existing == null)
            {
                return;
            }
            while (!queryBDone)
            {
                try
                {
                    await _client
                    //.AsReliable(_retryStrategy)
                    .DeleteDocumentAsync(existing.SelfLink, new RequestOptions()
                    {
                        PartitionKey = new PartitionKey(existing.Id)
                    });

                    queryBDone = true;
                }
                catch (DocumentClientException documentClientException)
                {
                    handleDocumentClientException(documentClientException);
                }
                catch (AggregateException aggregateException)
                {
                    handleAggregateException(aggregateException);
                }
            }
        }