/// <summary> /// Replace multiple documents. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collectionName"></param> /// <param name="documents"></param> /// <param name="query"></param> /// <param name="serializationOptions">The serialization options. When the value is null the /// the serialization options should be provided by the serializer, otherwise the given options should be used.</param> /// <returns></returns> public virtual async Task <PutDocumentsResponse <T> > PutDocumentsAsync <T>( string collectionName, IList <T> documents, PutDocumentsQuery query = null, ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(documents, serializationOptions); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { if (query != null && query.Silent.HasValue && query.Silent.Value) { return(PutDocumentsResponse <T> .Empty()); } else { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutDocumentsResponse <T> >(stream)); } } throw await GetApiErrorException(response); } }
/// <summary> /// Replaces the data of an edge in the collection. /// PUT /_api/gharial/{graph}/edge/{collection}/{edge} /// </summary> /// <typeparam name="T">Type of the document used for the update.</typeparam> /// <param name="graphName"></param> /// <param name="collectionName"></param> /// <param name="edgeKey"></param> /// <param name="edge"></param> /// <param name="query"></param> /// <returns></returns> public async Task <PutEdgeResponse <T> > PutEdgeAsync <T>( string graphName, string collectionName, string edgeKey, T edge, PutEdgeQuery query = null) { var content = GetContent(edge, false, false); string uri = _graphApiPath + "/" + WebUtility.UrlEncode(graphName) + "/edge/" + WebUtility.UrlEncode(collectionName) + "/" + WebUtility.UrlEncode(edgeKey); if (query != null) { uri += "?" + query.ToQueryString(); } using (var response = await _transport.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutEdgeResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Replaces the data of an edge based on its document ID. /// </summary> /// <exception cref="ArgumentException">Provided document ID is invalid.</exception> /// <typeparam name="T">Type of the document used for the update.</typeparam> /// <param name="graphName">The name of the graph in which to replace the edge.</param> /// <param name="documentId">The document ID of the edge to replace.</param> /// <param name="edge"></param> /// <param name="query"></param> /// <returns></returns> public virtual async Task <PutEdgeResponse <T> > PutEdgeAsync <T>( string graphName, string documentId, T edge, PutEdgeQuery query = null) { ValidateDocumentId(documentId); string uri = _graphApiPath + "/" + WebUtility.UrlEncode(graphName) + "/edge/" + documentId; if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(edge, new ApiClientSerializationOptions(false, false)); using (var response = await _transport.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutEdgeResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Truncates a collection, i.e. removes all documents in the collection. /// PUT/_api/collection/{collection-name}/truncate /// </summary> /// <param name="collectionName"></param> /// <returns></returns> public async Task <TruncateCollectionResponse> TruncateCollectionAsync(string collectionName) { using (var response = await _transport.PutAsync(_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/truncate", null)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <TruncateCollectionResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Replace an existing user. /// You need server access level Administrate in order to execute this REST call. /// Additionally, a user can change his/her own data. /// </summary> /// <param name="username">The name of the user.</param> /// <param name="body">The user information used for to replace operation.</param> /// <returns></returns> public virtual async Task <PutUserResponse> PutUserAsync(string username, PutUserBody body) { string uri = _userApiPath + '/' + username; var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutUserResponse>(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Replace multiple documents. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collectionName"></param> /// <param name="documents"></param> /// <param name="options"></param> /// <returns></returns> public async Task <PostDocumentsResponse <T> > PutDocumentsAsync <T>(string collectionName, IList <T> documents, PutDocumentsQuery query = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetStringContent(documents, false, false); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostDocumentsResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
public async Task <PutCursorResponse <T> > PutCursorAsync <T>(string cursorId) { using (var response = await _client.PutAsync(_cursorApiPath + "/" + cursorId, new StringContent(string.Empty))) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutCursorResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Advances an existing query cursor and gets the next set of results. /// </summary> /// <typeparam name="T">Result type to deserialize to</typeparam> /// <param name="cursorId">ID of the existing query cursor.</param> /// <returns></returns> public virtual async Task <PutCursorResponse <T> > PutCursorAsync <T>(string cursorId) { string uri = _cursorApiPath + "/" + WebUtility.UrlEncode(cursorId); using (var response = await _client.PutAsync(uri, new byte[0])) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutCursorResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Commit a transaction by PUT. /// </summary> /// <remarks> /// https://www.arangodb.com/docs/stable/http/transaction-stream-transaction.html#commit-transaction /// </remarks> /// <param name="transactionId">The transaction identifier.</param> /// <exception cref="ApiErrorException"> /// With ErrorNum 1653 if the transaction cannot be committed. /// With ErrorNum 10 if the transaction is not found. /// </exception> /// <returns>Response from ArangoDB after committing a transaction.</returns> public virtual async Task <StreamTransactionResponse> CommitTransaction(string transactionId) { string completeCommitTransactionPath = string.Format(_streamTransactionApiPath, transactionId); using (var response = await _client.PutAsync(completeCommitTransactionPath, Array.Empty <byte>()).ConfigureAwait(false)) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(DeserializeJsonFromStream <StreamTransactionResponse>(stream)); } var error = DeserializeJsonFromStream <ApiErrorResponse>(stream); throw new ApiErrorException(error); } }