コード例 #1
0
        async Task IBotDataStore <BotData> .SaveAsync(IAddress key, BotStoreType botStoreType, BotData botData,
                                                      CancellationToken cancellationToken)
        {
            try
            {
                var requestOptions = new RequestOptions()
                {
                    AccessCondition = new AccessCondition()
                    {
                        Type      = AccessConditionType.IfMatch,
                        Condition = botData.ETag
                    }
                };

                var entity    = new DocDbBotDataEntity(key, botStoreType, botData);
                var entityKey = DocDbBotDataEntity.GetEntityKey(key, botStoreType);

                if (string.IsNullOrEmpty(botData.ETag))
                {
                    await documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseId, collectionId), entity, requestOptions);
                }
                else if (botData.ETag == "*")
                {
                    if (botData.Data != null)
                    {
                        await documentClient.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseId, collectionId), entity, requestOptions);
                    }
                    else
                    {
                        await documentClient.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, entityKey), requestOptions);
                    }
                }
                else
                {
                    if (botData.Data != null)
                    {
                        await documentClient.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, entityKey), entity, requestOptions);
                    }
                    else
                    {
                        await documentClient.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, entityKey), requestOptions);
                    }
                }
            }
            catch (DocumentClientException e)
            {
                //if (e.StatusCode.HasValue && e.StatusCode.Value == HttpStatusCode.Conflict)
                //{
                //    throw new HttpException((int)HttpStatusCode.PreconditionFailed, e.Message, e);
                //}

                //throw new HttpException(e.StatusCode.HasValue ? (int)e.StatusCode.Value : 0, e.Message, e);

                throw;
            }
        }
コード例 #2
0
        public virtual async Task <IdentityResult> DeleteAsync(TRole role, CancellationToken token)
        {
            if (UsesPartitioning)
            {
                await DeleteMapping(role.NormalizedName);
            }
            await _Client.DeleteDocumentAsync(GetRoleUri(role.DocId), GetRequestOptions(role.PartitionKey));

            // todo low priority result based on delete result
            return(IdentityResult.Success);
        }
コード例 #3
0
        public async Task <bool> RemoveAsync(T entity)
        {
            if (!string.IsNullOrEmpty(entity.Self))
            {
                var resp = await _client.DeleteDocumentAsync(entity.Self);

                return(resp.StatusCode == System.Net.HttpStatusCode.NoContent);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public async Task <bool> Delete(string id)
        {
            try
            {
                await _documentClient.DeleteDocumentAsync(CreateDocumentUri(id), RequestOptions);

                return(true);
            }
            catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.NotFound)
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: UserRepository.cs プロジェクト: OliverOrchard/User
        public async Task <bool> DeleteUser(User.Domain.User user)
        {
            var response = await _documentClient.DeleteDocumentAsync(CreateDocumentUri(user.Id),
                                                                     new RequestOptions { PartitionKey = new PartitionKey(user.Id) });

            return(response.StatusCode == HttpStatusCode.NoContent);
        }
コード例 #6
0
        public async Task <int> DeleteAsync(Expression <Func <EventStoreDocument, bool> > predicate,
                                            CancellationToken cancellationToken = default
                                            )
        {
            var count = 0;

            await ExecuteAsync(async dbCol =>
            {
                var docs = await GetAsync <EventStoreDocument>(predicate, cancellationToken);

                foreach (var doc in docs)
                {
                    await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(dbCol.DatabaseId, dbCol.CollectionId, doc.Id),
                                                      new RequestOptions
                    {
                        PartitionKey           = new PartitionKey(doc.StreamId),
                        JsonSerializerSettings = _jsonSettings
                    },
                                                      cancellationToken
                                                      );
                    count++;
                }
            },
                               cancellationToken

                               );


            return(count);
        }
コード例 #7
0
        public async Task <Document> DeleteDocumentAsync(string documentId, RequestOptions options = null,
                                                         CancellationToken cancellationToken       = default(CancellationToken))
        {
            var uri = UriFactory.CreateDocumentUri(_databaseName, _collectionName, documentId);

            return(await _documentClient.DeleteDocumentAsync(uri, options, cancellationToken));
        }
コード例 #8
0
        public static async Task <IActionResult> Delete(
            [HttpTrigger(
                 AuthorizationLevel.Function,
                 "delete",
                 Route = "jurisdiction/{jurisdiction}/person/{id}")]
            HttpRequest req,
            string jurisdiction,
            string id,
            [CosmosDB(
                 Databases.MyApp.Name,
                 Databases.MyApp.Collections.People.Name,
                 ConnectionStringSetting = Databases.MyApp.ConnectionStringPropertyName,
                 Id = "{id}",
                 PartitionKey = "{jurisdiction}",
                 CreateIfNotExists = true)]
            Person toDelete,
            [CosmosDB(ConnectionStringSetting = Databases.MyApp.ConnectionStringPropertyName)]
            IDocumentClient client,
            ILogger log,
            CancellationToken cancellationToken)
        {
            if (toDelete == null)
            {
                return(new BadRequestErrorMessageResult(
                           $"Person with jurisdiction \"{jurisdiction}\" and ID \"{id}\" not found. Cannot Delete."));
            }

            await client.DeleteDocumentAsync(toDelete.SelfLink, new RequestOptions
            {
                PartitionKey = new PartitionKey(jurisdiction)
            }, cancellationToken);

            return(new AcceptedResult());
        }
コード例 #9
0
        public async Task <bool> DeleteAsync(string id, Domain.RequestOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("Missing document Id", nameof(id));
            }

            if (_databaseName == null)
            {
                throw new DataStoreException("Connect must be called to delete from CosmosDB");
            }

            try
            {
                var response = await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(_databaseName, _collectionName, id), options.ToRequestOptions(), _cancellationToken);

                return(response.StatusCode == HttpStatusCode.NoContent);
            }
            catch (DocumentClientException e)
            {
                if (e.StatusCode == HttpStatusCode.NotFound)
                {
                    return(true);
                }
                throw;
            }
        }
