Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream transaction support in the Collection and Graph APIs #403

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions arangodb-net-standard/ApiHeaderProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace ArangoDBNetStandard
{
public class ApiHeaderProperties
{
/// <summary>
/// Gets or sets the Id of a stream transaction.
/// </summary>
public string TransactionId { get; set; }

/// <summary>
/// Any other headers you wish to add based on
/// the specifications of the API operation.
/// </summary>
public Dictionary<string,string> OtherHeaders { get; set; }

public WebHeaderCollection ToWebHeaderCollection()
{
WebHeaderCollection collection = new WebHeaderCollection();
if (TransactionId != null)
{
collection.Add(CustomHttpHeaders.StreamTransactionHeader, TransactionId);
}
if (OtherHeaders != null && OtherHeaders.Count > 0)
{
foreach (string key in OtherHeaders.Keys)
{
collection.Add(key, OtherHeaders[key]);
}
}
return collection;
}
}
}
17 changes: 11 additions & 6 deletions arangodb-net-standard/CollectionApi/CollectionApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ public virtual async Task<DeleteCollectionResponse> DeleteCollectionAsync(string
/// Truncates a collection, i.e. removes all documents in the collection.
/// PUT/_api/collection/{collection-name}/truncate
/// </summary>
/// <param name="collectionName"></param>
/// <param name="collectionName">Name of the collection</param>
/// <param name="headers">Headers (such as transaction id) to use for this operation.</param>
/// <returns></returns>
public virtual async Task<TruncateCollectionResponse> TruncateCollectionAsync(string collectionName)
public virtual async Task<TruncateCollectionResponse> TruncateCollectionAsync(string collectionName, CollectionHeaderProperties headers = null)
{
using (var response = await _transport.PutAsync(
_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/truncate",
new byte[0]).ConfigureAwait(false))
new byte[0],
headers?.ToWebHeaderCollection()).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -106,11 +108,14 @@ public virtual async Task<TruncateCollectionResponse> TruncateCollectionAsync(st
/// Gets count of documents in a collection.
/// GET/_api/collection/{collection-name}/count
/// </summary>
/// <param name="collectionName"></param>
/// <param name="collectionName">Name of the collection</param>
/// <param name="headers">Headers (such as transaction id) to use for this operation.</param>
/// <returns></returns>
public virtual async Task<GetCollectionCountResponse> GetCollectionCountAsync(string collectionName)
public virtual async Task<GetCollectionCountResponse> GetCollectionCountAsync(string collectionName, CollectionHeaderProperties headers = null)
{
using (var response = await _transport.GetAsync(_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/count").ConfigureAwait(false))
using (var response = await _transport.GetAsync(
_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/count",
headers?.ToWebHeaderCollection()).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand Down
10 changes: 6 additions & 4 deletions arangodb-net-standard/CollectionApi/ICollectionApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ Task<PostCollectionResponse> PostCollectionAsync(
/// Truncates a collection, i.e. removes all documents in the collection.
/// PUT/_api/collection/{collection-name}/truncate
/// </summary>
/// <param name="collectionName"></param>
/// <param name="collectionName">Name of the collection</param>
/// <param name="headers">Headers (such as transaction id) to use for this operation.</param>
/// <returns></returns>
Task<TruncateCollectionResponse> TruncateCollectionAsync(string collectionName);
Task<TruncateCollectionResponse> TruncateCollectionAsync(string collectionName, CollectionHeaderProperties headers = null);

/// <summary>
/// Gets count of documents in a collection.
/// GET/_api/collection/{collection-name}/count
/// </summary>
/// <param name="collectionName"></param>
/// <param name="collectionName">Name of the collection</param>
/// <param name="headers">Headers (such as transaction id) to use for this operation.</param>
/// <returns></returns>
Task<GetCollectionCountResponse> GetCollectionCountAsync(string collectionName);
Task<GetCollectionCountResponse> GetCollectionCountAsync(string collectionName, CollectionHeaderProperties headers = null);

/// <summary>
/// Get all collections.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ArangoDBNetStandard.CollectionApi.Models
{
/// <summary>
/// Provides functionality for collection-specific headers
/// </summary>
public class CollectionHeaderProperties : ApiHeaderProperties
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
/// <summary>
/// Class representing the additional header properties for Cursor Api.
/// </summary>
public class CursorHeaderProperties
public class CursorHeaderProperties : ApiHeaderProperties
{
/// <summary>
/// Gets or sets the stream transaction Id.
/// </summary>
public string TransactionId { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace ArangoDBNetStandard.DocumentApi.Models
{
public class DocumentHeaderProperties
public class DocumentHeaderProperties:ApiHeaderProperties
{
public string IfMatch { get; set; }

public string IfNoneMatch { get; set; }

/// <summary>
/// Gets or sets the Id of a stream transaction.
/// </summary>
public string TransactionId { get; set; }

public WebHeaderCollection ToWebHeaderCollection()
public new WebHeaderCollection ToWebHeaderCollection()
{
WebHeaderCollection collection = new WebHeaderCollection();
WebHeaderCollection collection = base.ToWebHeaderCollection();

if (IfMatch != null)
{
collection.Add(HttpRequestHeader.IfMatch, $"\"{IfMatch}\"");
Expand All @@ -26,12 +22,7 @@ public WebHeaderCollection ToWebHeaderCollection()
collection.Add(HttpRequestHeader.IfNoneMatch, $"\"{IfNoneMatch}\"");
}

if (TransactionId != null)
{
collection.Add(CustomHttpHeaders.StreamTransactionHeader, TransactionId);
}

return collection;
}
}
}
}
Loading