Skip to content

Commit

Permalink
nibhati 5401 - add CancellationToken to GetResource() (#20396)
Browse files Browse the repository at this point in the history
* Change the accessbility to virtual for Resource.Id

* add token

Co-authored-by: YalinLi0312 <yall@microsoft.com>
  • Loading branch information
nisha-bhatia and YalinLi0312 authored Apr 14, 2021
1 parent 5e40926 commit f88ab1b
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ protected ExtensionResourceOperationsBase(OperationsBase genericOperations, Reso
/// Get details for this resource from the service or can be overriden to provide a cached instance.
/// </summary>
/// <returns> A <see cref="ArmResponse{TOperations}"/> operation for this resource. </returns>
protected virtual TOperations GetResource()
protected virtual TOperations GetResource(CancellationToken cancellationToken = default)
{
return Get().Value;
return Get(cancellationToken).Value;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal GenericResource(ResourceOperationsBase operations, GenericResourceData
public virtual GenericResourceData Data { get; }

/// <inheritdoc/>
protected override GenericResource GetResource()
protected override GenericResource GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task<ArmOperation<Response>> StartDeleteAsync(CancellationToken can
/// <inheritdoc/>
public ArmResponse<GenericResource> AddTag(string key, string value, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
// Potential optimization on tags set, remove NOOP to bypass the call.
resource.Data.Tags[key] = value;
var apiVersion = GetApiVersion(cancellationToken);
Expand All @@ -126,7 +126,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
/// <inheritdoc/>
public ArmOperation<GenericResource> StartAddTag(string key, string value, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
resource.Data.Tags[key] = value;
var apiVersion = GetApiVersion(cancellationToken);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand Down Expand Up @@ -177,7 +177,7 @@ protected override void Validate(ResourceIdentifier identifier)
/// <inheritdoc/>
public ArmResponse<GenericResource> SetTags(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
resource.Data.Tags.ReplaceWith(tags);
var apiVersion = GetApiVersion(cancellationToken);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand All @@ -200,7 +200,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
/// <inheritdoc/>
public ArmOperation<GenericResource> StartSetTags(IDictionary<string, string> tags, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
resource.Data.Tags.ReplaceWith(tags);
var apiVersion = GetApiVersion(cancellationToken);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand All @@ -223,7 +223,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
/// <inheritdoc/>
public ArmResponse<GenericResource> RemoveTag(string key, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
resource.Data.Tags.Remove(key);
var apiVersion = GetApiVersion(cancellationToken);
return new PhArmResponse<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand All @@ -246,7 +246,7 @@ await op.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false),
/// <inheritdoc/>
public ArmOperation<GenericResource> StartRemoveTag(string key, CancellationToken cancellationToken = default)
{
GenericResource resource = GetResource();
GenericResource resource = GetResource(cancellationToken);
resource.Data.Tags.Remove(key);
var apiVersion = GetApiVersion(cancellationToken);
return new PhArmOperation<GenericResource, ResourceManager.Resources.Models.GenericResource>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal ResourceGroup(ResourceOperationsBase operations, ResourceGroupData reso
public virtual ResourceGroupData Data { get; }

/// <inheritdoc />
protected override ResourceGroup GetResource()
protected override ResourceGroup GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public virtual ArmResponse<ResourceGroup> AddTag(string key, string value, Cance

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(resource.Data.Tags);
patch.Tags[key] = value;
Expand Down Expand Up @@ -264,7 +264,7 @@ public virtual ArmOperation<ResourceGroup> StartAddTag(string key, string value,

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(resource.Data.Tags);
patch.Tags[key] = value;
Expand Down Expand Up @@ -380,7 +380,7 @@ public virtual ArmResponse<ResourceGroup> SetTags(IDictionary<string, string> ta

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(tags);
return new PhArmResponse<ResourceGroup, ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch, cancellationToken), g =>
Expand Down Expand Up @@ -434,7 +434,7 @@ public virtual ArmOperation<ResourceGroup> StartSetTags(IDictionary<string, stri

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(tags);
return new PhArmOperation<ResourceGroup, ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch, cancellationToken), g =>
Expand Down Expand Up @@ -488,7 +488,7 @@ public virtual ArmResponse<ResourceGroup> RemoveTag(string key, CancellationToke

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(resource.Data.Tags);
patch.Tags.Remove(key);
Expand Down Expand Up @@ -544,7 +544,7 @@ public virtual ArmOperation<ResourceGroup> StartRemoveTag(string key, Cancellati

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(resource.Data.Tags);
patch.Tags.Remove(key);
Expand All @@ -571,7 +571,7 @@ public virtual async Task<ArmOperation<ResourceGroup>> StartRemoveTagAsync(strin

try
{
var resource = GetResource();
var resource = GetResource(cancellationToken);
var patch = new ResourceGroupPatchable();
patch.Tags.ReplaceWith(resource.Data.Tags);
patch.Tags.Remove(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ internal ResourceOperationsBase(ClientContext clientContext, ResourceIdentifier
/// Get details for this resource from the service or can be overriden to provide a cached instance.
/// </summary>
/// <returns> A <see cref="ArmResponse{TOperations}"/> operation for this resource. </returns>
protected virtual TOperations GetResource()
protected virtual TOperations GetResource(CancellationToken cancellationToken = default)
{
return Get().Value;
return Get(cancellationToken).Value;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal Subscription(SubscriptionOperations subscription, SubscriptionData subs
public virtual SubscriptionData Data { get; }

/// <inheritdoc />
protected override Subscription GetResource()
protected override Subscription GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal RoleAssignment(OperationsBase operations, RoleAssignmentData data)
public RoleAssignmentData Data { get; }

/// <inheritdoc />
protected override RoleAssignment GetResource()
protected override RoleAssignment GetResource(CancellationToken cancellationToken = default)
{
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/Proto.Client/billing/BillingAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal BillingAccount(ResourceOperationsBase options, BillingAccountData resou
public BillingAccountData Data { get; private set; }

/// <inheritdoc />
protected override BillingAccount GetResource()
protected override BillingAccount GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/resourcemanager/Proto.Client/compute/AvailabilitySet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading;
using Azure.ResourceManager.Core;
using System.Threading;
using System.Threading.Tasks;
using Azure.ResourceManager.Core;

namespace Proto.Compute
{
Expand All @@ -26,7 +26,7 @@ internal AvailabilitySet(ResourceOperationsBase options, AvailabilitySetData res
public AvailabilitySetData Data { get; private set; }

/// <inheritdoc />
protected override AvailabilitySet GetResource()
protected override AvailabilitySet GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/Proto.Client/compute/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal VirtualMachine(ResourceOperationsBase operations, VirtualMachineData re
}

/// <inheritdoc />
protected override VirtualMachine GetResource()
protected override VirtualMachine GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal NetworkInterface(ResourceOperationsBase options, NetworkInterfaceData r
public NetworkInterfaceData Data { get; private set; }

/// <inheritdoc />
protected override NetworkInterface GetResource()
protected override NetworkInterface GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal NetworkSecurityGroup(ResourceOperationsBase operations, NetworkSecurity
public NetworkSecurityGroupData Data { get; private set; }

/// <inheritdoc />
protected override NetworkSecurityGroup GetResource()
protected override NetworkSecurityGroup GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public async Task<ArmOperation<Response>> StartDeleteAsync(CancellationToken can
}

/// <inheritdoc/>
protected override NetworkSecurityGroup GetResource()
protected override NetworkSecurityGroup GetResource(CancellationToken cancellationToken = default)
{
return Get().Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal PublicIpAddress(ResourceOperationsBase options, PublicIPAddressData res
public PublicIPAddressData Data { get; private set; }

/// <inheritdoc />
protected override PublicIpAddress GetResource()
protected override PublicIpAddress GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/Proto.Client/network/Subnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal Subnet(ResourceOperationsBase options, SubnetData resource)
public SubnetData Data { get; private set; }

/// <inheritdoc />
protected override Subnet GetResource()
protected override Subnet GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/Proto.Client/network/VirtualNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal VirtualNetwork(ResourceOperationsBase options, VirtualNetworkData resou
public VirtualNetworkData Data { get; private set; }

/// <inheritdoc />
protected override VirtualNetwork GetResource()
protected override VirtualNetwork GetResource(CancellationToken cancellation = default)
{
return this;
}
Expand Down

0 comments on commit f88ab1b

Please sign in to comment.