コード例 #10
0
        public async Task <bool> DeleteAsync <T>(string id) where T : IBaseEntity
        {
            await GetDBClient();

            var result = await _documentClient.DeleteDocumentAsync(UriFactory.CreateDocumentUri(cosmosDBName, typeof(T).Name, id));

            return(result.StatusCode == System.Net.HttpStatusCode.Created);
        }
コード例 #11
0
 public async Task DeleteTodoAsync(string userId, string id)
 {
     await documentClient.DeleteDocumentAsync(
         UriFactory.CreateDocumentUri(dbName, collectionName, id),
         new RequestOptions()
     {
         PartitionKey = new PartitionKey(userId)
     });
 }
コード例 #12
0
        public virtual async Task <IdentityResult> DeleteAsync(TUser user, CancellationToken token)
        {
            if (UsesPartitioning)
            {
                await DeleteMapping(user.NormalizedUserName, TypeEnum.UserMappingUsername);
                await DeleteMapping(user.NormalizedEmail, TypeEnum.UserMappingEmail);

                /*await Task.WhenAll(user.Logins.Select((login) =>
                 * {
                 *  var partitionKey = login.LoginProvider + login.ProviderKey;
                 *  return DeleteMapping(partitionKey);
                 * }));*/
            }
            await _Client.DeleteDocumentAsync(GetUserUri(user), GetRequestOptions(user.PartitionKey));

            // todo success based on delete result
            return(IdentityResult.Success);
        }
コード例 #13
0
        //This method is ignored because OpenCover can't cover all branches for async methods
        public async Task DeleteDocument(string collectionId, string documentId, RequestOptions options = null)
        {
            if (options == null)
                options = new RequestOptions
                {
                    PartitionKey = new PartitionKey(documentId)
                };

            var documentUri = UriFactory.CreateDocumentUri(databaseId, collectionId, documentId);
            await documentClient.DeleteDocumentAsync(documentUri, options);
        }
コード例 #14
0
        public virtual async Task Delete(TDocument document)
        {
            var selfLink = await GetDocumentSelfLink(document);

            if (string.IsNullOrWhiteSpace(selfLink))
            {
                throw new InvalidOperationException("Document does not exist in collection");
            }

            await _documentClient.DeleteDocumentAsync(selfLink);
        }
コード例 #15
0
        public async Task <ToDo> DeleteById(Guid id)
        {
            var deleted = await GetById(id);

            if (deleted != null)
            {
                await _documentClient.DeleteDocumentAsync(GetDocumentUriForEntity(deleted));
            }

            return(deleted);
        }
