From 85008f9cd40e3a89fa874707fecf9cef32f15285 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Fri, 24 May 2024 14:29:47 -0700 Subject: [PATCH 1/3] Initial draft of subtype of ResultOperation to add status functionality --- .../api/System.ClientModel.net6.0.cs | 7 ++++++ .../api/System.ClientModel.netstandard2.0.cs | 7 ++++++ .../src/Convenience/StatusBasedOperation.cs | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs 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 7b2b23d32a34b..c6a7126c5185e 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs @@ -100,6 +100,13 @@ 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(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 b47c69ed60b35..f557cf4d0f84d 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs @@ -100,6 +100,13 @@ 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + } } namespace System.ClientModel.Primitives { 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 0000000000000..a705e5ea32f72 --- /dev/null +++ b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs @@ -0,0 +1,24 @@ +// 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(CancellationToken cancellationToken = default); + + public abstract ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(CancellationToken cancellationToken = default); +} +#pragma warning restore CS1591 // public XML comments From 85f9627e986639a1e7f150fbbddccd0847ca7b76 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Fri, 24 May 2024 16:38:24 -0700 Subject: [PATCH 2/3] default the pollingInterval parameter, per APIView suggestion --- .../api/System.ClientModel.net6.0.cs | 10 ++++------ .../api/System.ClientModel.netstandard2.0.cs | 10 ++++------ .../src/Convenience/ResultOperationOfT.cs | 8 ++------ .../src/Convenience/StatusBasedOperation.cs | 4 ++-- 4 files changed, 12 insertions(+), 20 deletions(-) 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 c6a7126c5185e..69306658c9a49 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs @@ -83,10 +83,8 @@ public abstract partial class ResultOperation : System.ClientModel.ResultOper { 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.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.ClientModel.ClientResult WaitForCompletion(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + 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 { @@ -104,8 +102,8 @@ public abstract partial class StatusBasedOperation : System.Cli { 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(TStatus status, 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 f557cf4d0f84d..468fdbb101f9a 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs @@ -83,10 +83,8 @@ public abstract partial class ResultOperation : System.ClientModel.ResultOper { 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.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.ClientModel.ClientResult WaitForCompletion(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForCompletionAsync(System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + 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 { @@ -104,8 +102,8 @@ public abstract partial class StatusBasedOperation : System.Cli { 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(TStatus status, 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/ResultOperationOfT.cs b/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs index 99d9e3817d403..44f9de9c91bfd 100644 --- a/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs +++ b/sdk/core/System.ClientModel/src/Convenience/ResultOperationOfT.cs @@ -16,12 +16,8 @@ protected ResultOperation(string id, PipelineResponse response) : base(id, respo public T? Value { get; protected set; } - public abstract ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default); + public abstract ValueTask> WaitForCompletionAsync(TimeSpan? pollingInterval =default, CancellationToken cancellationToken = default); - public abstract ClientResult WaitForCompletion(CancellationToken cancellationToken = default); - - public abstract ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default); - - public abstract ClientResult WaitForCompletion(TimeSpan pollingInterval, 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/StatusBasedOperation.cs b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs index a705e5ea32f72..01c71a7a9d94f 100644 --- a/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs +++ b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs @@ -17,8 +17,8 @@ protected StatusBasedOperation(string id, TStatus status, PipelineResponse respo public TStatus Status { get; protected set; } - public abstract ValueTask> WaitForStatusUpdateAsync(CancellationToken cancellationToken = default); + public abstract ValueTask> WaitForStatusUpdateAsync(TimeSpan? pollingInterval = default, CancellationToken cancellationToken = default); - public abstract ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(CancellationToken cancellationToken = default); + public abstract ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TimeSpan? pollingInterval = default, CancellationToken cancellationToken = default); } #pragma warning restore CS1591 // public XML comments From dd2b59546fd83d9cf6de60873b668ba10ce00330 Mon Sep 17 00:00:00 2001 From: Anne Thompson Date: Fri, 24 May 2024 17:17:53 -0700 Subject: [PATCH 3/3] Add APIs to Pause and Resume polling --- .../System.ClientModel/api/System.ClientModel.net6.0.cs | 6 ++++-- .../api/System.ClientModel.netstandard2.0.cs | 6 ++++-- .../src/Convenience/StatusBasedOperation.cs | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) 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 69306658c9a49..8577ad5115d37 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs @@ -102,8 +102,10 @@ public abstract partial class StatusBasedOperation : System.Cli { 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + 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 468fdbb101f9a..a8060dab2f09c 100644 --- a/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs +++ b/sdk/core/System.ClientModel/api/System.ClientModel.netstandard2.0.cs @@ -102,8 +102,10 @@ public abstract partial class StatusBasedOperation : System.Cli { 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 System.ClientModel.ClientResult<(TStatus Status, TValue? Value)> WaitForStatusUpdate(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); - public abstract System.Threading.Tasks.ValueTask> WaitForStatusUpdateAsync(TStatus status, System.TimeSpan? pollingInterval = default(System.TimeSpan?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + 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/StatusBasedOperation.cs b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs index 01c71a7a9d94f..2d047013b35f0 100644 --- a/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs +++ b/sdk/core/System.ClientModel/src/Convenience/StatusBasedOperation.cs @@ -20,5 +20,10 @@ protected StatusBasedOperation(string id, TStatus status, PipelineResponse respo 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