Example #1
0
 /// <summary>
 /// Delete multiple documents based on the passed document selectors.
 /// A document selector is either the document ID or the document Key.
 /// </summary>
 /// <remarks>
 /// This method overload is provided as a convenience when the client does not care about the type of <see cref="DeleteDocumentResponse{T}.Old"/>
 /// in the returned <see cref="DeleteDocumentsResponse{T}"/>. These will be <c>null</c> when
 /// <see cref="DeleteDocumentsQuery.ReturnOld"/> is either <c>false</c> or not set, so this overload is useful in the default case
 /// when deleting documents.
 /// </remarks>
 /// <param name="collectionName"></param>
 /// <param name="selectors"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentsResponse <object> > DeleteDocumentsAsync(
     string collectionName,
     IList <string> selectors,
     DeleteDocumentsQuery query = null)
 {
     return(await DeleteDocumentsAsync <object>(collectionName, selectors, query));
 }
Example #2
0
        /// <summary>
        /// Delete multiple documents based on the passed document selectors.
        /// A document selector is either the document ID or the document Key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collectionName"></param>
        /// <param name="selectors"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public virtual async Task <DeleteDocumentsResponse <T> > DeleteDocumentsAsync <T>(
            string collectionName,
            IList <string> selectors,
            DeleteDocumentsQuery query = null)
        {
            string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName);

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }
            var content = GetContent(selectors, new ApiClientSerializationOptions(false, false));

            using (var response = await _client.DeleteAsync(uri, content))
            {
                if (response.IsSuccessStatusCode)
                {
                    if (query != null && query.Silent.HasValue && query.Silent.Value)
                    {
                        return(DeleteDocumentsResponse <T> .Empty());
                    }
                    else
                    {
                        var stream = await response.Content.ReadAsStreamAsync();

                        return(DeserializeJsonFromStream <DeleteDocumentsResponse <T> >(stream));
                    }
                }
                throw await GetApiErrorException(response);
            }
        }
Example #3
0
 /// <summary>
 /// Delete multiple documents based on the passed document selectors.
 /// A document selector is either the document ID or the document Key.
 /// </summary>
 /// <remarks>
 /// This method overload is provided as a convenience when the client does not care about the type of <see cref="DeleteDocumentResponse{T}.Old"/>
 /// in the returned <see cref="DeleteDocumentsResponse{T}"/>. These will be <c>null</c> when
 /// <see cref="DeleteDocumentsQuery.ReturnOld"/> is either <c>false</c> or not set, so this overload is useful in the default case
 /// when deleting documents.
 /// </remarks>
 /// <param name="collectionName"></param>
 /// <param name="selectors"></param>
 /// <param name="query"></param>
 /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentsResponse <object> > DeleteDocumentsAsync(
     string collectionName,
     IList <string> selectors,
     DeleteDocumentsQuery query       = null,
     DocumentHeaderProperties headers = null)
 {
     return(await DeleteDocumentsAsync <object>(collectionName, selectors, query, headers).ConfigureAwait(false));
 }
Example #4
0
        /// <summary>
        /// Delete multiple documents based on the passed document selectors.
        /// A document selector is either the document ID or the document Key.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collectionName"></param>
        /// <param name="selectors"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <DeleteDocumentsResponse <T> > DeleteDocumentsAsync <T>(string collectionName, IList <string> selectors, DeleteDocumentsQuery query = null)
        {
            string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName);

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }
            var content = GetStringContent(selectors, false, false);

            using (var response = await _client.DeleteAsync(uri, content))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    var responseModel = DeserializeJsonFromStream <DeleteDocumentsResponse <T> >(stream);
                    return(responseModel);
                }
                throw await GetApiErrorException(response);
            }
        }
Example #5
0
        /// <summary>
        /// Delete a document based on its document ID.
        /// </summary>
        /// <param name="documentId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(string documentId, DeleteDocumentsQuery query = null)
        {
            ValidateDocumentId(documentId);
            string uri = _docApiPath + "/" + documentId;

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }
            using (var response = await _client.DeleteAsync(uri))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    var responseModel = DeserializeJsonFromStream <DeleteDocumentResponse <T> >(stream);
                    return(responseModel);
                }
                throw await GetApiErrorException(response);
            }
        }
Example #6
0
 /// <summary>
 /// Delete a document.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="collectionName"></param>
 /// <param name="documentKey"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(string collectionName, string documentKey, DeleteDocumentsQuery query = null)
 {
     return(await DeleteDocumentAsync <T>($"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}", query));
 }
Example #7
0
 /// <summary>
 /// Delete a document based on its document ID.
 /// </summary>
 /// <remarks>
 /// This method overload is provided as a convenience when the client does not care about the type of <see cref="DeleteDocumentResponse{T}.Old"/>
 /// in the returned <see cref="DeleteDocumentResponse{object}"/>. Its value will be <see cref="null"/> when
 /// <see cref="DeleteDocumentsQuery.ReturnOld"/> is either <see cref="false"/> or not set, so this overload is useful in the default case
 /// when deleting documents.
 /// </remarks>
 /// <param name="documentId"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public async Task <DeleteDocumentResponse <object> > DeleteDocumentAsync(string documentId, DeleteDocumentsQuery query = null)
 {
     return(await DeleteDocumentAsync <object>(documentId, query));
 }