コード例 #16
0
 public async Task DeleteAccount(string email)
 {
     try
     {
         await _documentClient.DeleteDocumentAsync(CreateDocumentUri(email),
                                                   new RequestOptions { PartitionKey = new PartitionKey("FYP") });
     }
     catch (DocumentClientException e)
     {
         throw new StorageErrorException($"Failed to delete account with email {email} from FYP", e, (int)e.StatusCode);
     }
 }
コード例 #17
0
        public async Task SetCompleted()
        {
            IsCompleted = true;

            if (_existing)
            {
                await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(_databaseName, _collectionName, Saga.CorrelationId.ToString()), _requestOptions)
                .ConfigureAwait(false);

                this.LogRemoved();
            }
        }
コード例 #18
0
        public async Task <Document> DeleteShopAsync(string Id)
        {
            Document res = null;

            try
            {
                res = await client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, Id));
            }
            catch
            {
                throw new System.Exception($"Shop with id:{Id} was not found");
            }
            return(res);
        }
コード例 #19
0
        /// <summary>
        /// Deletes a document.
        /// </summary>
        /// <param name="dbId">Database id.</param>
        /// <param name="collectionId">Collection id.</param>
        /// <param name="docId">Document id</param>
        /// <param name="requestOptions">Request options</param>
        /// <returns>Deleted document.</returns>
        public async Task <ResourceResponse <Document> > DeleteDocumentAsync(
            string dbId, string collectionId, string docId, RequestOptions requestOptions = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(dbId, nameof(dbId), TaggingUtilities.ReserveTag(0x2381b1c3 /* tag_961hd */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(collectionId, nameof(collectionId), TaggingUtilities.ReserveTag(0x2381b1c4 /* tag_961he */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(docId, nameof(docId), TaggingUtilities.ReserveTag(0x2381b1c5 /* tag_961hf */));

            IDocumentClient client = await GetDocumentClientAsync().ConfigureAwait(false);

            return(await DocumentDbAdapter.ExecuteAndLogAsync(TaggingUtilities.ReserveTag(0x2381b1c6 /* tag_961hg */),
                                                              () => client.DeleteDocumentAsync(
                                                                  UriFactory.CreateDocumentUri(dbId, collectionId, docId), requestOptions))
                   .ConfigureAwait(false));
        }
コード例 #20
0
        public async Task SetCompleted()
        {
            IsCompleted = true;

            if (_existing)
            {
                await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(_databaseName, _collectionName, Saga.CorrelationId.ToString())).ConfigureAwait(false);

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("SAGA:{0}:{1} Removed {2}", TypeMetadataCache <TSaga> .ShortName, TypeMetadataCache <TMessage> .ShortName, Saga.CorrelationId);
                }
            }
        }
コード例 #21
0
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                await _documentClient.DeleteDocumentAsync(
                    UriFactory.CreateDocumentUri(databaseId, collectionId, id)
                    );

                return(Ok());
            }
            catch
            {
                return(NoContent());
            }
        }
コード例 #22
0
        public async Task DeleteAllExportJobRecordsAsync(CancellationToken cancellationToken = default)
        {
            IDocumentQuery <Document> query = _documentClient.CreateDocumentQuery <Document>(
                _collectionUri,
                new SqlQuerySpec("SELECT doc._self FROM doc"),
                new FeedOptions()
            {
                PartitionKey = new PartitionKey(ExportJobPartitionKey)
            })
                                              .AsDocumentQuery();

            while (query.HasMoreResults)
            {
                FeedResponse <Document> documents = await query.ExecuteNextAsync <Document>(cancellationToken);

                foreach (Document doc in documents)
                {
                    await _documentClient.DeleteDocumentAsync(doc.SelfLink, new RequestOptions()
                    {
                        PartitionKey = new PartitionKey(ExportJobPartitionKey)
                    }, cancellationToken);
                }
            }
        }
コード例 #23
0
 public async Task Delete(string id)
 {
     try
     {
         await _client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(_databaseId, _documentCollection.Id, id));
     }
     catch (DocumentClientException exception)
     {
         if (exception.StatusCode == HttpStatusCode.NotFound)
         {
             return;
         }
         throw;
     }
 }
