diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs index 1170ab80c876..f66ed787f113 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ApiVersionsBase.cs @@ -185,14 +185,14 @@ public override string ToString() /// /// Compares the API version value in ApiVersionsBase object and the one in object. /// - /// The object to compare. + /// The object to compare. /// Comparison result in boolean. Equal returns true otherwise returns false. - public override bool Equals(object obj) + public override bool Equals(object other) { - if (obj is ApiVersionsBase) - return Equals(obj as ApiVersionsBase); - if (obj is string) - return Equals(obj as string); + if (other is ApiVersionsBase) + return Equals(other as ApiVersionsBase); + if (other is string) + return Equals(other as string); return false; } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceContainer.cs deleted file mode 100644 index 045795d5f34f..000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceContainer.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.ResourceManager.Core -{ - /// - /// Container for extension resources. Because there is no CreateOrUpdate, there is a difference in the input and output model - /// - /// Operations class returned. - /// Input Model. - public abstract class ExtensionResourceContainer : ExtensionResourceOperationsBase - where TOperations : ExtensionResourceOperationsBase - where TInput : class - { - /// - /// Initializes a new instance of the class. - /// Create an ResourceContainer from an operations class or client - /// - /// The operations to copy the client options from. - protected ExtensionResourceContainer(OperationsBase operations) - : base(operations) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The operations to copy the client options from. - /// The resource Id of the parent resource. - protected ExtensionResourceContainer(OperationsBase operations, ResourceIdentifier parentId) - : base(new ClientContext(operations.ClientOptions, operations.Credential, operations.BaseUri, operations.Pipeline), parentId) - { - } - - /// - /// Validate that the given resource Id represents a valid parent for this resource - /// - /// The resource Id of the parent resource. - protected override void Validate(ResourceIdentifier identifier) - { - } - - /// - /// Create a new extension resource at the given scope. Block further execution on the current thread until creation is complete. - /// - /// The name of the created extension resource. - /// The properties of the extension resource. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// An Http envelope containing the operations for the given extension. - public abstract Response Create(string name, TInput resourceDetails, CancellationToken cancellationToken = default); - - /// - /// Create a new extension resource at the given scope without blocking the current thread. - /// Returns a Task that allows control over when or if the thread is blocked. - /// - /// The name of the created extension resource. - /// The properties of the extension resource. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// A Task that creates the extension resource. - public abstract Task> CreateAsync(string name, TInput resourceDetails, CancellationToken cancellationToken = default); - - /// - /// Begin Creation of a new extension resource. Block until the creation is accepted by the service. - /// The returned object allows fine-grained control over waiting for creation to complete. - /// - /// The name of the created extension resource. - /// The properties of the extension resource. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// An instance of , allowing fine grained control over waiting for creation to complete. - public abstract Operation StartCreate(string name, TInput resourceDetails, CancellationToken cancellationToken = default); - - /// - /// Begin Creation of a new extension resource in a background task. - /// When creation has successfully begin, the object returned from the completed task allows fine-grained control over waiting for creation to complete. - /// - /// The name of the created extension resource. - /// The properties of the extension resource. - /// 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 abstract Task> StartCreateAsync(string name, TInput resourceDetails, CancellationToken cancellationToken = default); - - /// - /// Lists the extension resources at the current scope. Blocks until the first page of results is returned. - /// - /// A token to allow the caller to cancel the call to the service. The default value is . - /// An instance of allowing paged or non-paged enumeration of results. - public abstract Pageable ListAtScope(CancellationToken cancellationToken = default); - - /// - /// Lists the extension resources at the current scope asynchronously. The returned task completes when the first page of results is returned. - /// - /// The cancellation token clients can use to cancel any blocking HTTP requests made by this method, including - /// any Http requests that result from enumerating pages of results. - /// An instance of allowing asynchronous paged or non-paged enumeration of results. - public abstract AsyncPageable ListAtScopeAsync(CancellationToken cancellationToken = default); - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceOperationsBase.cs deleted file mode 100644 index 35d063696287..000000000000 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ExtensionResourceOperationsBase.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.ResourceManager.Core -{ - /// - /// Base class for all extensions - /// - public abstract class ExtensionResourceOperationsBase : OperationsBase - { - /// - /// Initializes a new instance of the class. - /// - /// The operations to copy the client options from. - internal ExtensionResourceOperationsBase(OperationsBase genericOperations) - : this(new ClientContext(genericOperations.ClientOptions, genericOperations.Credential, genericOperations.BaseUri, genericOperations.Pipeline), genericOperations.Id) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The identifier of the extension resource. - internal ExtensionResourceOperationsBase(ClientContext clientContext, ResourceIdentifier id) - : base(clientContext, id) - { - } - } - - /// - /// Separate Extension resources from non-extension resources - /// - /// The typed operations class for a specific resource. - [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Resource types that differ by Type arguments")] - public abstract class ExtensionResourceOperationsBase : ExtensionResourceOperationsBase - where TOperations : ExtensionResourceOperationsBase - { - /// - /// Initializes a new instance of the class. - /// - /// The operations to copy the client options from. - protected ExtensionResourceOperationsBase(OperationsBase genericOperations) - : base(genericOperations) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The operations to copy the client options from. - /// The identifier of the extension resource. - protected ExtensionResourceOperationsBase(OperationsBase genericOperations, ResourceIdentifier id) - : base(new ClientContext(genericOperations.ClientOptions, genericOperations.Credential, genericOperations.BaseUri, genericOperations.Pipeline), id) - { - } - - /// - /// Get details and operations for this extension resource. This call will block the thread until details are returned from the service. - /// - /// A token allowing cancellation of the Http call in the task. - /// An Http Response containing details and operations for the extension resource. - public abstract Response Get(CancellationToken cancellationToken = default); - - /// - /// Get details and operations for this extension resource. This call returns a Task that completes when the details are returned from the service. - /// - /// A token allowing cancellation of the Http call in the task. - /// A Task that retrieves the resource details. When complete, the task will yield an Http Response - /// containing details and operations for the extension resource. - public abstract Task> GetAsync(CancellationToken cancellationToken = default); - - /// - /// Get details for this resource from the service or can be overriden to provide a cached instance. - /// - /// A operation for this resource. - protected virtual TOperations GetResource(CancellationToken cancellationToken = default) - { - return Get(cancellationToken).Value; - } - - /// - /// Get details for this resource from the service or can be overriden to provide a cached instance. - /// - /// A token allowing cancellation of the Http call in the task. - /// A that on completion returns a operation for this resource. - protected virtual async Task GetResourceAsync(CancellationToken cancellationToken = default) - { - return (await GetAsync(cancellationToken).ConfigureAwait(false)).Value; - } - } -} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs index a78be82e24c1..41b837798b81 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs @@ -117,29 +117,29 @@ public static implicit operator string(ResourceType other) /// /// Compares two objects. /// - /// First object. - /// Second object. + /// First object. + /// Second object. /// True if they are equal, otherwise False. - public static bool operator ==(ResourceType source, ResourceType target) + public static bool operator ==(ResourceType left, ResourceType right) { - if (source is null) - return target is null; + if (left is null) + return right is null; - return source.Equals(target); + return left.Equals(right); } /// /// Compares two objects. /// - /// First object. - /// Second object. + /// First object. + /// Second object. /// False if they are equal, otherwise True. - public static bool operator !=(ResourceType source, ResourceType target) + public static bool operator !=(ResourceType left, ResourceType right) { - if (source is null) - return !(target is null); + if (left is null) + return !(right is null); - return !source.Equals(target); + return !left.Equals(right); } /// @@ -184,22 +184,22 @@ public override string ToString() } /// - public override bool Equals(object obj) + public override bool Equals(object other) { - if (obj is null) + if (other is null) return false; - var resourceObj = obj as ResourceType; + var resourceObj = other as ResourceType; if (!(resourceObj is null)) return Equals(resourceObj); - var stringObj = obj as string; + var stringObj = other as string; if (stringObj != null) return Equals(stringObj); - return base.Equals(obj); + return base.Equals(other); } /// diff --git a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentContainer.cs b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentContainer.cs index 362bf6a8993c..e4e106801e26 100644 --- a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentContainer.cs +++ b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentContainer.cs @@ -13,13 +13,13 @@ namespace Proto.Authorization /// /// Container for role assignments - note that in this case, the container is either a TrackedResource or a resource Id /// - public class RoleAssignmentContainer : ExtensionResourceContainer + public class RoleAssignmentContainer : ResourceContainerBase { /// /// Initializes a new instance of the class. /// /// A generic operations class representing the parent of the role Assignment. - internal RoleAssignmentContainer(OperationsBase operations) + internal RoleAssignmentContainer(ResourceOperationsBase operations) : base(operations) { // TODO: Remove this once we nio longer need to create management clients @@ -37,8 +37,8 @@ internal RoleAssignmentContainer(OperationsBase operations) /// /// The client options with http client details for these operations. /// The resource id of the target resource, resource group, or subscription for this role assignment. - internal RoleAssignmentContainer(OperationsBase operations, ResourceIdentifier scope) - : base(operations, scope) + internal RoleAssignmentContainer(ResourceOperationsBase operations, ResourceIdentifier scope) + : base(operations) { // TODO: Remove this once we nio longer need to create management clients string subscriptionId; @@ -58,6 +58,30 @@ internal RoleAssignmentContainer(OperationsBase operations, ResourceIdentifier s /// private RoleAssignmentsOperations Operations { get; } + /// + /// Gets a RoleAssignment + /// + /// The role assignment name. + /// A token that allows cancellation of any blockign API calls made during this method. + /// The role assignment. + public override Response Get(string resourceName, CancellationToken cancellationToken = default) + { + var response = Operations.Get(Id, resourceName, cancellationToken); + return Response.FromValue(new RoleAssignment(this, new RoleAssignmentData(response.Value)), response.GetRawResponse()); + } + + /// + /// Gets a RoleAssignment + /// + /// The role assignment name. + /// A token that allows cancellation of any blockign API calls made during this method. + /// The role assignment. + public async override Task> GetAsync(string resourceName, CancellationToken cancellationToken = default) + { + var response = await Operations.GetAsync(Id, resourceName, cancellationToken).ConfigureAwait(false); + return Response.FromValue(new RoleAssignment(this, new RoleAssignmentData(response.Value)), response.GetRawResponse()); + } + /// /// Create a role assignment. This method blocks until the RoleAssignment is created on the service. /// @@ -65,7 +89,7 @@ internal RoleAssignmentContainer(OperationsBase operations, ResourceIdentifier s /// The properties of the role assignment. /// A token that allows cancellation of any blockign API calls made during this method. /// The created role assignment. - public override Response Create(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) + public Response Create(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) { var response = Operations.Create(Id, name, resourceDetails.ToModel(), cancellationToken); return Response.FromValue(new RoleAssignment(this, new RoleAssignmentData(response.Value)), response.GetRawResponse()); @@ -79,7 +103,7 @@ public override Response Create(string name, RoleAssignmentCreat /// The properties of the role assignment. /// A token that allows cancellation of any blockign API calls made during this method. /// A Task that yields the created role assignment when complete. - public async override Task> CreateAsync(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) + public async Task> CreateAsync(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) { var response = await Operations.CreateAsync(Id, name, resourceDetails.ToModel(), cancellationToken).ConfigureAwait(false); return Response.FromValue(new RoleAssignment(this, new RoleAssignmentData(response.Value)), response.GetRawResponse()); @@ -93,7 +117,7 @@ public async override Task> CreateAsync(string name, Ro /// The properties of the role assignment. /// A token that allows cancellation of any blocking API calls made during this method. /// An ArmOperation that yields the created role assignment and gives the user control over polling. - public override Operation StartCreate(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) + public Operation StartCreate(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( Operations.Create(Id, name, resourceDetails.ToModel(), cancellationToken), @@ -108,7 +132,7 @@ public override Operation StartCreate(string name, RoleAssignmen /// The properties of the role assignment. /// A token that allows cancellation of any blocking API calls made during this method. /// A that yields the created role assignment and gives the user control over polling. - public async override Task> StartCreateAsync(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) + public async Task> StartCreateAsync(string name, RoleAssignmentCreateParameters resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( await Operations.CreateAsync(Id, name, resourceDetails.ToModel(), cancellationToken).ConfigureAwait(false), @@ -120,7 +144,7 @@ await Operations.CreateAsync(Id, name, resourceDetails.ToModel(), cancellationTo /// /// A token that allows cancellation of any blocking API calls made during this method. /// A that allows paged enumeration of the role assignments at this scope. - public override Azure.Pageable ListAtScope(CancellationToken cancellationToken = default) + public Azure.Pageable ListAtScope(CancellationToken cancellationToken = default) { throw new System.NotImplementedException(); } @@ -130,7 +154,7 @@ public override Azure.Pageable ListAtScope(CancellationToken can /// /// A token that allows cancellation of any blocking API calls made during this method. /// A that allows asynchronous paged enumeration of the role assignments at this scope. - public override Azure.AsyncPageable ListAtScopeAsync(CancellationToken cancellationToken = default) + public Azure.AsyncPageable ListAtScopeAsync(CancellationToken cancellationToken = default) { throw new System.NotImplementedException(); } diff --git a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs index 878a227f5a14..1134a5185d03 100644 --- a/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs +++ b/sdk/resourcemanager/Proto.Client/authorization/RoleAssignmentOperations.cs @@ -13,7 +13,7 @@ namespace Proto.Authorization /// /// Operations over Role Assignments for Role-based access control to ARM resources /// - public class RoleAssignmentOperations : ExtensionResourceOperationsBase + public class RoleAssignmentOperations : ResourceOperationsBase { /// /// Gets the resource type for Role Assignments. @@ -25,8 +25,8 @@ public class RoleAssignmentOperations : ExtensionResourceOperationsBase /// A generic operations class corresponding to a Role Assignment. - internal RoleAssignmentOperations(GenericResourceOperations genericOperations) - : base(genericOperations) + internal RoleAssignmentOperations(ResourceOperationsBase parent) + : base(parent, parent.Id) { string subscriptionId; if (!Id.TryGetSubscriptionId(out subscriptionId))