From a31bb43dcc828121dcb5c3c97e805f0a6e8fd036 Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Wed, 5 May 2021 12:18:54 -0700 Subject: [PATCH] Update arm response types to match current Azure.Core pattern (#20738) * WIP * wip * Change the accessbility to virtual for Resource.Id * update strawman for operation changes * finalize changes before testing * update ph overloads * move pipeline creation into armoperation * wip * updates based on new OperationInternals * address PR comments * update test classes to use new pattern * final fixes for arm core tests * use mock response instead of null * updates to proto code * add null check around basetype Co-authored-by: YalinLi0312 Co-authored-by: m-nash --- .../InstrumentResultInterceptor.cs | 2 +- .../Azure.Core/tests/Azure.Core.Tests.csproj | 1 + .../tests/TestClients/ArmOperationTest.cs | 47 +++--- .../tests/TestClients/PhArmOperationTest.cs | 31 +++- .../TestClients/TestResourceOperations.cs | 19 +-- .../src/ArmOperation.cs | 83 ----------- .../src/ArmResponse.cs | 46 ------ .../src/ArmVoidOperation.cs | 116 --------------- .../Generated/UpdateResourceGroupOperation.cs | 64 +++++++++ .../src/GenericResourceOperations.cs | 19 ++- .../src/IDeletableResource.cs | 8 +- .../src/Operation/ArmOperation.cs | 100 +++++++++++++ .../src/Operation/PhArmOperation.cs | 136 ++++++++++++++++++ .../src/Operation/PhValueArmOperation.cs | 71 +++++++++ .../src/Operation/PhVoidArmOperation.cs | 90 ++++++++++++ .../src/Placeholder/PhArmOperation.cs | 109 -------------- .../src/Placeholder/ResourceGroupData.cs | 2 +- .../src/ResourceGroupContainer.cs | 4 +- .../src/ResourceGroupOperations.cs | 20 +-- .../src/Response/ArmResponse.cs | 86 +++++++++++ .../src/Response/ArmValueResponse.cs | 28 ++++ .../src/Response/ArmVoidResponse.cs | 58 ++++++++ .../{Adapters => Response}/PhArmResponse.cs | 0 .../tests/Scenario/GenericResourceTests.cs | 2 +- .../Scenario/ResourceGroupOperationsTests.cs | 2 +- .../tests/Unit/ArmResponseTests.cs | 3 +- .../tests/Unit/ResourceTypeFilterTests.cs | 4 +- .../authorization/RoleAssignmentOperations.cs | 16 +-- .../compute/AvailabilitySetOperations.cs | 16 +-- .../compute/RollingUpgradeOperations.cs | 8 +- .../compute/VirtualMachineOperations.cs | 64 ++++----- .../VirtualMachineScaleSetOperations.cs | 16 +-- .../network/LoadBalancerOperations.cs | 16 +-- .../network/NetworkInterfaceOperations.cs | 16 +-- .../network/NetworkSecurityGroupOperations.cs | 16 +-- .../network/PublicIpAddressOperations.cs | 16 +-- .../Proto.Client/network/SubnetOperations.cs | 16 +-- .../network/VirtualNetworkOperations.cs | 16 +-- 38 files changed, 835 insertions(+), 532 deletions(-) delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmOperation.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmResponse.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmVoidOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/UpdateResourceGroupOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/ArmOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhArmOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhValueArmOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhVoidArmOperation.cs delete mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/PhArmOperation.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmResponse.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmValueResponse.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmVoidResponse.cs rename sdk/resourcemanager/Azure.ResourceManager.Core/src/{Adapters => Response}/PhArmResponse.cs (100%) diff --git a/sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs b/sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs index f5de30d6bbcb8..1c94317d018fb 100644 --- a/sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs +++ b/sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs @@ -41,7 +41,7 @@ public void Intercept(IInvocation invocation) if ( // Generated ARM clients will have a property containing the sub-client that ends with Operations. - (invocation.Method.Name.StartsWith("get_") && (type.Name.EndsWith("Operations") || type.BaseType.Name.EndsWith("Operations"))) || + (invocation.Method.Name.StartsWith("get_") && (type.Name.EndsWith("Operations") || (type.BaseType != null && type.BaseType.Name.EndsWith("Operations")))) || // Instrument the container construction methods inside Operations objects (invocation.Method.Name.StartsWith("Get") && type.Name.EndsWith("Container")) || // Instrument the operations construction methods inside Operations objects diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index ac3aaf34aa811..ae7811d3b6d79 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -4,6 +4,7 @@ $(RequiredTargetFrameworks) $(DefineConstants);HAS_INTERNALS_VISIBLE_CORE true + true diff --git a/sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs b/sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs index 3cbc9db31f415..39f8e95a9ca5f 100644 --- a/sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs +++ b/sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs @@ -4,69 +4,66 @@ using System; using System.Threading; using System.Threading.Tasks; +using Azure.Core.TestFramework; using Azure.ResourceManager.Core; namespace Azure.Core.Tests { - public class ArmOperationTest : ArmOperation - where T : class + public class ArmOperationTest : ArmOperation, IOperationSource { - private T _value; + private TestResource _value; private bool _exceptionOnWait; + private OperationOrResponseInternals _operationHelper; protected ArmOperationTest() { } - public ArmOperationTest(T value, bool exceptionOnWait = false) + public ArmOperationTest(TestResource value, bool exceptionOnWait = false) { _value = value; _exceptionOnWait = exceptionOnWait; + _operationHelper = new OperationOrResponseInternals(Response.FromValue(value, new MockResponse(200))); } public override string Id => "testId"; - public override T Value => _value; + public override TestResource Value => _operationHelper.Value; - public override bool HasCompleted => true; + public override bool HasCompleted => _operationHelper.HasCompleted; - public override bool HasValue => true; + public override bool HasValue => _operationHelper.HasValue; - public override Response GetRawResponse() - { - return Response.FromValue(_value, null) as Response; - } + public override Response GetRawResponse() => _operationHelper.GetRawResponse(); - public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) { if (_exceptionOnWait) throw new ArgumentException("FakeArg"); - return new ValueTask>(Response.FromValue(_value, null)); + return new ValueTask>(Response.FromValue(_value, new MockResponse(200))); } - public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) { if (_exceptionOnWait) throw new ArgumentException("FakeArg"); - return new ValueTask>(Response.FromValue(_value, null)); + return new ValueTask>(Response.FromValue(_value, new MockResponse(200))); } - public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) - { - if (_exceptionOnWait) - throw new ArgumentException("FakeArg"); + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatusAsync(cancellationToken); - return new ValueTask(Response.FromValue(_value, null) as Response); - } + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatus(cancellationToken); - public override Response UpdateStatus(CancellationToken cancellationToken = default) + public TestResource CreateResult(Response response, CancellationToken cancellationToken) { - if (_exceptionOnWait) - throw new ArgumentException("FakeArg"); + return _value; + } - return Response.FromValue(_value, null) as Response; + public ValueTask CreateResultAsync(Response response, CancellationToken cancellationToken) + { + return new ValueTask(_value); } } } diff --git a/sdk/core/Azure.Core/tests/TestClients/PhArmOperationTest.cs b/sdk/core/Azure.Core/tests/TestClients/PhArmOperationTest.cs index a87d98ce67a85..a70a99bc5910d 100644 --- a/sdk/core/Azure.Core/tests/TestClients/PhArmOperationTest.cs +++ b/sdk/core/Azure.Core/tests/TestClients/PhArmOperationTest.cs @@ -1,17 +1,44 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Core; + namespace Azure.Core.Tests { - public class PhArmOperationTest : ArmOperationTest + public class PhArmOperationTest : ArmOperation where T : class { + private OperationOrResponseInternals _operationHelper; + + public override T Value => _operationHelper.Value; + + public override bool HasValue => _operationHelper.HasValue; + + public override string Id => "MyId"; + + public override bool HasCompleted => _operationHelper.HasCompleted; + protected PhArmOperationTest() { } - public PhArmOperationTest(T value) : base(value) + public PhArmOperationTest(T value) { + _operationHelper = new OperationOrResponseInternals(Response.FromValue(value, new MockResponse(200))); } + + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operationHelper.WaitForCompletionAsync(cancellationToken); + + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) => _operationHelper.WaitForCompletionAsync(pollingInterval, cancellationToken); + + public override Response GetRawResponse() => _operationHelper.GetRawResponse(); + + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatusAsync(cancellationToken); + + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatus(cancellationToken); } } diff --git a/sdk/core/Azure.Core/tests/TestClients/TestResourceOperations.cs b/sdk/core/Azure.Core/tests/TestClients/TestResourceOperations.cs index 46b5116c18440..f49ac25bf2ccf 100644 --- a/sdk/core/Azure.Core/tests/TestClients/TestResourceOperations.cs +++ b/sdk/core/Azure.Core/tests/TestClients/TestResourceOperations.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Azure.Core.Pipeline; +using Azure.ResourceManager.Core; namespace Azure.Core.Tests { @@ -17,14 +18,14 @@ public virtual TestResourceOperations GetAnotherOperations() return new TestResource(); } - public virtual ArmOperationTest GetArmOperation(bool exceptionOnWait = false, CancellationToken cancellationToken = default) + public virtual ArmOperationTest GetArmOperation(bool exceptionOnWait = false, CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperation"); scope.Start(); try { - return new ArmOperationTest(new TestResource(), exceptionOnWait); + return new ArmOperationTest(new TestResource(), exceptionOnWait); } catch (Exception e) { @@ -33,14 +34,14 @@ public virtual ArmOperationTest GetArmOperation(bool exceptionOnWa } } - public virtual Task> GetArmOperationAsync(bool exceptionOnWait = false, CancellationToken cancellationToken = default) + public virtual Task GetArmOperationAsync(bool exceptionOnWait = false, CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperation"); scope.Start(); try { - return Task.FromResult(new ArmOperationTest(new TestResource(), exceptionOnWait)); + return Task.FromResult(new ArmOperationTest(new TestResource(), exceptionOnWait)); } catch (Exception e) { @@ -81,7 +82,7 @@ public virtual Task> GetArmResponseAsync(Cancellat } } - public virtual ArmOperationTest GetPhArmOperation(CancellationToken cancellationToken = default) + public virtual ArmOperation GetPhArmOperation(CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetPhArmOperation"); scope.Start(); @@ -97,14 +98,14 @@ public virtual ArmOperationTest GetPhArmOperation(CancellationToke } } - public virtual Task> GetPhArmOperationAsync(CancellationToken cancellationToken = default) + public virtual Task> GetPhArmOperationAsync(CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetPhArmOperation"); scope.Start(); try { - return Task.FromResult>(new PhArmOperationTest(new TestResource())); + return Task.FromResult>(new PhArmOperationTest(new TestResource())); } catch (Exception e) { @@ -177,7 +178,7 @@ public virtual Task> GetArmResponseExceptionAsync( } } - public virtual ArmOperationTest GetArmOperationException(CancellationToken cancellationToken = default) + public virtual ArmOperationTest GetArmOperationException(CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperationException"); scope.Start(); @@ -193,7 +194,7 @@ public virtual ArmOperationTest GetArmOperationException(Cancellat } } - public virtual Task> GetArmOperationExceptionAsync(CancellationToken cancellationToken = default) + public virtual Task GetArmOperationExceptionAsync(CancellationToken cancellationToken = default) { using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperationException"); scope.Start(); diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmOperation.cs deleted file mode 100644 index c874438b64ace..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmOperation.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; - -namespace Azure.ResourceManager.Core -{ - /// - /// Abstract class for long-running or synchronous applications. - /// - /// The to return representing the result of the ArmOperation. - public abstract class ArmOperation : Operation - where TOperations : class - { - /// - /// Initializes a new instance of the class for mocking. - /// - protected ArmOperation() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The representing the result of the ArmOperation. - protected ArmOperation(TOperations syncValue) - { - CompletedSynchronously = syncValue != null; - SyncValue = syncValue; - } - - /// - /// Gets a value indicating whether or not the operation completed synchronously. - /// - protected bool CompletedSynchronously { get; } - - /// - /// Gets the representing the result of the ArmOperation. - /// - protected TOperations SyncValue { get; } - - /// - /// Waits for the completion of the long running operations. - /// - /// A token to allow the caller to cancel the call to the service. The default value is . - /// A response with the operation for this resource. - /// - /// Details on long running operation object. - /// - public Response WaitForCompletion(CancellationToken cancellationToken = default) - { - return WaitForCompletion(OperationHelpers.DefaultPollingInterval.Seconds, cancellationToken); - } - - /// - /// Waits for the completion of the long running operations. - /// - /// The polling interval in seconds to check for status. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// A response with the operation for this resource. - /// - /// Details on long running operation object. - /// - public Response WaitForCompletion(int pollingInterval, CancellationToken cancellationToken = default) - { - var polling = TimeSpan.FromSeconds(pollingInterval); - while (true) - { - UpdateStatus(cancellationToken); - if (HasCompleted) - { - Response response = Response.FromValue(Value, GetRawResponse()); - return new PhArmResponse(response, old => old); - } - - Task.Delay(pollingInterval, cancellationToken).Wait(cancellationToken); - } - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmResponse.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmResponse.cs deleted file mode 100644 index c9f4e005822d2..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmResponse.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -namespace Azure.ResourceManager.Core -{ - /// - /// A class representing a response object from azure resource manager service. - /// - public sealed class ArmResponse : ArmResponse - { - private readonly Response _response; - - /// - /// Initializes a new instance of the class. - /// - /// The azure response object to wrap. - /// If is null. - public ArmResponse(Response response) - { - if (response is null) - throw new ArgumentNullException(nameof(response)); - - _response = response; - } - - /// - public override Response Value => _response; - - /// - public override Response GetRawResponse() - { - return _response; - } - } - - /// - /// A class representing a response object from azure resource manager service. - /// - /// The operations object return by the api call. - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Allowed when we have a generic version of the same type")] - public abstract class ArmResponse : Response - { - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmVoidOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmVoidOperation.cs deleted file mode 100644 index f0d24e3e714e4..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmVoidOperation.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.ResourceManager.Core -{ - /// - /// Generic ARM long running operation class for operations with no returned value - /// - public sealed class ArmVoidOperation : ArmOperation - { - private readonly Operation _wrapped; - - /// - /// Initializes a new instance of the class. - /// - /// The operation that has a response which has no body. - public ArmVoidOperation(Operation other) - : base(null) - { - if (other is null) - throw new ArgumentNullException(nameof(other)); - - _wrapped = other; - } - - /// - /// Initializes a new instance of the class. - /// - /// The response which has no body. - public ArmVoidOperation(Response other) - : base(other) - { - if (other is null) - throw new ArgumentNullException(nameof(other)); - } - - /// - public override string Id => _wrapped?.Id; - - /// - public override Response Value => SyncValue; - - /// - public override bool HasCompleted => CompletedSynchronously || _wrapped.HasCompleted; - - /// - public override bool HasValue => CompletedSynchronously || _wrapped.HasValue; - - /// - public override Response GetRawResponse() - { - return CompletedSynchronously ? SyncValue : _wrapped.GetRawResponse(); - } - - /// - public override Response UpdateStatus(CancellationToken cancellationToken = default) - { - return CompletedSynchronously ? SyncValue : _wrapped.UpdateStatus(cancellationToken); - } - - /// - public override async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) - { - return CompletedSynchronously ? SyncValue : await _wrapped.UpdateStatusAsync(cancellationToken).ConfigureAwait(false); - } - - /// - public override async ValueTask> WaitForCompletionAsync( - CancellationToken cancellationToken = default) - { - return CompletedSynchronously - ? new WrappingResponse(SyncValue) - : await _wrapped.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); - } - - /// - public override async ValueTask> WaitForCompletionAsync( - TimeSpan pollingInterval, - CancellationToken cancellationToken) - { - return CompletedSynchronously - ? new WrappingResponse(SyncValue) - : await _wrapped.WaitForCompletionAsync(pollingInterval, cancellationToken).ConfigureAwait(false); - } - - /// - /// A class which wraps a response with no body. - /// - internal class WrappingResponse : ArmResponse - { - private readonly Response _wrapped; - - /// - /// Initializes a new instance of the class. - /// - /// The response object to wrap. - public WrappingResponse(Response wrapped) - { - _wrapped = wrapped; - } - - /// - public override Response Value => _wrapped; - - /// - public override Response GetRawResponse() - { - return _wrapped; - } - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/UpdateResourceGroupOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/UpdateResourceGroupOperation.cs new file mode 100644 index 0000000000000..86b8bea8bbd56 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/UpdateResourceGroupOperation.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Core +{ + internal class UpdateResourceGroupOperation : ArmOperation, IOperationSource + { + private readonly ResourceOperationsBase _operations; + private readonly OperationOrResponseInternals _operationHelper; + + protected UpdateResourceGroupOperation() + { + } + + internal UpdateResourceGroupOperation(ResourceOperationsBase operations, ArmResponse response) + { + _operationHelper = new OperationOrResponseInternals(response); + _operations = operations; + } + + public override ResourceGroup Value => _operationHelper.Value; + + public override bool HasValue => _operationHelper.HasValue; + + public override string Id => throw new System.NotImplementedException(); + + public override bool HasCompleted => _operationHelper.HasCompleted; + + public override Response GetRawResponse() => _operationHelper.GetRawResponse(); + + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatus(cancellationToken); + + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatusAsync(cancellationToken); + + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operationHelper.WaitForCompletionAsync(cancellationToken); + + public override ValueTask> WaitForCompletionAsync(System.TimeSpan pollingInterval, CancellationToken cancellationToken) => _operationHelper.WaitForCompletionAsync(pollingInterval, cancellationToken); + + ResourceGroup IOperationSource.CreateResult(Response response, CancellationToken cancellationToken) + { + using var document = JsonDocument.Parse(response.ContentStream); + return GetResourceGrouop(document); + } + + async ValueTask IOperationSource.CreateResultAsync(Response response, CancellationToken cancellationToken) + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + return GetResourceGrouop(document); + } + + private ResourceGroup GetResourceGrouop(JsonDocument document) + { + var method = typeof(ResourceManager.Resources.Models.ResourceGroup).GetMethod("DeserializeResourceGroup", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); + var obj = method.Invoke(null, new object[] { document.RootElement }); + return new ResourceGroup(_operations, new ResourceGroupData(obj as ResourceManager.Resources.Models.ResourceGroup)); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/GenericResourceOperations.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/GenericResourceOperations.cs index 9d22d3af5d686..921734c7ce423 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/GenericResourceOperations.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/GenericResourceOperations.cs @@ -51,9 +51,9 @@ private ResourcesOperations Operations /// /// A token allowing immediate cancellation of any blocking call performed during the deletion. /// The status of the delete operation. - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDeleteById(Id, GetApiVersion(cancellationToken), cancellationToken).WaitForCompletion(cancellationToken)); + return ArmResponse.FromResponse(Operations.StartDeleteById(Id, GetApiVersion(cancellationToken), cancellationToken).WaitForCompletion(cancellationToken)); } /// @@ -61,11 +61,11 @@ public ArmResponse Delete(CancellationToken cancellationToken = defaul /// /// A token allowing immediate cancellation of any blocking call performed during the deletion. /// A that on completion returns the status of the delete operation. - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { var operation = await Operations.StartDeleteByIdAsync(Id, await GetApiVersionAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); var result = await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); - return new ArmResponse(result); + return ArmResponse.FromResponse(result); } /// @@ -77,9 +77,9 @@ public async Task> DeleteAsync(CancellationToken cancellat /// /// Details on long running operation object. /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDeleteById(Id, GetApiVersion(cancellationToken), cancellationToken)); + return new PhVoidArmOperation(Operations.StartDeleteById(Id, GetApiVersion(cancellationToken), cancellationToken)); } /// @@ -93,17 +93,16 @@ public ArmOperation StartDelete(CancellationToken cancellationToken = /// /// Details on long running operation object. /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { var operation = await Operations.StartDeleteByIdAsync(Id, await GetApiVersionAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); - return new ArmVoidOperation(operation); + return new PhVoidArmOperation(operation); } /// public ArmResponse AddTag(string key, string value, CancellationToken cancellationToken = default) { GenericResource resource = GetResource(cancellationToken); - // Potential optimization on tags set, remove NOOP to bypass the call. resource.Data.Tags[key] = value; var apiVersion = GetApiVersion(cancellationToken); return new PhArmResponse( @@ -130,7 +129,7 @@ public ArmOperation StartAddTag(string key, string value, Cance resource.Data.Tags[key] = value; var apiVersion = GetApiVersion(cancellationToken); return new PhArmOperation( - Operations.StartUpdateById(Id, apiVersion, resource.Data, cancellationToken).WaitForCompletionAsync(cancellationToken).EnsureCompleted(), + Operations.StartUpdateById(Id, apiVersion, resource.Data, cancellationToken), v => new GenericResource(this, new GenericResourceData(v))); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/IDeletableResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/IDeletableResource.cs index 782049e856f9b..f77a93d5dedfe 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/IDeletableResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/IDeletableResource.cs @@ -16,14 +16,14 @@ public interface IDeletableResource /// /// A token allowing immediate cancellation of any blocking call performed during the deletion. /// The status of the delete operation. - ArmResponse Delete(CancellationToken cancellationToken = default); + ArmResponse Delete(CancellationToken cancellationToken = default); /// /// Delete the resource. /// /// A token allowing immediate cancellation of any blocking call performed during the deletion. /// A that on completion returns the status of the delete operation. - Task> DeleteAsync(CancellationToken cancellationToken = default); + Task DeleteAsync(CancellationToken cancellationToken = default); /// /// Delete the resource. @@ -34,7 +34,7 @@ public interface IDeletableResource /// /// Details on long running operation object. /// - ArmOperation StartDelete(CancellationToken cancellationToken = default); + ArmOperation StartDelete(CancellationToken cancellationToken = default); /// /// Delete the resource. This call returns a Task that blocks until the delete operation is accepted on the service. @@ -47,6 +47,6 @@ public interface IDeletableResource /// /// Details on long running operation object. /// - Task> StartDeleteAsync(CancellationToken cancellationToken = default); + Task StartDeleteAsync(CancellationToken cancellationToken = default); } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/ArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/ArmOperation.cs new file mode 100644 index 0000000000000..76f0509ab5a72 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/ArmOperation.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// Abstract class for long-running or synchronous applications. + /// + public abstract class ArmOperation : Operation + { + /// + /// Initializes a new instance of the class for mocking. + /// + protected ArmOperation() + { + } + + /// + /// Waits for the completion of the long running operations. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// The response with the final state of the operation. + public virtual Response WaitForCompletion(CancellationToken cancellationToken = default) + { + return WaitForCompletion(OperationInternals.DefaultPollingInterval, cancellationToken); + } + + /// + /// Waits for the completion of the long running operations. + /// + /// The polling interval to check for status. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// The response with the final state of the operation. + public virtual Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) + { + while (true) + { + UpdateStatus(cancellationToken); + if (HasCompleted) + { + return new ArmVoidResponse(GetRawResponse()); + } + + Task.Delay(pollingInterval, cancellationToken).Wait(cancellationToken); + } + } + } + + /// + /// Abstract class for long-running or synchronous applications. + /// + /// The to return representing the result of the ArmOperation. +#pragma warning disable SA1402 // File may only contain a single type + public abstract class ArmOperation : Operation + where TOperations : notnull +#pragma warning restore SA1402 // File may only contain a single type + { + /// + /// Initializes a new instance of the class for mocking. + /// + protected ArmOperation() + { + } + + /// + /// Waits for the completion of the long running operations. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// The response with the final state of the operation. + public virtual Response WaitForCompletion(CancellationToken cancellationToken = default) + { + return WaitForCompletion(OperationInternals.DefaultPollingInterval, cancellationToken); + } + + /// + /// Waits for the completion of the long running operations. + /// + /// The polling interval to check for status. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// The response with the final state of the operation. + public virtual Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) + { + while (true) + { + UpdateStatus(cancellationToken); + if (HasCompleted) + { + return Response.FromValue(Value, GetRawResponse()) as ArmResponse; + } + + Task.Delay(pollingInterval, cancellationToken).Wait(cancellationToken); + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhArmOperation.cs new file mode 100644 index 0000000000000..b0f9777dd9272 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhArmOperation.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing an arm operation wrapper object. + /// + /// The to convert TModel into. + /// The model returned by existing Operation methods. + public class PhArmOperation : ArmOperation + where TOperations : class + where TModel : class + { + private readonly Func _converter; + private readonly Operation _wrappedOperation; + private readonly ArmOperation _wrappedResponseOperation; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected PhArmOperation() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The results to wrap. + /// The function used to convert from existing type to new type. + public PhArmOperation(Operation wrapped, Func converter) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + if (converter is null) + throw new ArgumentNullException(nameof(converter)); + + _wrappedOperation = wrapped; + _converter = converter; + } + + /// + /// Initializes a new instance of the class. + /// + /// The results to wrap. + /// The function used to convert from existing type to new type. + public PhArmOperation(Response wrapped, Func converter) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + if (converter is null) + throw new ArgumentNullException(nameof(converter)); + + _wrappedResponseOperation = new PhValueArmOperation(wrapped); + _converter = converter; + } + + private bool _doesWrapOperation => _wrappedResponseOperation is null; + + /// + public override string Id => _wrappedOperation?.Id; + + /// + public override TOperations Value => _converter(_doesWrapOperation ? _wrappedOperation.Value : _wrappedResponseOperation.Value); + + /// + public override bool HasCompleted => _doesWrapOperation ? _wrappedOperation.HasCompleted : _wrappedResponseOperation.HasCompleted; + + /// + public override bool HasValue => _doesWrapOperation ? _wrappedOperation.HasValue : _wrappedResponseOperation.HasValue; + + /// + public override Response GetRawResponse() + { + return _doesWrapOperation ? _wrappedOperation.GetRawResponse() : _wrappedResponseOperation.GetRawResponse(); + } + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) + { + return _doesWrapOperation ? _wrappedOperation.UpdateStatus(cancellationToken) : _wrappedResponseOperation.UpdateStatus(cancellationToken); + } + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) + { + return _doesWrapOperation + ? _wrappedOperation.UpdateStatusAsync(cancellationToken) + : _wrappedResponseOperation.UpdateStatusAsync(cancellationToken); + } + + /// + public override async ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) + { + var task = WaitForCompletionAsync(OperationInternals.DefaultPollingInterval, cancellationToken); + return await task.ConfigureAwait(false); + } + + /// + public override async ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) + { + var value = _doesWrapOperation + ? await _wrappedOperation.WaitForCompletionAsync(pollingInterval, cancellationToken).ConfigureAwait(false) + : await _wrappedResponseOperation.WaitForCompletionAsync(pollingInterval, cancellationToken).ConfigureAwait(false); + return Response.FromValue(_converter(value.Value), GetRawResponse()); + } + + /// + public override Response WaitForCompletion(CancellationToken cancellationToken = default) + { + return WaitForCompletion(OperationInternals.DefaultPollingInterval, cancellationToken); + } + + /// + public override Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) + { + while (true) + { + UpdateStatus(cancellationToken); + if (HasCompleted) + { + return Response.FromValue(Value, GetRawResponse()) as ArmResponse; + } + + Task.Delay(pollingInterval, cancellationToken).Wait(cancellationToken); + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhValueArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhValueArmOperation.cs new file mode 100644 index 0000000000000..91d7a97836a2e --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhValueArmOperation.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing an arm operation wrapper object. + /// + internal class PhValueArmOperation : ArmOperation + where TOperations : class + { + private readonly Operation _wrappedOperation; + private readonly OperationOrResponseInternals _wrappedResponseOperation; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected PhValueArmOperation() + { + } + + /// + /// Initializes a new instance of the . + /// + /// The operation object to wrap. + public PhValueArmOperation(Operation wrapped) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + _wrappedOperation = wrapped; + } + + /// + /// Initializes a new instance of the . + /// + /// The response object to wrap. + public PhValueArmOperation(Response wrapped) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + _wrappedResponseOperation = new OperationOrResponseInternals(wrapped); + } + + private bool _doesWrapOperation => _wrappedResponseOperation is null; + + public override TOperations Value => _doesWrapOperation ? _wrappedOperation.Value : _wrappedResponseOperation.Value; + + public override bool HasValue => _doesWrapOperation ? _wrappedOperation.HasValue : _wrappedResponseOperation.HasValue; + + public override string Id => _wrappedOperation?.Id; + + public override bool HasCompleted => _doesWrapOperation ? _wrappedOperation.HasCompleted : _wrappedResponseOperation.HasCompleted; + + public override Response GetRawResponse() => _doesWrapOperation? _wrappedOperation.GetRawResponse() : _wrappedResponseOperation.GetRawResponse(); + + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _doesWrapOperation ? _wrappedOperation.UpdateStatus(cancellationToken) : _wrappedResponseOperation.UpdateStatus(cancellationToken); + + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _doesWrapOperation ? _wrappedOperation.UpdateStatusAsync(cancellationToken) : _wrappedResponseOperation.UpdateStatusAsync(cancellationToken); + + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _doesWrapOperation ? _wrappedOperation.WaitForCompletionAsync(cancellationToken) : _wrappedResponseOperation.WaitForCompletionAsync(cancellationToken); + + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) => _doesWrapOperation ? _wrappedOperation.WaitForCompletionAsync(pollingInterval, cancellationToken) : _wrappedResponseOperation.WaitForCompletionAsync(pollingInterval, cancellationToken); + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhVoidArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhVoidArmOperation.cs new file mode 100644 index 0000000000000..23be0560b60d9 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Operation/PhVoidArmOperation.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing an arm operation wrapper object. + /// + public class PhVoidArmOperation : ArmOperation + { + private readonly Operation _wrappedOperation; + private readonly OperationOrResponseInternals _wrappedResponseOperation; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected PhVoidArmOperation() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The results to wrap. + public PhVoidArmOperation(Operation wrapped) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + _wrappedOperation = wrapped; + } + + /// + /// Initializes a new instance of the class. + /// + /// The results to wrap. + public PhVoidArmOperation(Response wrapped) + { + if (wrapped is null) + throw new ArgumentNullException(nameof(wrapped)); + + _wrappedResponseOperation = new OperationOrResponseInternals(Response.FromValue(wrapped, wrapped)); + } + + private bool _doesWrapOperation => _wrappedResponseOperation is null; + + /// + public override string Id => _wrappedOperation?.Id; + + /// + public override bool HasCompleted => _doesWrapOperation ? _wrappedOperation.HasCompleted : _wrappedResponseOperation.HasCompleted; + + /// + public override Response GetRawResponse() => _doesWrapOperation ? _wrappedOperation.GetRawResponse() : _wrappedResponseOperation.GetRawResponse(); + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _doesWrapOperation ? _wrappedOperation.UpdateStatus(cancellationToken) : _wrappedResponseOperation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _doesWrapOperation ? _wrappedOperation.UpdateStatusAsync(cancellationToken) : _wrappedResponseOperation.UpdateStatusAsync(cancellationToken); + + /// + public override async ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) + { + var task = WaitForCompletionResponseAsync(OperationInternals.DefaultPollingInterval, cancellationToken); + return await task.ConfigureAwait(false); + } + + /// + public override async ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) + { + if (_doesWrapOperation) + { + return await _wrappedOperation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken).ConfigureAwait(false); + } + else + { + var taskResponseResponse = await _wrappedResponseOperation.WaitForCompletionAsync(pollingInterval, cancellationToken).ConfigureAwait(false); + var taskResponse = Task.FromResult(taskResponseResponse.Value); + var valueTask = new ValueTask(taskResponse); + return await valueTask.ConfigureAwait(false); + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/PhArmOperation.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/PhArmOperation.cs deleted file mode 100644 index 9f293c1d5364b..0000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/PhArmOperation.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.ResourceManager.Core -{ - /// - /// A calss representing an arm operation wrapper object. - /// - /// The to convert TModel into. - /// The model returned by existing Operation methods. - public class PhArmOperation : ArmOperation - where TOperations : class - where TModel : class - { - private readonly Func _converter; - private readonly Response _syncWrapped; - private readonly Operation _wrapped; - - /// - /// Initializes a new instance of the class for mocking. - /// - protected PhArmOperation() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The results to wrap. - /// The function used to convert from existing type to new type. - public PhArmOperation(Operation wrapped, Func converter) - : base(null) - { - _wrapped = wrapped; - _converter = converter; - } - - /// - /// Initializes a new instance of the class. - /// - /// The results to wrap. - /// The function used to convert from existing type to new type. - public PhArmOperation(Response wrapped, Func converter) - : base(converter(wrapped.Value)) - { - _converter = converter; - _syncWrapped = wrapped; - } - - /// - public override string Id => _wrapped?.Id; - - /// - public override TOperations Value => CompletedSynchronously ? SyncValue : _converter(_wrapped.Value); - - /// - public override bool HasCompleted => CompletedSynchronously || _wrapped.HasCompleted; - - /// - public override bool HasValue => CompletedSynchronously || _wrapped.HasValue; - - /// - public override Response GetRawResponse() - { - return CompletedSynchronously ? _syncWrapped.GetRawResponse() : _wrapped.GetRawResponse(); - } - - /// - public override Response UpdateStatus(CancellationToken cancellationToken = default) - { - return CompletedSynchronously ? _syncWrapped.GetRawResponse() : _wrapped.UpdateStatus(cancellationToken); - } - - /// - public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) - { - return CompletedSynchronously - ? new ValueTask(_syncWrapped.GetRawResponse()) - : _wrapped.UpdateStatusAsync(cancellationToken); - } - - /// - public override async ValueTask> WaitForCompletionAsync( - CancellationToken cancellationToken = default) - { - return CompletedSynchronously - ? new PhArmResponse(_syncWrapped, _converter) - : new PhArmResponse( - await _wrapped.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false), - _converter); - } - - /// - public override async ValueTask> WaitForCompletionAsync( - TimeSpan pollingInterval, - CancellationToken cancellationToken) - { - return CompletedSynchronously - ? new PhArmResponse(_syncWrapped, _converter) - : new PhArmResponse( - await _wrapped.WaitForCompletionAsync(pollingInterval, cancellationToken).ConfigureAwait(false), - _converter); - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/ResourceGroupData.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/ResourceGroupData.cs index db26673c18d79..15fdf78eb9eae 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/ResourceGroupData.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Placeholder/ResourceGroupData.cs @@ -11,7 +11,7 @@ namespace Azure.ResourceManager.Core /// /// A class representing the ResourceGroup data model. /// - public class ResourceGroupData : TrackedResource + public partial class ResourceGroupData : TrackedResource { /// /// Initializes a new instance of the class. diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupContainer.cs index f1b3f4f968d85..538ad8fb78b26 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupContainer.cs @@ -160,8 +160,8 @@ public ArmOperation StartCreateOrUpdate(string name, ResourceGrou try { return new PhArmOperation( - Operations.CreateOrUpdate(name, resourceDetails, cancellationToken), - g => new ResourceGroup(Parent, new ResourceGroupData(g))); + Operations.CreateOrUpdate(name, resourceDetails, cancellationToken), + g => new ResourceGroup(Parent, new ResourceGroupData(g))); } catch (Exception e) { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupOperations.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupOperations.cs index b0911df20d78c..86372c821d3d2 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupOperations.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceGroupOperations.cs @@ -80,15 +80,15 @@ protected ResourceGroupOperations(ResourceOperationsBase options, ResourceGroupR /// When you delete a resource group, all of its resources are also deleted. Deleting a resource group deletes all of its template deployments and currently stored operations. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// A response with the operation for this resource. - public virtual ArmResponse Delete(CancellationToken cancellationToken = default) + /// A response with the operation for this resource. + public virtual ArmResponse Delete(CancellationToken cancellationToken = default) { using var scope = Diagnostics.CreateScope("ResourceGroupOperations.Delete"); scope.Start(); try { - return new ArmResponse(Operations.StartDelete(Id.Name, cancellationToken).WaitForCompletion(cancellationToken)); + return ArmResponse.FromResponse(Operations.StartDelete(Id.Name, cancellationToken).WaitForCompletion(cancellationToken)); } catch (Exception e) { @@ -101,15 +101,15 @@ public virtual ArmResponse Delete(CancellationToken cancellationToken /// When you delete a resource group, all of its resources are also deleted. Deleting a resource group deletes all of its template deployments and currently stored operations. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// A that on completion returns a response with the operation for this resource. - public virtual async Task> DeleteAsync(CancellationToken cancellationToken = default) + /// A that on completion returns a response with the operation for this resource. + public virtual async Task DeleteAsync(CancellationToken cancellationToken = default) { using var scope = Diagnostics.CreateScope("ResourceGroupOperations.Delete"); scope.Start(); try { - return new ArmResponse(await Operations.StartDelete(Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); + return ArmResponse.FromResponse(await Operations.StartDelete(Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); } catch (Exception e) { @@ -126,14 +126,14 @@ public virtual async Task> DeleteAsync(CancellationToken c /// /// Details on long running operation object. /// - public virtual ArmOperation StartDelete(CancellationToken cancellationToken = default) + public virtual ArmOperation StartDelete(CancellationToken cancellationToken = default) { using var scope = Diagnostics.CreateScope("ResourceGroupOperations.StartDelete"); scope.Start(); try { - return new ArmVoidOperation(Operations.StartDelete(Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.Name, cancellationToken)); } catch (Exception e) { @@ -150,14 +150,14 @@ public virtual ArmOperation StartDelete(CancellationToken cancellation /// /// Details on long running operation object. /// - public virtual async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public virtual async Task StartDeleteAsync(CancellationToken cancellationToken = default) { using var scope = Diagnostics.CreateScope("ResourceGroupOperations.StartDelete"); scope.Start(); try { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.Name, cancellationToken).ConfigureAwait(false)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.Name, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmResponse.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmResponse.cs new file mode 100644 index 0000000000000..f647cd14422bb --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmResponse.cs @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing a response object from azure resource manager service. + /// + public abstract class ArmResponse : Response + { + /// + /// Creates a new instance of with the provided value and HTTP response. + /// + /// The type of the value. + /// The value. + /// The HTTP response. + /// A new instance of with the provided value and HTTP response. + /// Throws if response or value are null. + public static ArmResponse FromValue(TOperations value, ArmResponse response) + { + if (value is null) + throw new ArgumentNullException(nameof(value)); + + if (response is null) + throw new ArgumentNullException(nameof(response)); + + return new ArmValueResponse(response, value); + } + + /// + /// Creates a new instance of with the provided value and HTTP response. + /// + /// The HTTP response. + /// A new instance of with the provided value and HTTP response. + /// Throws if response is null. + public static ArmResponse FromResponse(Response response) + { + if (response is null) + throw new ArgumentNullException(nameof(response)); + + return new ArmVoidResponse(response); + } + + /// + /// Gets the correlation id from x-ms-correlation-id. + /// + public string CorrelationId + { + get + { + string correlationId = null; + Headers.TryGetValue("x-ms-correlation-id", out correlationId); + return correlationId; + } + } + } + + /// + /// A class representing a response object from azure resource manager service. + /// + /// The operations object return by the api call. + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Allowed when we have a generic version of the same type")] + public abstract class ArmResponse : Response + { + /// + /// Returns the value of this object. + /// + /// The instance. + public static implicit operator TOperations(ArmResponse response) => response.Value; + + /// + /// Gets the correlation id from x-ms-correlation-id. + /// + public string CorrelationId + { + get + { + string correlationId = null; + GetRawResponse().Headers.TryGetValue("x-ms-correlation-id", out correlationId); + return correlationId; + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmValueResponse.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmValueResponse.cs new file mode 100644 index 0000000000000..d3494f60cca7b --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmValueResponse.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.ResourceManager.Core +{ + internal class ArmValueResponse : ArmResponse + { + private readonly ArmResponse _response; + + public ArmValueResponse(ArmResponse response, TOperations value) + { + if (response is null) + throw new ArgumentNullException(nameof(response)); + + if (value is null) + throw new ArgumentNullException(nameof(value)); + + _response = response; + Value = value; + } + + public override TOperations Value { get; } + + public override Response GetRawResponse() => _response; + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmVoidResponse.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmVoidResponse.cs new file mode 100644 index 0000000000000..a1bdfd00e967b --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/ArmVoidResponse.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + internal class ArmVoidResponse : ArmResponse + { + private readonly Response _response; + + public ArmVoidResponse(Response response) + { + if (response is null) + throw new ArgumentNullException(nameof(response)); + + _response = response; + } + + /// + public override int Status => _response.Status; + + /// + public override string ReasonPhrase => _response.ReasonPhrase; + + /// + public override Stream ContentStream + { + get => _response.ContentStream; + set => _response.ContentStream = value; + } + + /// + public override string ClientRequestId + { + get => _response.ClientRequestId; + set => _response.ClientRequestId = value; + } + + /// + public override void Dispose() => _response.Dispose(); + + /// + protected override bool ContainsHeader(string name) => _response.Headers.Contains(name); + + /// + protected override IEnumerable EnumerateHeaders() => _response.Headers; + + /// + protected override bool TryGetHeader(string name, out string value) => _response.Headers.TryGetValue(name, out value); + + /// + protected override bool TryGetHeaderValues(string name, out IEnumerable values) => _response.Headers.TryGetValues(name, out values); + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Adapters/PhArmResponse.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/PhArmResponse.cs similarity index 100% rename from sdk/resourcemanager/Azure.ResourceManager.Core/src/Adapters/PhArmResponse.cs rename to sdk/resourcemanager/Azure.ResourceManager.Core/src/Response/PhArmResponse.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/GenericResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/GenericResourceTests.cs index 413d52b711df1..e2d08c7557dc9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/GenericResourceTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/GenericResourceTests.cs @@ -26,7 +26,7 @@ public async Task LocalOneTimeSetup() { _rgName = SessionRecording.GenerateAssetName("testRg-"); var subscription = await GlobalClient.GetSubscriptions().TryGetAsync(SessionEnvironment.SubscriptionId); - _ = subscription.GetResourceGroups().Construct(_location).StartCreateOrUpdateAsync(_rgName).ConfigureAwait(false).GetAwaiter().GetResult().Value; + _ = await subscription.GetResourceGroups().Construct(_location).StartCreateOrUpdateAsync(_rgName).ConfigureAwait(false); StopSessionRecording(); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResourceGroupOperationsTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResourceGroupOperationsTests.cs index 379c2ff918260..51e8b349c248e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResourceGroupOperationsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResourceGroupOperationsTests.cs @@ -31,7 +31,7 @@ public async Task StartDeleteRg() var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg")); ResourceGroup rg = await rgOp.WaitForCompletionAsync(); var deleteOp = await rg.StartDeleteAsync(); - await deleteOp.WaitForCompletionAsync(); + await deleteOp.WaitForCompletionResponseAsync(); } [TestCase] diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ArmResponseTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ArmResponseTests.cs index 06e502e0ed5fe..868671e7a9c35 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ArmResponseTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ArmResponseTests.cs @@ -12,8 +12,7 @@ public class ArmResponseTests [TestCase] public void TestArmResponseParamCheck() { - Assert.Throws(() => { new ArmResponse(null); }); - + Assert.Throws(() => { ArmResponse.FromResponse(null); }); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeFilterTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeFilterTests.cs index 208c970bf67b1..7aa0b03b0063d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeFilterTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeFilterTests.cs @@ -13,8 +13,8 @@ public class ResourceTypeFilterTests [TestCase] public void TestResourceTypeFilterParamCheck() { - Assert.Throws(() => { new ArmVoidOperation((Operation)null); }); - Assert.Throws(() => { new ArmVoidOperation((Response)null); }); + Assert.Throws(() => { new PhVoidArmOperation((Operation)null); }); + Assert.Throws(() => { new PhVoidArmOperation((Response)null); }); } } } diff --git a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs index adc08ef924d59..445c5b9a24d01 100644 --- a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs +++ b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs @@ -62,27 +62,27 @@ internal RoleAssignmentOperations(OperationsBase operation, ResourceIdentifier i private RoleAssignmentsOperations Operations { get; } /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.DeleteById(Id, cancellationToken).GetRawResponse()); + return ArmResponse.FromResponse(Operations.DeleteById(Id, cancellationToken).GetRawResponse()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.DeleteByIdAsync(Id, cancellationToken)).GetRawResponse()); + return ArmResponse.FromResponse((await Operations.DeleteByIdAsync(Id, cancellationToken)).GetRawResponse()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.DeleteById(Id, cancellationToken).GetRawResponse()); + return new PhVoidArmOperation(Operations.DeleteById(Id, cancellationToken).GetRawResponse()); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation((await Operations.DeleteByIdAsync(Id, cancellationToken)).GetRawResponse()); + return new PhVoidArmOperation((await Operations.DeleteByIdAsync(Id, cancellationToken)).GetRawResponse()); } /// diff --git a/sdk/resourcemanager/Proto.Client/compute/AvailabilitySetOperations.cs b/sdk/resourcemanager/Proto.Client/compute/AvailabilitySetOperations.cs index b35e3ae633bd8..2abd922c1d867 100644 --- a/sdk/resourcemanager/Proto.Client/compute/AvailabilitySetOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/AvailabilitySetOperations.cs @@ -58,27 +58,27 @@ protected AvailabilitySetOperations(ResourceOperationsBase options, ResourceGrou ClientOptions.Convert()).AvailabilitySets; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.Delete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return ArmResponse.FromResponse(Operations.Delete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse(await Operations.DeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return ArmResponse.FromResponse(await Operations.DeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.Delete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.Delete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.DeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.DeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs index 8d6dbc2c239dd..980921f3de9b9 100644 --- a/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs @@ -60,16 +60,16 @@ await Operations.GetLatestAsync(ParentId.ResourceGroupName, ParentId.Name, cance // Note: Singleton may have different operations such as GET/PUT/PATCH/POST or a combination of these // Individual methods will be generated as they are declared - public ArmResponse Cancel(CancellationToken cancellationToken = default) + public ArmResponse Cancel(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations + return ArmResponse.FromResponse(Operations .StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } - public async Task> CancelAsync(CancellationToken cancellationToken = default) + public async Task CancelAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations + return ArmResponse.FromResponse((await Operations .StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken))); } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs index 5b5a04c8f6c8b..9c6ffc18884ca 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs @@ -70,27 +70,27 @@ public static VirtualMachineOperations FromGeneric(GenericResourceOperations gen } /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } #region PowerOn @@ -98,42 +98,42 @@ public async Task> StartDeleteAsync(CancellationToken can /// The operation to start a virtual machine. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// A response with the operation for this resource. - public ArmResponse PowerOn(CancellationToken cancellationToken = default) + /// A response with the operation for this resource. + public ArmResponse PowerOn(CancellationToken cancellationToken = default) { var operation = Operations.StartStart(Id.ResourceGroupName, Id.Name, cancellationToken); - return new ArmResponse(operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse(operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// /// The operation to start a virtual machine. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// A that on completion returns a response with the operation for this resource. - public async Task> PowerOnAsync(CancellationToken cancellationToken = default) + /// A that on completion returns a response with the operation for this resource. + public async Task PowerOnAsync(CancellationToken cancellationToken = default) { var operation = await Operations.StartStartAsync(Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false); - return new ArmResponse(await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); + return ArmResponse.FromResponse(await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); } /// /// The operation to start a virtual machine. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// An that allows polling for completion of the operation. - public ArmOperation StartPowerOn(CancellationToken cancellationToken = default) + /// An that allows polling for completion of the operation. + public ArmOperation StartPowerOn(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartStart(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartStart(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// /// The operation to start a virtual machine. /// /// A token to allow the caller to cancel the call to the service. The default value is . - /// A that on completion returns an that allows polling for completion of the operation. - public async Task> StartPowerOnAsync(CancellationToken cancellationToken = default) + /// A that on completion returns an that allows polling for completion of the operation. + public async Task StartPowerOnAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartStartAsync(Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false)); + return new PhVoidArmOperation(await Operations.StartStartAsync(Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false)); } #endregion @@ -143,11 +143,11 @@ public async Task> StartPowerOnAsync(CancellationToken ca /// /// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. /// A token to allow the caller to cancel the call to the service. The default value is . - /// A response with the operation for this resource. - public ArmResponse PowerOff(bool? skipShutdown = null, CancellationToken cancellationToken = default) + /// A response with the operation for this resource. + public ArmResponse PowerOff(bool? skipShutdown = null, CancellationToken cancellationToken = default) { var operation = Operations.StartPowerOff(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken); - return new ArmResponse(operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse(operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// @@ -155,11 +155,11 @@ public ArmResponse PowerOff(bool? skipShutdown = null, CancellationTok /// /// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. /// A token to allow the caller to cancel the call to the service. The default value is . - /// A that on completion returns a response with the operation for this resource. - public async Task> PowerOffAsync(bool? skipShutdown = null, CancellationToken cancellationToken = default) + /// A that on completion returns a response with the operation for this resource. + public async Task PowerOffAsync(bool? skipShutdown = null, CancellationToken cancellationToken = default) { var operation = await Operations.StartPowerOffAsync(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken).ConfigureAwait(false); - return new ArmResponse(await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); + return ArmResponse.FromResponse(await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false)); } /// @@ -167,10 +167,10 @@ public async Task> PowerOffAsync(bool? skipShutdown = null /// /// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. /// A token to allow the caller to cancel the call to the service. The default value is . - /// An that allows polling for completion of the operation. - public ArmOperation StartPowerOff(bool? skipShutdown = null, CancellationToken cancellationToken = default) + /// An that allows polling for completion of the operation. + public ArmOperation StartPowerOff(bool? skipShutdown = null, CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartPowerOff(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken)); + return new PhVoidArmOperation(Operations.StartPowerOff(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken)); } /// @@ -178,10 +178,10 @@ public ArmOperation StartPowerOff(bool? skipShutdown = null, Cancellat /// /// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified. /// A token to allow the caller to cancel the call to the service. The default value is . - /// A that on completion returns an that allows polling for completion of the operation. - public async Task> StartPowerOffAsync(bool? skipShutdown = null, CancellationToken cancellationToken = default) + /// A that on completion returns an that allows polling for completion of the operation. + public async Task StartPowerOffAsync(bool? skipShutdown = null, CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartPowerOffAsync(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken).ConfigureAwait(false)); + return new PhVoidArmOperation(await Operations.StartPowerOffAsync(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken).ConfigureAwait(false)); } #endregion diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs index d7425a1130c03..dae66829ac4d3 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs @@ -70,27 +70,27 @@ public static VirtualMachineScaleSetOperations FromGeneric(GenericResourceOperat } /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs b/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs index 2994fa8f1e50e..4f42ffe004a70 100644 --- a/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs @@ -49,30 +49,30 @@ protected LoadBalancerOperations(ResourceOperationsBase options, ResourceIdentif ClientOptions.Convert()).LoadBalancers; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/NetworkInterfaceOperations.cs b/sdk/resourcemanager/Proto.Client/network/NetworkInterfaceOperations.cs index 60ffdb798789e..6e022831b687a 100644 --- a/sdk/resourcemanager/Proto.Client/network/NetworkInterfaceOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/NetworkInterfaceOperations.cs @@ -49,29 +49,29 @@ protected NetworkInterfaceOperations(ResourceOperationsBase options, ResourceGro ClientOptions.Convert()).NetworkInterfaces; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/NetworkSecurityGroupOperations.cs b/sdk/resourcemanager/Proto.Client/network/NetworkSecurityGroupOperations.cs index 1a31336eca351..1571ad5e961d2 100644 --- a/sdk/resourcemanager/Proto.Client/network/NetworkSecurityGroupOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/NetworkSecurityGroupOperations.cs @@ -166,29 +166,29 @@ await Operations.UpdateTagsAsync(Id.ResourceGroupName, Id.Name, patchable, cance } /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/PublicIpAddressOperations.cs b/sdk/resourcemanager/Proto.Client/network/PublicIpAddressOperations.cs index 0e8c4d87f2d84..4b6a342409df7 100644 --- a/sdk/resourcemanager/Proto.Client/network/PublicIpAddressOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/PublicIpAddressOperations.cs @@ -61,29 +61,29 @@ protected PublicIpAddressOperations(ResourceOperationsBase options, ResourceIden ClientOptions.Convert()).PublicIPAddresses; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/SubnetOperations.cs b/sdk/resourcemanager/Proto.Client/network/SubnetOperations.cs index 5ab4f9bd53723..8e7a2478e9b90 100644 --- a/sdk/resourcemanager/Proto.Client/network/SubnetOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/SubnetOperations.cs @@ -48,30 +48,30 @@ protected SubnetOperations(ResourceOperationsBase options, ResourceIdentifier id ClientOptions.Convert()).Subnets; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken) + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)) + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)) .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken)); } /// diff --git a/sdk/resourcemanager/Proto.Client/network/VirtualNetworkOperations.cs b/sdk/resourcemanager/Proto.Client/network/VirtualNetworkOperations.cs index 6a7db8239d72f..a8d82492b9caf 100644 --- a/sdk/resourcemanager/Proto.Client/network/VirtualNetworkOperations.cs +++ b/sdk/resourcemanager/Proto.Client/network/VirtualNetworkOperations.cs @@ -60,27 +60,27 @@ protected VirtualNetworkOperations(ResourceOperationsBase options, ResourceIdent ClientOptions.Convert()).VirtualNetworks; /// - public ArmResponse Delete(CancellationToken cancellationToken = default) + public ArmResponse Delete(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public async Task> DeleteAsync(CancellationToken cancellationToken = default) + public async Task DeleteAsync(CancellationToken cancellationToken = default) { - return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return ArmResponse.FromResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); } /// - public ArmOperation StartDelete(CancellationToken cancellationToken = default) + public ArmOperation StartDelete(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); } /// - public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + public async Task StartDeleteAsync(CancellationToken cancellationToken = default) { - return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + return new PhVoidArmOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); } ///