コード例 #24
0
        public async Task <bool> RemoveAsync(string id, RequestOptions requestOptions = null)
        {
            bool isSuccess = false;

            var doc = await GetDocumentByIdAsync(id);

            if (doc != null)
            {
                var result = await _client.DeleteDocumentAsync(doc.SelfLink, requestOptions);

                isSuccess = result.StatusCode == HttpStatusCode.NoContent;
            }

            return(isSuccess);
        }
 /// <summary>
 /// Removes the object instance by removing the document from documentdb.
 /// WARNING: The document will be hard deleted from the db, not by setting an enddate field.
 /// </summary>
 /// <param name="collectionName">Name of the collection on which the operation must be performed.</param>
 /// <param name="id">The id of the object instance that needs to be deleted forever.</param>
 /// <param name="partition">The partition of the object to remove.</param>
 public async Task Remove(string collectionName, string id, string partition)
 {
     try
     {
         Uri uri = CreateDocumentLink(collectionName, id);
         await _client.DeleteDocumentAsync(uri, GetRequestOptions(partition));
     }
     catch (DocumentClientException documentClientException)
     {
         if (documentClientException.StatusCode == HttpStatusCode.NotFound)
         {
             _trace.TraceInformation(ErrorCodes.DBDocumentNotFound, collectionName, id, partition);
         }
         throw;
     }
 }
コード例 #26
0
        private static async Task <int> DeleteDocumentsInQueryAsync <T>(IDocumentClient client, IDocumentQuery <T> query)
        {
            var linksToDelete = new List <string>();

            while (query.HasMoreResults)
            {
                var documents = await query.ExecuteNextAsync <Document>().ConfigureAwait(false);

                linksToDelete.AddRange(documents.Select(d => d.SelfLink));
            }
            foreach (var link in linksToDelete)
            {
                await client.DeleteDocumentAsync(link).ConfigureAwait(false);
            }
            return(linksToDelete.Count);
        }
コード例 #27
0
        public static async Task <ResourceResponse <Document> > HandleEntityDeleteAsync(string tableName, string partitionKey, string rowKey, string ifMatch, IDocumentClient client, RequestOptions requestOptions, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            Uri uri = UriFactory.CreateDocumentUri("TablesDB", tableName, rowKey);

            requestOptions = SetPartitionKey(requestOptions, partitionKey);
            if (!string.IsNullOrEmpty(ifMatch))
            {
                requestOptions.AccessCondition = new AccessCondition
                {
                    Type      = AccessConditionType.IfMatch,
                    Condition = ifMatch
                };
            }
            return(await client.DeleteDocumentAsync(uri.ToString(), requestOptions));
        }
コード例 #28
0
 public async Task DeleteMessage(string conversationId, string messageId)
 {
     try
     {
         await _documentClient.DeleteDocumentAsync(CreateDocumentUri(messageId),
                                                   new RequestOptions { PartitionKey = new PartitionKey("m_" + conversationId) });
     }
     catch (DocumentClientException e)
     {
         if (e.StatusCode == HttpStatusCode.NotFound)
         {
             throw new MessageNotFoundException($"Message with id {messageId} was not found");
         }
         throw new StorageErrorException($"Failed to delete message {messageId} from conversation {conversationId}",
                                         e, (int)e.StatusCode);
     }
 }
コード例 #29
0
 public async Task DeleteConversation(string username, string conversationId)
 {
     try
     {
         await _documentClient.DeleteDocumentAsync(CreateDocumentUri("m_" + conversationId),
                                                   new RequestOptions { PartitionKey = new PartitionKey("c_" + username) });
     }
     catch (DocumentClientException e)
     {
         if (e.StatusCode == HttpStatusCode.NotFound)
         {
             throw new ConversationNotFoundException($"Conversation with id {conversationId} was not found");
         }
         throw new StorageErrorException($"Failed to delete conversation {conversationId} from User {username}",
                                         e, (int)e.StatusCode);
     }
 }
        public async Task <HttpStatusCode> DeleteAsync(Guid documentId)
        {
            var documentUri      = CreateDocumentUri(documentId);
            var existingDocument = await GetAsync(f => f.DocumentId == documentId).ConfigureAwait(false);

            if (existingDocument == null)
            {
                return(HttpStatusCode.NotFound);
            }

            var accessCondition = new AccessCondition {
                Condition = existingDocument.Etag, Type = AccessConditionType.IfMatch
            };
            var partitionKey = new PartitionKey(existingDocument.PartitionKey);

            var result = await documentClient.DeleteDocumentAsync(documentUri, new RequestOptions { AccessCondition = accessCondition, PartitionKey = partitionKey }).ConfigureAwait(false);

            return(result.StatusCode);
        }