diff --git a/src/Dapr.Client/DaprClient.cs b/src/Dapr.Client/DaprClient.cs index 7f4a4a66..6d80bae3 100644 --- a/src/Dapr.Client/DaprClient.cs +++ b/src/Dapr.Client/DaprClient.cs @@ -67,6 +67,16 @@ namespace Dapr.Client IReadOnlyDictionary metadata = default, CancellationToken cancellationToken = default); + /// + /// Gets the current value associated with the from the Dapr state store. + /// + /// The state store name. + /// The state key. + /// A that can be used to cancel the operation. + /// The data type. + /// A that will return the value when the operation has completed. + public abstract ValueTask GetStateAsync(string storeName, string key, CancellationToken cancellationToken = default); + /// /// Gets the current value associated with the from the Dapr state store. /// @@ -78,6 +88,16 @@ namespace Dapr.Client /// A that will return the value when the operation has completed. public abstract ValueTask GetStateAsync(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default); + /// + /// Gets the current value associated with the from the Dapr state store and an ETag. + /// + /// The data type. + /// The state store name. + /// The state key. + /// A that can be used to cancel the operation. + /// + public abstract ValueTask> GetStateAndETagAsync(string storeName, string key, CancellationToken cancellationToken = default); + /// /// Gets the current value associated with the from the Dapr state store and an ETag. /// @@ -89,6 +109,20 @@ namespace Dapr.Client /// public abstract ValueTask> GetStateAndETagAsync(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default); + /// + /// Gets a for the current value associated with the from + /// the Dapr state store. + /// + /// The state store name. + /// The state key. + /// A that can be used to cancel the operation. + /// The data type. + /// A that will return the when the operation has completed. + public ValueTask> GetStateEntryAsync(string storeName, string key, CancellationToken cancellationToken = default) + { + return this.GetStateEntryAsync(storeName, key, null, cancellationToken); + } + /// /// Gets a for the current value associated with the from /// the Dapr state store. @@ -115,6 +149,18 @@ namespace Dapr.Client return new StateEntry(this, storeName, key, stateAndETag.Data, stateAndETag.ETag); } + /// + /// Saves the provided associated with the provided to the Dapr state + /// store. + /// + /// The state store name. + /// The state key. + /// The value to save. + /// A that can be used to cancel the operation. + /// The data type. + /// A that will complete when the operation has completed. + public abstract ValueTask SaveStateAsync(string storeName, string key, TValue value, CancellationToken cancellationToken = default); + /// /// Saves the provided associated with the provided to the Dapr state /// store. @@ -136,6 +182,15 @@ namespace Dapr.Client IReadOnlyDictionary metadata, StateRequestOptions stateRequestOptions, CancellationToken cancellationToken = default); + + /// + /// Deletes the value associated with the provided in the Dapr state store. + /// + /// The state store name. + /// The state key. + /// A that can be used to cancel the operation. + /// A that will complete when the operation has completed. + public abstract ValueTask DeleteStateAsync(string storeName, string key, CancellationToken cancellationToken = default); /// /// Deletes the value associated with the provided in the Dapr state store. diff --git a/src/Dapr.Client/DaprClientGrpc.cs b/src/Dapr.Client/DaprClientGrpc.cs index c1a5c01a..39ec1865 100644 --- a/src/Dapr.Client/DaprClientGrpc.cs +++ b/src/Dapr.Client/DaprClientGrpc.cs @@ -207,6 +207,12 @@ namespace Dapr.Client return JsonSerializer.Deserialize(responseData, this.jsonSerializerOptions); } + /// + public override ValueTask GetStateAsync(string storeName, string key, CancellationToken cancellationToken = default) + { + return this.GetStateAsync(storeName, key, null, cancellationToken); + } + /// public override async ValueTask GetStateAsync(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default) { @@ -233,6 +239,12 @@ namespace Dapr.Client return JsonSerializer.Deserialize(responseData, this.jsonSerializerOptions); } + /// + public override ValueTask> GetStateAndETagAsync(string storeName, string key, CancellationToken cancellationToken = default) + { + return this.GetStateAndETagAsync(storeName, key, null, cancellationToken); + } + /// public override async ValueTask> GetStateAndETagAsync(string storeName, string key, ConsistencyMode? consistencyMode = default, CancellationToken cancellationToken = default) { @@ -260,6 +272,12 @@ namespace Dapr.Client return new StateAndETag(deserialized, response.Etag); } + /// + public override ValueTask SaveStateAsync(string storeName, string key, TValue value, CancellationToken cancellationToken = default) + { + return this.SaveStateAsync(storeName, key, value, null, null, null, cancellationToken); + } + /// public override async ValueTask SaveStateAsync( string storeName, @@ -319,6 +337,12 @@ namespace Dapr.Client await client.SaveStateAsync(saveStateEnvelope, callOptions); } + /// + public override ValueTask DeleteStateAsync(string storeName, string key, CancellationToken cancellationToken = default) + { + return this.DeleteStateAsync(storeName, key, null, null, cancellationToken); + } + /// public override async ValueTask DeleteStateAsync(string storeName, string key, string etag, StateOptions stateOptions = default, CancellationToken cancellationToken = default) { diff --git a/src/Dapr.Client/StateEntry.cs b/src/Dapr.Client/StateEntry.cs index abe2e132..5fe9898e 100644 --- a/src/Dapr.Client/StateEntry.cs +++ b/src/Dapr.Client/StateEntry.cs @@ -29,7 +29,8 @@ namespace Dapr /// The value. /// The etag. /// - /// Application code should not need to create instances of . Use + /// Application code should not need to create instances of . Use + /// to access /// state entries. /// public StateEntry(DaprClient client, string storeName, string key, TValue value, string etag) @@ -77,6 +78,16 @@ namespace Dapr /// public string ETag { get; } + /// + /// Deletes the entry associated with in the state store. + /// + /// A that can be used to cancel the operation. + /// A that will complete when the operation has completed. + public ValueTask DeleteAsync(CancellationToken cancellationToken = default) + { + return this.DeleteAsync(cancellationToken); + } + /// /// Deletes the entry associated with in the state store. /// @@ -89,6 +100,16 @@ namespace Dapr return this.client.DeleteStateAsync(this.StoreName, this.Key, null, stateOptions, cancellationToken); } + /// + /// Saves the current value of to the state store. + /// + /// A that can be used to cancel the operation. + /// A that will complete when the operation has completed. + public ValueTask SaveAsync(CancellationToken cancellationToken = default) + { + return this.SaveAsync(null, null, cancellationToken); + } + /// /// Saves the current value of to the state store. /// @@ -102,6 +123,16 @@ namespace Dapr return this.client.SaveStateAsync(this.StoreName, this.Key, this.Value, null, metadata, stateRequestOptions, cancellationToken); } + /// + /// Saves the current value of to the state store. + /// + /// A that can be used to cancel the operation. + /// A that will complete when the operation has completed. + public ValueTask TrySaveAsync(CancellationToken cancellationToken = default) + { + return this.TrySaveAsync(null, null, cancellationToken); + } + /// /// Saves the current value of to the state store. ///