metadata, etag, options, etc are optional

This commit is contained in:
LM 2020-03-06 11:29:40 -08:00
parent 6e6aadf779
commit ea5dc12c5d
3 changed files with 111 additions and 1 deletions

View File

@ -67,6 +67,16 @@ namespace Dapr.Client
IReadOnlyDictionary<string, string> metadata = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Gets the current value associated with the <paramref name="key" /> from the Dapr state store.
/// </summary>
/// <param name="storeName">The state store name.</param>
/// <param name="key">The state key.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <typeparam name="TValue">The data type.</typeparam>
/// <returns>A <see cref="ValueTask" /> that will return the value when the operation has completed.</returns>
public abstract ValueTask<TValue> GetStateAsync<TValue>(string storeName, string key, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the current value associated with the <paramref name="key" /> from the Dapr state store.
/// </summary>
@ -78,6 +88,16 @@ namespace Dapr.Client
/// <returns>A <see cref="ValueTask" /> that will return the value when the operation has completed.</returns>
public abstract ValueTask<TValue> GetStateAsync<TValue>(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the current value associated with the <paramref name="key" /> from the Dapr state store and an ETag.
/// </summary>
/// <typeparam name="TValue">The data type.</typeparam>
/// <param name="storeName">The state store name.</param>
/// <param name="key">The state key.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <returns></returns>
public abstract ValueTask<StateAndETag<TValue>> GetStateAndETagAsync<TValue>(string storeName, string key, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the current value associated with the <paramref name="key" /> from the Dapr state store and an ETag.
/// </summary>
@ -89,6 +109,20 @@ namespace Dapr.Client
/// <returns></returns>
public abstract ValueTask<StateAndETag<TValue>> GetStateAndETagAsync<TValue>(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default);
/// <summary>
/// Gets a <see cref="StateEntry{T}" /> for the current value associated with the <paramref name="key" /> from
/// the Dapr state store.
/// </summary>
/// <param name="storeName">The state store name.</param>
/// <param name="key">The state key.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <typeparam name="TValue">The data type.</typeparam>
/// <returns>A <see cref="ValueTask" /> that will return the <see cref="StateEntry{T}" /> when the operation has completed.</returns>
public ValueTask<StateEntry<TValue>> GetStateEntryAsync<TValue>(string storeName, string key, CancellationToken cancellationToken = default)
{
return this.GetStateEntryAsync<TValue>(storeName, key, null, cancellationToken);
}
/// <summary>
/// Gets a <see cref="StateEntry{T}" /> for the current value associated with the <paramref name="key" /> from
/// the Dapr state store.
@ -115,6 +149,18 @@ namespace Dapr.Client
return new StateEntry<TValue>(this, storeName, key, stateAndETag.Data, stateAndETag.ETag);
}
/// <summary>
/// Saves the provided <paramref name="value" /> associated with the provided <paramref name="key" /> to the Dapr state
/// store.
/// </summary>
/// <param name="storeName">The state store name.</param>
/// <param name="key">The state key.</param>
/// <param name="value">The value to save.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <typeparam name="TValue">The data type.</typeparam>
/// <returns>A <see cref="ValueTask" /> that will complete when the operation has completed.</returns>
public abstract ValueTask SaveStateAsync<TValue>(string storeName, string key, TValue value, CancellationToken cancellationToken = default);
/// <summary>
/// Saves the provided <paramref name="value" /> associated with the provided <paramref name="key" /> to the Dapr state
/// store.
@ -136,6 +182,15 @@ namespace Dapr.Client
IReadOnlyDictionary<string, string> metadata,
StateRequestOptions stateRequestOptions,
CancellationToken cancellationToken = default);
/// <summary>
/// Deletes the value associated with the provided <paramref name="key" /> in the Dapr state store.
/// </summary>
/// <param name="storeName">The state store name.</param>
/// <param name="key">The state key.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <returns>A <see cref="ValueTask" /> that will complete when the operation has completed.</returns>
public abstract ValueTask DeleteStateAsync(string storeName, string key, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes the value associated with the provided <paramref name="key" /> in the Dapr state store.

View File

@ -207,6 +207,12 @@ namespace Dapr.Client
return JsonSerializer.Deserialize<TResponse>(responseData, this.jsonSerializerOptions);
}
/// <inheritdoc/>
public override ValueTask<TValue> GetStateAsync<TValue>(string storeName, string key, CancellationToken cancellationToken = default)
{
return this.GetStateAsync<TValue>(storeName, key, null, cancellationToken);
}
/// <inheritdoc/>
public override async ValueTask<TValue> GetStateAsync<TValue>(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default)
{
@ -233,6 +239,12 @@ namespace Dapr.Client
return JsonSerializer.Deserialize<TValue>(responseData, this.jsonSerializerOptions);
}
/// <inheritdoc/>
public override ValueTask<StateAndETag<TValue>> GetStateAndETagAsync<TValue>(string storeName, string key, CancellationToken cancellationToken = default)
{
return this.GetStateAndETagAsync<TValue>(storeName, key, null, cancellationToken);
}
/// <inheritdoc/>
public override async ValueTask<StateAndETag<TValue>> GetStateAndETagAsync<TValue>(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default)
{
@ -260,6 +272,12 @@ namespace Dapr.Client
return new StateAndETag<TValue>(deserialized, response.Etag);
}
/// <inheritdoc/>
public override ValueTask SaveStateAsync<TValue>(string storeName, string key, TValue value, CancellationToken cancellationToken = default)
{
return this.SaveStateAsync<TValue>(storeName, key, value, null, null, null, cancellationToken);
}
/// <inheritdoc/>
public override async ValueTask SaveStateAsync<TValue>(
string storeName,
@ -319,6 +337,12 @@ namespace Dapr.Client
await client.SaveStateAsync(saveStateEnvelope, callOptions);
}
/// <inheritdoc/>
public override ValueTask DeleteStateAsync(string storeName, string key, CancellationToken cancellationToken = default)
{
return this.DeleteStateAsync(storeName, key, null, null, cancellationToken);
}
/// <inheritdoc/>
public override async ValueTask DeleteStateAsync(string storeName, string key, string etag, StateOptions stateOptions = default, CancellationToken cancellationToken = default)
{

View File

@ -29,7 +29,8 @@ namespace Dapr
/// <param name="value">The value.</param>
/// <param name="etag">The etag.</param>
/// <remarks>
/// Application code should not need to create instances of <see cref="StateEntry{T}" />. Use
/// Application code should not need to create instances of <see cref="StateEntry{T}" />. Use
/// <see cref="Dapr.Client.DaprClient.GetStateEntryAsync{TValue}(string, string, ConsistencyMode?, CancellationToken)" /> to access
/// state entries.
/// </remarks>
public StateEntry(DaprClient client, string storeName, string key, TValue value, string etag)
@ -77,6 +78,16 @@ namespace Dapr
/// </summary>
public string ETag { get; }
/// <summary>
/// Deletes the entry associated with <see cref="Key" /> in the state store.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <returns>A <see cref="ValueTask" /> that will complete when the operation has completed.</returns>
public ValueTask DeleteAsync(CancellationToken cancellationToken = default)
{
return this.DeleteAsync(cancellationToken);
}
/// <summary>
/// Deletes the entry associated with <see cref="Key" /> in the state store.
/// </summary>
@ -89,6 +100,16 @@ namespace Dapr
return this.client.DeleteStateAsync(this.StoreName, this.Key, null, stateOptions, cancellationToken);
}
/// <summary>
/// Saves the current value of <see cref="Value" /> to the state store.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <returns>A <see cref="ValueTask" /> that will complete when the operation has completed.</returns>
public ValueTask SaveAsync(CancellationToken cancellationToken = default)
{
return this.SaveAsync(null, null, cancellationToken);
}
/// <summary>
/// Saves the current value of <see cref="Value" /> to the state store.
/// </summary>
@ -102,6 +123,16 @@ namespace Dapr
return this.client.SaveStateAsync(this.StoreName, this.Key, this.Value, null, metadata, stateRequestOptions, cancellationToken);
}
/// <summary>
/// Saves the current value of <see cref="Value" /> to the state store.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
/// <returns>A <see cref="ValueTask" /> that will complete when the operation has completed.</returns>
public ValueTask<bool> TrySaveAsync(CancellationToken cancellationToken = default)
{
return this.TrySaveAsync(null, null, cancellationToken);
}
/// <summary>
/// Saves the current value of <see cref="Value" /> to the state store.
/// </summary>