diff --git a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs index 53cdd65eb9a9..8577ad5115d3 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs @@ -67,6 +67,25 @@ protected internal ResultCollection(System.ClientModel.Primitives.PipelineRespon public abstract System.Collections.Generic.IEnumerator GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } + public abstract partial class ResultOperation : System.ClientModel.ClientResult + { + protected ResultOperation(string id, System.ClientModel.Primitives.PipelineResponse response) { } + public bool HasCompleted { get { throw null; } protected set { } } + public string Id { get { throw null; } protected set { } } + public abstract System.ClientModel.ClientResult UpdateStatus(); + public abstract System.Threading.Tasks.ValueTask UpdateStatusAsync(); + public abstract System.ClientModel.ClientResult WaitForCompletionResult(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.ClientModel.ClientResult WaitForCompletionResult(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask WaitForCompletionResultAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask WaitForCompletionResultAsync(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } + public abstract partial class ResultOperation : System.ClientModel.ResultOperation + { + protected ResultOperation(string id, System.ClientModel.Primitives.PipelineResponse response) : base (default(string), default(System.ClientModel.Primitives.PipelineResponse)) { } + public T? Value { get { throw null; } protected set { } } + public abstract System.ClientModel.ClientResult WaitForCompletion(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } public partial class ResultPage : System.ClientModel.ResultCollection { internal ResultPage() { } @@ -74,6 +93,20 @@ internal ResultPage() { } public static System.ClientModel.ResultPage Create(System.Collections.Generic.IEnumerable values, string? continuationToken, System.ClientModel.Primitives.PipelineResponse response) { throw null; } public override System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } } + public enum ReturnWhen + { + Started = 0, + Completed = 1, + } + public abstract partial class StatusBasedOperation : System.ClientModel.ResultOperation + { + protected StatusBasedOperation(string id, TStatus status, System.ClientModel.Primitives.PipelineResponse response) : base (default(string), default(System.ClientModel.Primitives.PipelineResponse)) { } + public TStatus Status { get { throw null; } protected set { } } + public abstract void Pause(); + public abstract void Resume(); + public abstract System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } } namespace System.ClientModel.Primitives { diff --git a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs index e43b75c72c1e..a8060dab2f09 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs @@ -67,6 +67,25 @@ protected internal ResultCollection(System.ClientModel.Primitives.PipelineRespon public abstract System.Collections.Generic.IEnumerator GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } } + public abstract partial class ResultOperation : System.ClientModel.ClientResult + { + protected ResultOperation(string id, System.ClientModel.Primitives.PipelineResponse response) { } + public bool HasCompleted { get { throw null; } protected set { } } + public string Id { get { throw null; } protected set { } } + public abstract System.ClientModel.ClientResult UpdateStatus(); + public abstract System.Threading.Tasks.ValueTask UpdateStatusAsync(); + public abstract System.ClientModel.ClientResult WaitForCompletionResult(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.ClientModel.ClientResult WaitForCompletionResult(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask WaitForCompletionResultAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask WaitForCompletionResultAsync(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } + public abstract partial class ResultOperation : System.ClientModel.ResultOperation + { + protected ResultOperation(string id, System.ClientModel.Primitives.PipelineResponse response) : base (default(string), default(System.ClientModel.Primitives.PipelineResponse)) { } + public T? Value { get { throw null; } protected set { } } + public abstract System.ClientModel.ClientResult WaitForCompletion(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } public partial class ResultPage : System.ClientModel.ResultCollection { internal ResultPage() { } @@ -74,6 +93,20 @@ internal ResultPage() { } public static System.ClientModel.ResultPage Create(System.Collections.Generic.IEnumerable values, string? continuationToken, System.ClientModel.Primitives.PipelineResponse response) { throw null; } public override System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } } + public enum ReturnWhen + { + Started = 0, + Completed = 1, + } + public abstract partial class StatusBasedOperation : System.ClientModel.ResultOperation + { + protected StatusBasedOperation(string id, TStatus status, System.ClientModel.Primitives.PipelineResponse response) : base (default(string), default(System.ClientModel.Primitives.PipelineResponse)) { } + public TStatus Status { get { throw null; } protected set { } } + public abstract void Pause(); + public abstract void Resume(); + public abstract System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } } namespace System.ClientModel.Primitives { diff --git a/sdk/core/System.ClientModel/src/Convenience/ResultOperation.cs b/sdk/core/System.ClientModel/src/Convenience/ResultOperation.cs new file mode 100644 index 000000000000..4a6047beb391 --- /dev/null +++ b/sdk/core/System.ClientModel/src/Convenience/ResultOperation.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.ClientModel.Primitives; +using System.Threading; +using System.Threading.Tasks; + +namespace System.ClientModel; + +#pragma warning disable CS1591 // public XML comments +public abstract class ResultOperation : ClientResult +{ + protected ResultOperation(string id, PipelineResponse response) : base(response) + { + Id = id; + } + + public string Id { get; protected set; } + + public bool HasCompleted { get; protected set; } + + // TODO: Should we take a cancellationToken, since third-party convenience methods don't? + // TODO: Should we take a RequestOptions? + // i.e. Is the non-T version of this for protocol-level, or only for operations that + // don't have an output value? + public abstract ValueTask UpdateStatusAsync(); + + public abstract ClientResult UpdateStatus(); + + // TODO: what is the use case for these? How do they differ from GetRawResponse() ? + public abstract ValueTask WaitForCompletionResultAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default); + + public abstract ClientResult WaitForCompletionResult(TimeSpan pollingInterval, CancellationToken cancellationToken = default); + + public abstract ValueTask WaitForCompletionResultAsync(CancellationToken cancellationToken = default); + + public abstract ClientResult WaitForCompletionResult(CancellationToken cancellationToken = default); + + // TODO: should these be virtual with an internal poller implementation? + // TODO: should we have something like DelayStrategy? +} +#pragma warning restore CS1591 // public XML comments diff --git a/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs b/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs new file mode 100644 index 000000000000..44f9de9c91bf --- /dev/null +++ b/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.ClientModel.Primitives; +using System.Threading; +using System.Threading.Tasks; + +namespace System.ClientModel; + +#pragma warning disable CS1591 // public XML comments +public abstract class ResultOperation : ResultOperation +{ + protected ResultOperation(string id, PipelineResponse response) : base(id, response) + { + } + + public T? Value { get; protected set; } + + public abstract ValueTask> WaitForCompletionAsync(TimeSpan? pollingInterval =default, CancellationToken cancellationToken = default); + + public abstract ClientResult WaitForCompletion(TimeSpan? pollingInterval = default, CancellationToken cancellationToken = default); +} +#pragma warning restore CS1591 // public XML comments diff --git a/sdk/core/System.ClientModel/src/Convenience/ReturnWhen.cs b/sdk/core/System.ClientModel/src/Convenience/ReturnWhen.cs new file mode 100644 index 000000000000..ce8133f55be3 --- /dev/null +++ b/sdk/core/System.ClientModel/src/Convenience/ReturnWhen.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace System.ClientModel; + +#pragma warning disable CS1591 // public XML comments +public enum ReturnWhen +{ + Started, + Completed +} +#pragma warning restore CS1591 // public XML comments diff --git a/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs new file mode 100644 index 000000000000..2d047013b35f --- /dev/null +++ b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.ClientModel.Primitives; +using System.Threading; +using System.Threading.Tasks; + +namespace System.ClientModel; + +#pragma warning disable CS1591 // public XML comments +public abstract class StatusBasedOperation : ResultOperation +{ + protected StatusBasedOperation(string id, TStatus status, PipelineResponse response) : base(id, response) + { + Status = status; + } + + public TStatus Status { get; protected set; } + + public abstract ValueTask> WaitForStatusUpdateAsync(TimeSpan? pollingInterval = default, CancellationToken cancellationToken = default); + + public abstract ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TimeSpan? pollingInterval = default, CancellationToken cancellationToken = default); + + // TODO: Optional APIs to Pause and Resume polling + public abstract void Pause(); + + public abstract void Resume(); +} +#pragma warning restore CS1591 // public XML comments diff --git a/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockLroClient.cs b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockLroClient.cs new file mode 100644 index 000000000000..385f8564723a --- /dev/null +++ b/sdk/core/System.ClientModel/tests/TestFramework/Mocks/MockLroClient.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using Azure.Core.TestFramework; + +namespace ClientModel.Tests.Mocks; + +public class MockLroClient +{ + public virtual ResultOperation GetModelLater(ReturnWhen returnWhen, string content) + { + throw new NotImplementedException(); + } + + public virtual ClientResult GetModelLater(string content, RequestOptions? options = default) + { + throw new NotImplementedException(); + } +}