diff --git a/samples/Azure.Management.Storage/Generated/BlobContainerContainer.cs b/samples/Azure.Management.Storage/Generated/BlobContainerContainer.cs index df7756174b7..5a11121365f 100644 --- a/samples/Azure.Management.Storage/Generated/BlobContainerContainer.cs +++ b/samples/Azure.Management.Storage/Generated/BlobContainerContainer.cs @@ -5,23 +5,357 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of BlobContainer and their operations over a StorageAccount. - public partial class BlobContainerContainer + public partial class BlobContainerContainer : ResourceContainerBase { - /// Initializes a new instance of BlobContainerContainer for mocking. + /// Initializes a new instance of the class for mocking. protected BlobContainerContainer() { } - internal BlobContainerContainer(ResourceOperationsBase parent) + /// Initializes a new instance of BlobContainerContainer class. + /// The resource representing the parent resource. + internal BlobContainerContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private BlobContainersRestOperations _restClient => new BlobContainersRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a BlobContainer. Please note some properties can be set only during creation. + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the blob container to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string containerName, BlobContainerData blobContainer, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + if (blobContainer == null) + { + throw new ArgumentNullException(nameof(blobContainer)); + } + + return StartCreateOrUpdate(containerName, blobContainer, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobContainer. Please note some properties can be set only during creation. + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the blob container to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string containerName, BlobContainerData blobContainer, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + if (blobContainer == null) + { + throw new ArgumentNullException(nameof(blobContainer)); + } + + var operation = await StartCreateOrUpdateAsync(containerName, blobContainer, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobContainer. Please note some properties can be set only during creation. + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the blob container to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string containerName, BlobContainerData blobContainer, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + if (blobContainer == null) + { + throw new ArgumentNullException(nameof(blobContainer)); + } + + var originalResponse = _restClient.Create(Id.ResourceGroupName, Id.Parent.Name, containerName, blobContainer, cancellationToken: cancellationToken); + return new BlobContainersCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobContainer. Please note some properties can be set only during creation. + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the blob container to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string containerName, BlobContainerData blobContainer, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + if (blobContainer == null) + { + throw new ArgumentNullException(nameof(blobContainer)); + } + + var originalResponse = await _restClient.CreateAsync(Id.ResourceGroupName, Id.Parent.Name, containerName, blobContainer, cancellationToken: cancellationToken).ConfigureAwait(false); + return new BlobContainersCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string containerName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.Get"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, containerName, cancellationToken: cancellationToken); + return Response.FromValue(new BlobContainer(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string containerName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.Get"); + scope.Start(); + try + { + if (containerName == null) + { + throw new ArgumentNullException(nameof(containerName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, containerName, cancellationToken: cancellationToken); + return Response.FromValue(new BlobContainer(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new BlobContainer(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new BlobContainer(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new BlobContainerOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new BlobContainer(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new BlobContainer(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new BlobContainerOperations(genericResource).Get().Value); + } + + /// Filters the list of BlobContainer for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BlobContainerOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of BlobContainer for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobContainerContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BlobContainerOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/BlobContainerOperations.cs b/samples/Azure.Management.Storage/Generated/BlobContainerOperations.cs index 1efdb019288..40c7cb6a5d7 100644 --- a/samples/Azure.Management.Storage/Generated/BlobContainerOperations.cs +++ b/samples/Azure.Management.Storage/Generated/BlobContainerOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific BlobContainer. public partial class BlobContainerOperations : ResourceOperationsBase { - /// Initializes a new instance of BlobContainerOperations for mocking. + /// Initializes a new instance of the class for mocking. protected BlobContainerOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a BlobContainer. + internal BlobContainerOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected BlobContainerOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/BlobServiceContainer.cs b/samples/Azure.Management.Storage/Generated/BlobServiceContainer.cs index 37b6ef4ebab..83548d1bb9c 100644 --- a/samples/Azure.Management.Storage/Generated/BlobServiceContainer.cs +++ b/samples/Azure.Management.Storage/Generated/BlobServiceContainer.cs @@ -5,23 +5,327 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of BlobService and their operations over a StorageAccount. - public partial class BlobServiceContainer + public partial class BlobServiceContainer : ResourceContainerBase { - /// Initializes a new instance of BlobServiceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected BlobServiceContainer() { } - internal BlobServiceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of BlobServiceContainer class. + /// The resource representing the parent resource. + internal BlobServiceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private BlobServicesRestOperations _restClient => new BlobServicesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a BlobService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string accountName, BlobServiceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(accountName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string accountName, BlobServiceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(accountName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string accountName, BlobServiceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.SetServiceProperties(Id.ResourceGroupName, accountName, parameters, cancellationToken: cancellationToken); + return new BlobServicesSetServicePropertiesOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a BlobService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The properties of a storage account’s Blob service, including properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string accountName, BlobServiceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.SetServicePropertiesAsync(Id.ResourceGroupName, accountName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new BlobServicesSetServicePropertiesOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = _restClient.GetServiceProperties(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new BlobService(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = await _restClient.GetServicePropertiesAsync(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new BlobService(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new BlobService(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new BlobServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new BlobService(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new BlobServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of BlobService for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BlobServiceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of BlobService for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BlobServiceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BlobServiceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/BlobServiceOperations.cs b/samples/Azure.Management.Storage/Generated/BlobServiceOperations.cs index 12b4a371474..ab8749c8229 100644 --- a/samples/Azure.Management.Storage/Generated/BlobServiceOperations.cs +++ b/samples/Azure.Management.Storage/Generated/BlobServiceOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific BlobService. public partial class BlobServiceOperations : ResourceOperationsBase { - /// Initializes a new instance of BlobServiceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected BlobServiceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a BlobService. + internal BlobServiceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected BlobServiceOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/CodeModel.yaml b/samples/Azure.Management.Storage/Generated/CodeModel.yaml index be88b3c4171..3ee9faf20c2 100644 --- a/samples/Azure.Management.Storage/Generated/CodeModel.yaml +++ b/samples/Azure.Management.Storage/Generated/CodeModel.yaml @@ -73,7 +73,7 @@ schemas: !Schemas The hasImmutabilityPolicy public property is set to true by SRP if ImmutabilityPolicy has been created for this container. The hasImmutabilityPolicy public property is set to false by SRP if ImmutabilityPolicy has not been created for this container. protocol: !Protocols {} - - !BooleanSchema &ref_40 + - !BooleanSchema &ref_38 type: boolean language: !Languages default: @@ -246,7 +246,7 @@ schemas: !Schemas name: LeaseContainerRequestLeaseDuration description: Required for acquire. Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. protocol: !Protocols {} - - !NumberSchema &ref_36 + - !NumberSchema &ref_34 type: integer apiVersions: - !ApiVersion @@ -259,7 +259,7 @@ schemas: !Schemas name: FileSharePropertiesShareQuota description: The maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB (5120). For Large File Shares, the maximum size is 102400. protocol: !Protocols {} - - !NumberSchema &ref_42 + - !NumberSchema &ref_40 type: integer apiVersions: - !ApiVersion @@ -270,7 +270,7 @@ schemas: !Schemas name: FileSharePropertiesRemainingRetentionDays description: Remaining retention days for share that was soft deleted. protocol: !Protocols {} - - !NumberSchema &ref_46 + - !NumberSchema &ref_44 type: integer apiVersions: - !ApiVersion @@ -712,7 +712,7 @@ schemas: !Schemas name: String description: '' protocol: !Protocols {} - - !StringSchema &ref_39 + - !StringSchema &ref_37 type: string apiVersions: - !ApiVersion @@ -722,7 +722,7 @@ schemas: !Schemas name: FileSharePropertiesVersion description: The version of the share. protocol: !Protocols {} - - !StringSchema &ref_45 + - !StringSchema &ref_43 type: string apiVersions: - !ApiVersion @@ -2184,7 +2184,7 @@ schemas: !Schemas name: LeaseContainerRequestAction description: Specifies the lease action. Can be one of the available actions. protocol: !Protocols {} - - !ChoiceSchema &ref_37 + - !ChoiceSchema &ref_35 choices: - !ChoiceValue value: SMB @@ -2212,7 +2212,7 @@ schemas: !Schemas name: EnabledProtocols description: The authentication protocol that is used for the file share. Can only be specified when creating a share. protocol: !Protocols {} - - !ChoiceSchema &ref_38 + - !ChoiceSchema &ref_36 choices: - !ChoiceValue value: NoRootSquash @@ -2242,7 +2242,7 @@ schemas: !Schemas name: RootSquashType description: The property is for NFS share only. The default is NoRootSquash. protocol: !Protocols {} - - !ChoiceSchema &ref_43 + - !ChoiceSchema &ref_41 choices: - !ChoiceValue value: TransactionOptimized @@ -3361,7 +3361,7 @@ schemas: !Schemas name: ContainerPropertiesMetadata description: A name-value pair to associate with the container as metadata. protocol: !Protocols {} - - !DictionarySchema &ref_35 + - !DictionarySchema &ref_33 type: dictionary elementType: *ref_2 language: !Languages @@ -3442,7 +3442,7 @@ schemas: !Schemas name: TagPropertyTimestamp description: Returns the date and time the tag was added. protocol: !Protocols {} - - !DateTimeSchema &ref_34 + - !DateTimeSchema &ref_32 type: date-time format: date-time apiVersions: @@ -3453,7 +3453,7 @@ schemas: !Schemas name: FileSharePropertiesLastModifiedTime description: Returns the date and time the share was last modified. protocol: !Protocols {} - - !DateTimeSchema &ref_41 + - !DateTimeSchema &ref_39 type: date-time format: date-time apiVersions: @@ -3464,7 +3464,7 @@ schemas: !Schemas name: FileSharePropertiesDeletedTime description: The deleted time if the share was deleted. protocol: !Protocols {} - - !DateTimeSchema &ref_44 + - !DateTimeSchema &ref_42 type: date-time format: date-time apiVersions: @@ -3775,7 +3775,7 @@ schemas: !Schemas description: A name-value pair to associate with the container as metadata. protocol: !Protocols {} - !Property - schema: !ObjectSchema &ref_32 + schema: !ObjectSchema &ref_45 type: object apiVersions: - !ApiVersion @@ -3937,7 +3937,7 @@ schemas: !Schemas description: The ImmutabilityPolicy property of the container. protocol: !Protocols {} - !Property - schema: !ObjectSchema &ref_33 + schema: !ObjectSchema &ref_46 type: object apiVersions: - !ApiVersion @@ -4084,173 +4084,6 @@ schemas: !Schemas protocol: !Protocols {} serializationFormats: - json - usage: - - output - - input - language: !Languages - default: - name: ListContainerItem - description: The blob container properties be listed out. - namespace: '' - protocol: !Protocols {} - - !ObjectSchema &ref_48 - type: object - apiVersions: - - !ApiVersion - version: '2019-06-01' - parents: !Relations - all: - - *ref_5 - - *ref_6 - immediate: - - *ref_5 - properties: - - !Property - schema: *ref_7 - flattenedNames: - - properties - - defaultEncryptionScope - serializedName: defaultEncryptionScope - language: !Languages - default: - name: defaultEncryptionScope - description: Default the container to use specified encryption scope for all writes. - protocol: !Protocols {} - - !Property - schema: *ref_8 - flattenedNames: - - properties - - denyEncryptionScopeOverride - serializedName: denyEncryptionScopeOverride - language: !Languages - default: - name: denyEncryptionScopeOverride - description: Block override of encryption scope from the container default. - protocol: !Protocols {} - - !Property - schema: *ref_9 - flattenedNames: - - properties - - publicAccess - serializedName: publicAccess - language: !Languages - default: - name: publicAccess - description: Specifies whether data in the container may be accessed publicly and the level of access. - protocol: !Protocols {} - - !Property - schema: *ref_10 - flattenedNames: - - properties - - lastModifiedTime - readOnly: true - serializedName: lastModifiedTime - language: !Languages - default: - name: lastModifiedTime - description: Returns the date and time the container was last modified. - protocol: !Protocols {} - - !Property - schema: *ref_11 - flattenedNames: - - properties - - leaseStatus - readOnly: true - serializedName: leaseStatus - language: !Languages - default: - name: leaseStatus - description: The lease status of the container. - protocol: !Protocols {} - - !Property - schema: *ref_12 - flattenedNames: - - properties - - leaseState - readOnly: true - serializedName: leaseState - language: !Languages - default: - name: leaseState - description: Lease state of the container. - protocol: !Protocols {} - - !Property - schema: *ref_13 - flattenedNames: - - properties - - leaseDuration - readOnly: true - serializedName: leaseDuration - language: !Languages - default: - name: leaseDuration - description: Specifies whether the lease on a container is of infinite or fixed duration, only when the container is leased. - protocol: !Protocols {} - - !Property - schema: *ref_14 - flattenedNames: - - properties - - metadata - serializedName: metadata - language: !Languages - default: - name: metadata - description: A name-value pair to associate with the container as metadata. - protocol: !Protocols {} - - !Property - schema: *ref_32 - flattenedNames: - - properties - - immutabilityPolicy - readOnly: true - serializedName: immutabilityPolicy - language: !Languages - default: - name: immutabilityPolicy - description: The ImmutabilityPolicy property of the container. - protocol: !Protocols {} - - !Property - schema: *ref_33 - flattenedNames: - - properties - - legalHold - readOnly: true - serializedName: legalHold - language: !Languages - default: - name: legalHold - description: The LegalHold property of the container. - protocol: !Protocols {} - - !Property - schema: *ref_25 - flattenedNames: - - properties - - hasLegalHold - readOnly: true - serializedName: hasLegalHold - language: !Languages - default: - name: hasLegalHold - description: >- - The hasLegalHold public property is set to true by SRP if there are at least one existing tag. The hasLegalHold public property is set to false by SRP if all existing legal hold tags are cleared - out. There can be a maximum of 1000 blob containers with hasLegalHold=true for a given account. - protocol: !Protocols {} - - !Property - schema: *ref_31 - flattenedNames: - - properties - - hasImmutabilityPolicy - readOnly: true - serializedName: hasImmutabilityPolicy - language: !Languages - default: - name: hasImmutabilityPolicy - description: >- - The hasImmutabilityPolicy public property is set to true by SRP if ImmutabilityPolicy has been created for this container. The hasImmutabilityPolicy public property is set to false by SRP if - ImmutabilityPolicy has not been created for this container. - protocol: !Protocols {} - serializationFormats: - - json usage: - input - output @@ -4260,7 +4093,7 @@ schemas: !Schemas description: Properties of the blob container, including Id, resource name, resource type, Etag. namespace: '' protocol: !Protocols {} - - !ObjectSchema &ref_49 + - !ObjectSchema &ref_48 type: object apiVersions: - !ApiVersion @@ -4319,7 +4152,7 @@ schemas: !Schemas description: The ImmutabilityPolicy property of a blob container, including Id, resource name, resource type, Etag. namespace: '' protocol: !Protocols {} - - !ObjectSchema &ref_50 + - !ObjectSchema &ref_49 type: object apiVersions: - !ApiVersion @@ -4332,7 +4165,7 @@ schemas: !Schemas - *ref_5 properties: - !Property - schema: *ref_34 + schema: *ref_32 flattenedNames: - properties - lastModifiedTime @@ -4344,7 +4177,7 @@ schemas: !Schemas description: Returns the date and time the share was last modified. protocol: !Protocols {} - !Property - schema: *ref_35 + schema: *ref_33 flattenedNames: - properties - metadata @@ -4355,7 +4188,7 @@ schemas: !Schemas description: A name-value pair to associate with the share as metadata. protocol: !Protocols {} - !Property - schema: *ref_36 + schema: *ref_34 flattenedNames: - properties - shareQuota @@ -4366,7 +4199,7 @@ schemas: !Schemas description: The maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB (5120). For Large File Shares, the maximum size is 102400. protocol: !Protocols {} - !Property - schema: *ref_37 + schema: *ref_35 flattenedNames: - properties - enabledProtocols @@ -4377,7 +4210,7 @@ schemas: !Schemas description: The authentication protocol that is used for the file share. Can only be specified when creating a share. protocol: !Protocols {} - !Property - schema: *ref_38 + schema: *ref_36 flattenedNames: - properties - rootSquash @@ -4388,7 +4221,7 @@ schemas: !Schemas description: The property is for NFS share only. The default is NoRootSquash. protocol: !Protocols {} - !Property - schema: *ref_39 + schema: *ref_37 flattenedNames: - properties - version @@ -4400,7 +4233,7 @@ schemas: !Schemas description: The version of the share. protocol: !Protocols {} - !Property - schema: *ref_40 + schema: *ref_38 flattenedNames: - properties - deleted @@ -4412,7 +4245,7 @@ schemas: !Schemas description: Indicates whether the share was deleted. protocol: !Protocols {} - !Property - schema: *ref_41 + schema: *ref_39 flattenedNames: - properties - deletedTime @@ -4424,7 +4257,7 @@ schemas: !Schemas description: The deleted time if the share was deleted. protocol: !Protocols {} - !Property - schema: *ref_42 + schema: *ref_40 flattenedNames: - properties - remainingRetentionDays @@ -4436,7 +4269,7 @@ schemas: !Schemas description: Remaining retention days for share that was soft deleted. protocol: !Protocols {} - !Property - schema: *ref_43 + schema: *ref_41 flattenedNames: - properties - accessTier @@ -4447,7 +4280,7 @@ schemas: !Schemas description: Access tier for specific share. GpV2 account can choose between TransactionOptimized (default), Hot, and Cool. FileStorage account can choose Premium. protocol: !Protocols {} - !Property - schema: *ref_44 + schema: *ref_42 flattenedNames: - properties - accessTierChangeTime @@ -4459,7 +4292,7 @@ schemas: !Schemas description: Indicates the last modification time for share access tier. protocol: !Protocols {} - !Property - schema: *ref_45 + schema: *ref_43 flattenedNames: - properties - accessTierStatus @@ -4471,7 +4304,7 @@ schemas: !Schemas description: Indicates if there is a pending transition for access tier. protocol: !Protocols {} - !Property - schema: *ref_46 + schema: *ref_44 flattenedNames: - properties - shareUsageBytes @@ -4484,13 +4317,180 @@ schemas: !Schemas protocol: !Protocols {} serializationFormats: - json + usage: + - input + - output + language: !Languages + default: + name: FileShare + description: Properties of the file share, including Id, resource name, resource type, Etag. + namespace: '' + protocol: !Protocols {} + - !ObjectSchema &ref_50 + type: object + apiVersions: + - !ApiVersion + version: '2019-06-01' + parents: !Relations + all: + - *ref_5 + - *ref_6 + immediate: + - *ref_5 + properties: + - !Property + schema: *ref_7 + flattenedNames: + - properties + - defaultEncryptionScope + serializedName: defaultEncryptionScope + language: !Languages + default: + name: defaultEncryptionScope + description: Default the container to use specified encryption scope for all writes. + protocol: !Protocols {} + - !Property + schema: *ref_8 + flattenedNames: + - properties + - denyEncryptionScopeOverride + serializedName: denyEncryptionScopeOverride + language: !Languages + default: + name: denyEncryptionScopeOverride + description: Block override of encryption scope from the container default. + protocol: !Protocols {} + - !Property + schema: *ref_9 + flattenedNames: + - properties + - publicAccess + serializedName: publicAccess + language: !Languages + default: + name: publicAccess + description: Specifies whether data in the container may be accessed publicly and the level of access. + protocol: !Protocols {} + - !Property + schema: *ref_10 + flattenedNames: + - properties + - lastModifiedTime + readOnly: true + serializedName: lastModifiedTime + language: !Languages + default: + name: lastModifiedTime + description: Returns the date and time the container was last modified. + protocol: !Protocols {} + - !Property + schema: *ref_11 + flattenedNames: + - properties + - leaseStatus + readOnly: true + serializedName: leaseStatus + language: !Languages + default: + name: leaseStatus + description: The lease status of the container. + protocol: !Protocols {} + - !Property + schema: *ref_12 + flattenedNames: + - properties + - leaseState + readOnly: true + serializedName: leaseState + language: !Languages + default: + name: leaseState + description: Lease state of the container. + protocol: !Protocols {} + - !Property + schema: *ref_13 + flattenedNames: + - properties + - leaseDuration + readOnly: true + serializedName: leaseDuration + language: !Languages + default: + name: leaseDuration + description: Specifies whether the lease on a container is of infinite or fixed duration, only when the container is leased. + protocol: !Protocols {} + - !Property + schema: *ref_14 + flattenedNames: + - properties + - metadata + serializedName: metadata + language: !Languages + default: + name: metadata + description: A name-value pair to associate with the container as metadata. + protocol: !Protocols {} + - !Property + schema: *ref_45 + flattenedNames: + - properties + - immutabilityPolicy + readOnly: true + serializedName: immutabilityPolicy + language: !Languages + default: + name: immutabilityPolicy + description: The ImmutabilityPolicy property of the container. + protocol: !Protocols {} + - !Property + schema: *ref_46 + flattenedNames: + - properties + - legalHold + readOnly: true + serializedName: legalHold + language: !Languages + default: + name: legalHold + description: The LegalHold property of the container. + protocol: !Protocols {} + - !Property + schema: *ref_25 + flattenedNames: + - properties + - hasLegalHold + readOnly: true + serializedName: hasLegalHold + language: !Languages + default: + name: hasLegalHold + description: >- + The hasLegalHold public property is set to true by SRP if there are at least one existing tag. The hasLegalHold public property is set to false by SRP if all existing legal hold tags are cleared + out. There can be a maximum of 1000 blob containers with hasLegalHold=true for a given account. + protocol: !Protocols {} + - !Property + schema: *ref_31 + flattenedNames: + - properties + - hasImmutabilityPolicy + readOnly: true + serializedName: hasImmutabilityPolicy + language: !Languages + default: + name: hasImmutabilityPolicy + description: >- + The hasImmutabilityPolicy public property is set to true by SRP if ImmutabilityPolicy has been created for this container. The hasImmutabilityPolicy public property is set to false by SRP if + ImmutabilityPolicy has not been created for this container. + protocol: !Protocols {} + serializationFormats: + - json usage: - output - input language: !Languages default: - name: FileShareItem - description: The file share properties be listed out. + name: ListContainerItem + description: The blob container properties be listed out. namespace: '' protocol: !Protocols {} - !ObjectSchema &ref_51 @@ -4506,7 +4506,7 @@ schemas: !Schemas - *ref_5 properties: - !Property - schema: *ref_34 + schema: *ref_32 flattenedNames: - properties - lastModifiedTime @@ -4518,7 +4518,7 @@ schemas: !Schemas description: Returns the date and time the share was last modified. protocol: !Protocols {} - !Property - schema: *ref_35 + schema: *ref_33 flattenedNames: - properties - metadata @@ -4529,7 +4529,7 @@ schemas: !Schemas description: A name-value pair to associate with the share as metadata. protocol: !Protocols {} - !Property - schema: *ref_36 + schema: *ref_34 flattenedNames: - properties - shareQuota @@ -4540,7 +4540,7 @@ schemas: !Schemas description: The maximum size of the share, in gigabytes. Must be greater than 0, and less than or equal to 5TB (5120). For Large File Shares, the maximum size is 102400. protocol: !Protocols {} - !Property - schema: *ref_37 + schema: *ref_35 flattenedNames: - properties - enabledProtocols @@ -4551,7 +4551,7 @@ schemas: !Schemas description: The authentication protocol that is used for the file share. Can only be specified when creating a share. protocol: !Protocols {} - !Property - schema: *ref_38 + schema: *ref_36 flattenedNames: - properties - rootSquash @@ -4562,7 +4562,7 @@ schemas: !Schemas description: The property is for NFS share only. The default is NoRootSquash. protocol: !Protocols {} - !Property - schema: *ref_39 + schema: *ref_37 flattenedNames: - properties - version @@ -4574,7 +4574,7 @@ schemas: !Schemas description: The version of the share. protocol: !Protocols {} - !Property - schema: *ref_40 + schema: *ref_38 flattenedNames: - properties - deleted @@ -4586,7 +4586,7 @@ schemas: !Schemas description: Indicates whether the share was deleted. protocol: !Protocols {} - !Property - schema: *ref_41 + schema: *ref_39 flattenedNames: - properties - deletedTime @@ -4598,7 +4598,7 @@ schemas: !Schemas description: The deleted time if the share was deleted. protocol: !Protocols {} - !Property - schema: *ref_42 + schema: *ref_40 flattenedNames: - properties - remainingRetentionDays @@ -4610,7 +4610,7 @@ schemas: !Schemas description: Remaining retention days for share that was soft deleted. protocol: !Protocols {} - !Property - schema: *ref_43 + schema: *ref_41 flattenedNames: - properties - accessTier @@ -4621,7 +4621,7 @@ schemas: !Schemas description: Access tier for specific share. GpV2 account can choose between TransactionOptimized (default), Hot, and Cool. FileStorage account can choose Premium. protocol: !Protocols {} - !Property - schema: *ref_44 + schema: *ref_42 flattenedNames: - properties - accessTierChangeTime @@ -4633,7 +4633,7 @@ schemas: !Schemas description: Indicates the last modification time for share access tier. protocol: !Protocols {} - !Property - schema: *ref_45 + schema: *ref_43 flattenedNames: - properties - accessTierStatus @@ -4645,7 +4645,7 @@ schemas: !Schemas description: Indicates if there is a pending transition for access tier. protocol: !Protocols {} - !Property - schema: *ref_46 + schema: *ref_44 flattenedNames: - properties - shareUsageBytes @@ -4659,12 +4659,12 @@ schemas: !Schemas serializationFormats: - json usage: - - input - output + - input language: !Languages default: - name: FileShare - description: Properties of the file share, including Id, resource name, resource type, Etag. + name: FileShareItem + description: The file share properties be listed out. namespace: '' protocol: !Protocols {} immediate: @@ -4701,7 +4701,6 @@ schemas: !Schemas protocol: !Protocols {} - *ref_47 - *ref_48 - - *ref_49 - !ObjectSchema &ref_171 type: object apiVersions: @@ -4959,8 +4958,7 @@ schemas: !Schemas description: The properties of File services in storage account. namespace: '' protocol: !Protocols {} - - *ref_50 - - *ref_51 + - *ref_49 - !ObjectSchema &ref_62 type: object apiVersions: @@ -7200,6 +7198,8 @@ schemas: !Schemas description: The Encryption Scope resource. namespace: '' protocol: !Protocols {} + - *ref_50 + - *ref_51 immediate: - *ref_4 - *ref_5 @@ -7508,11 +7508,10 @@ schemas: !Schemas protocol: !Protocols {} - *ref_5 - *ref_47 - - *ref_32 + - *ref_45 - *ref_192 - - *ref_33 + - *ref_46 - *ref_193 - - *ref_48 - !ObjectSchema &ref_399 type: object apiVersions: @@ -7561,7 +7560,7 @@ schemas: !Schemas description: The LegalHold property of a blob container. namespace: '' protocol: !Protocols {} - - *ref_49 + - *ref_48 - !ObjectSchema &ref_443 type: object apiVersions: @@ -7789,7 +7788,7 @@ schemas: !Schemas apiVersions: - !ApiVersion version: '2019-06-01' - elementType: *ref_50 + elementType: *ref_49 language: !Languages default: name: FileShareItemsValue @@ -7821,8 +7820,7 @@ schemas: !Schemas description: Response schema. Contains list of shares returned, and if paging is requested or required, a URL to next page of shares. namespace: '' protocol: !Protocols {} - - *ref_50 - - *ref_51 + - *ref_49 - !ObjectSchema &ref_483 type: object apiVersions: @@ -9556,6 +9554,8 @@ schemas: !Schemas description: List of encryption scopes requested, and if paging is required, a URL to the next page of encryption scopes. namespace: '' protocol: !Protocols {} + - *ref_50 + - *ref_51 arrays: - *ref_322 - *ref_323 @@ -10411,7 +10411,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_385 - schema: *ref_48 + schema: *ref_47 implementation: Method required: true language: !Languages @@ -10455,7 +10455,7 @@ operationGroups: - *ref_388 responses: - !SchemaResponse - schema: *ref_48 + schema: *ref_47 language: !Languages default: name: '' @@ -10468,7 +10468,7 @@ operationGroups: statusCodes: - '200' - !SchemaResponse - schema: *ref_48 + schema: *ref_47 language: !Languages default: name: '' @@ -10599,7 +10599,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_389 - schema: *ref_48 + schema: *ref_47 implementation: Method required: true language: !Languages @@ -10643,7 +10643,7 @@ operationGroups: - *ref_392 responses: - !SchemaResponse - schema: *ref_48 + schema: *ref_47 language: !Languages default: name: '' @@ -10765,7 +10765,7 @@ operationGroups: - *ref_395 responses: - !SchemaResponse - schema: *ref_48 + schema: *ref_47 language: !Languages default: name: '' @@ -11343,7 +11343,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_411 - schema: *ref_49 + schema: *ref_48 flattened: true implementation: Method required: false @@ -11414,7 +11414,7 @@ operationGroups: - *ref_419 responses: - !SchemaResponse - schema: *ref_49 + schema: *ref_48 language: !Languages default: name: '' @@ -11569,7 +11569,7 @@ operationGroups: - *ref_424 responses: - !SchemaResponse - schema: *ref_49 + schema: *ref_48 language: !Languages default: name: '' @@ -11721,7 +11721,7 @@ operationGroups: - *ref_429 responses: - !SchemaResponse - schema: *ref_49 + schema: *ref_48 language: !Languages default: name: '' @@ -11863,7 +11863,7 @@ operationGroups: - *ref_434 responses: - !SchemaResponse - schema: *ref_49 + schema: *ref_48 language: !Languages default: name: '' @@ -11986,7 +11986,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_436 - schema: *ref_49 + schema: *ref_48 flattened: true implementation: Method required: false @@ -12057,7 +12057,7 @@ operationGroups: - *ref_442 responses: - !SchemaResponse - schema: *ref_49 + schema: *ref_48 language: !Languages default: name: '' @@ -13128,7 +13128,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_468 - schema: *ref_51 + schema: *ref_49 implementation: Method required: true language: !Languages @@ -13172,7 +13172,7 @@ operationGroups: - *ref_471 responses: - !SchemaResponse - schema: *ref_51 + schema: *ref_49 language: !Languages default: name: '' @@ -13185,7 +13185,7 @@ operationGroups: statusCodes: - '200' - !SchemaResponse - schema: *ref_51 + schema: *ref_49 language: !Languages default: name: '' @@ -13353,7 +13353,7 @@ operationGroups: http: !HttpParameter in: header - !Parameter &ref_472 - schema: *ref_51 + schema: *ref_49 implementation: Method required: true language: !Languages @@ -13397,7 +13397,7 @@ operationGroups: - *ref_475 responses: - !SchemaResponse - schema: *ref_51 + schema: *ref_49 language: !Languages default: name: '' @@ -13540,7 +13540,7 @@ operationGroups: - *ref_479 responses: - !SchemaResponse - schema: *ref_51 + schema: *ref_49 language: !Languages default: name: '' diff --git a/samples/Azure.Management.Storage/Generated/EncryptionScopeContainer.cs b/samples/Azure.Management.Storage/Generated/EncryptionScopeContainer.cs index 05c3f812f04..7f9beb14227 100644 --- a/samples/Azure.Management.Storage/Generated/EncryptionScopeContainer.cs +++ b/samples/Azure.Management.Storage/Generated/EncryptionScopeContainer.cs @@ -5,23 +5,357 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of EncryptionScope and their operations over a StorageAccount. - public partial class EncryptionScopeContainer + public partial class EncryptionScopeContainer : ResourceContainerBase { - /// Initializes a new instance of EncryptionScopeContainer for mocking. + /// Initializes a new instance of the class for mocking. protected EncryptionScopeContainer() { } - internal EncryptionScopeContainer(ResourceOperationsBase parent) + /// Initializes a new instance of EncryptionScopeContainer class. + /// The resource representing the parent resource. + internal EncryptionScopeContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private EncryptionScopesRestOperations _restClient => new EncryptionScopesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a EncryptionScope. Please note some properties can be set only during creation. + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Encryption scope properties to be used for the create or update. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string encryptionScopeName, EncryptionScopeData encryptionScope, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + if (encryptionScope == null) + { + throw new ArgumentNullException(nameof(encryptionScope)); + } + + return StartCreateOrUpdate(encryptionScopeName, encryptionScope, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a EncryptionScope. Please note some properties can be set only during creation. + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Encryption scope properties to be used for the create or update. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string encryptionScopeName, EncryptionScopeData encryptionScope, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + if (encryptionScope == null) + { + throw new ArgumentNullException(nameof(encryptionScope)); + } + + var operation = await StartCreateOrUpdateAsync(encryptionScopeName, encryptionScope, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a EncryptionScope. Please note some properties can be set only during creation. + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Encryption scope properties to be used for the create or update. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string encryptionScopeName, EncryptionScopeData encryptionScope, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + if (encryptionScope == null) + { + throw new ArgumentNullException(nameof(encryptionScope)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, Id.Parent.Name, encryptionScopeName, encryptionScope, cancellationToken: cancellationToken); + return new EncryptionScopesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a EncryptionScope. Please note some properties can be set only during creation. + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Encryption scope properties to be used for the create or update. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string encryptionScopeName, EncryptionScopeData encryptionScope, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + if (encryptionScope == null) + { + throw new ArgumentNullException(nameof(encryptionScope)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, Id.Parent.Name, encryptionScopeName, encryptionScope, cancellationToken: cancellationToken).ConfigureAwait(false); + return new EncryptionScopesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string encryptionScopeName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.Get"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, encryptionScopeName, cancellationToken: cancellationToken); + return Response.FromValue(new EncryptionScope(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string encryptionScopeName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.Get"); + scope.Start(); + try + { + if (encryptionScopeName == null) + { + throw new ArgumentNullException(nameof(encryptionScopeName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, encryptionScopeName, cancellationToken: cancellationToken); + return Response.FromValue(new EncryptionScope(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new EncryptionScope(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new EncryptionScope(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new EncryptionScopeOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new EncryptionScope(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new EncryptionScope(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new EncryptionScopeOperations(genericResource).Get().Value); + } + + /// Filters the list of EncryptionScope for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(EncryptionScopeOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of EncryptionScope for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("EncryptionScopeContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(EncryptionScopeOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/EncryptionScopeOperations.cs b/samples/Azure.Management.Storage/Generated/EncryptionScopeOperations.cs index 7702f371cd2..1dd92fe9bde 100644 --- a/samples/Azure.Management.Storage/Generated/EncryptionScopeOperations.cs +++ b/samples/Azure.Management.Storage/Generated/EncryptionScopeOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific EncryptionScope. public partial class EncryptionScopeOperations : ResourceOperationsBase { - /// Initializes a new instance of EncryptionScopeOperations for mocking. + /// Initializes a new instance of the class for mocking. protected EncryptionScopeOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a EncryptionScope. + internal EncryptionScopeOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected EncryptionScopeOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/FileServiceContainer.cs b/samples/Azure.Management.Storage/Generated/FileServiceContainer.cs index ffca0434df4..4fb3c871343 100644 --- a/samples/Azure.Management.Storage/Generated/FileServiceContainer.cs +++ b/samples/Azure.Management.Storage/Generated/FileServiceContainer.cs @@ -5,23 +5,286 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of FileService and their operations over a StorageAccount. - public partial class FileServiceContainer + public partial class FileServiceContainer : ResourceContainerBase { - /// Initializes a new instance of FileServiceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected FileServiceContainer() { } - internal FileServiceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of FileServiceContainer class. + /// The resource representing the parent resource. + internal FileServiceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private FileServicesRestOperations _restClient => new FileServicesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a FileService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// Specifies CORS rules for the File service. You can include up to five CorsRule elements in the request. If no CorsRule elements are included in the request body, all CORS rules will be deleted, and CORS will be disabled for the File service. + /// The file service properties for share soft delete. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string accountName, CorsRules cors = null, DeleteRetentionPolicy shareDeleteRetentionPolicy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + return StartCreateOrUpdate(accountName, cors, shareDeleteRetentionPolicy, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// Specifies CORS rules for the File service. You can include up to five CorsRule elements in the request. If no CorsRule elements are included in the request body, all CORS rules will be deleted, and CORS will be disabled for the File service. + /// The file service properties for share soft delete. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string accountName, CorsRules cors = null, DeleteRetentionPolicy shareDeleteRetentionPolicy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var operation = await StartCreateOrUpdateAsync(accountName, cors, shareDeleteRetentionPolicy, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// Specifies CORS rules for the File service. You can include up to five CorsRule elements in the request. If no CorsRule elements are included in the request body, all CORS rules will be deleted, and CORS will be disabled for the File service. + /// The file service properties for share soft delete. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string accountName, CorsRules cors = null, DeleteRetentionPolicy shareDeleteRetentionPolicy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var originalResponse = _restClient.SetServiceProperties(Id.ResourceGroupName, accountName, cors, shareDeleteRetentionPolicy, cancellationToken: cancellationToken); + return new FileServicesSetServicePropertiesOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileService. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// Specifies CORS rules for the File service. You can include up to five CorsRule elements in the request. If no CorsRule elements are included in the request body, all CORS rules will be deleted, and CORS will be disabled for the File service. + /// The file service properties for share soft delete. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string accountName, CorsRules cors = null, DeleteRetentionPolicy shareDeleteRetentionPolicy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var originalResponse = await _restClient.SetServicePropertiesAsync(Id.ResourceGroupName, accountName, cors, shareDeleteRetentionPolicy, cancellationToken: cancellationToken).ConfigureAwait(false); + return new FileServicesSetServicePropertiesOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = _restClient.GetServiceProperties(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new FileService(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = await _restClient.GetServicePropertiesAsync(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new FileService(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new FileServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new FileServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new FileServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new FileServiceOperations(genericResource).Get().Value); + } + + /// Filters the list of FileService for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(FileServiceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of FileService for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileServiceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(FileServiceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/FileServiceOperations.cs b/samples/Azure.Management.Storage/Generated/FileServiceOperations.cs index fe650e5bd4b..09b6cdf6f2b 100644 --- a/samples/Azure.Management.Storage/Generated/FileServiceOperations.cs +++ b/samples/Azure.Management.Storage/Generated/FileServiceOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific FileService. public partial class FileServiceOperations : ResourceOperationsBase { - /// Initializes a new instance of FileServiceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected FileServiceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a FileService. + internal FileServiceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected FileServiceOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/FileShareContainer.cs b/samples/Azure.Management.Storage/Generated/FileShareContainer.cs index 15259630309..8e73b6d89d6 100644 --- a/samples/Azure.Management.Storage/Generated/FileShareContainer.cs +++ b/samples/Azure.Management.Storage/Generated/FileShareContainer.cs @@ -5,23 +5,357 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of FileShare and their operations over a StorageAccount. - public partial class FileShareContainer + public partial class FileShareContainer : ResourceContainerBase { - /// Initializes a new instance of FileShareContainer for mocking. + /// Initializes a new instance of the class for mocking. protected FileShareContainer() { } - internal FileShareContainer(ResourceOperationsBase parent) + /// Initializes a new instance of FileShareContainer class. + /// The resource representing the parent resource. + internal FileShareContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private FileSharesRestOperations _restClient => new FileSharesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a FileShare. Please note some properties can be set only during creation. + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the file share to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string shareName, FileShareData fileShare, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + if (fileShare == null) + { + throw new ArgumentNullException(nameof(fileShare)); + } + + return StartCreateOrUpdate(shareName, fileShare, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileShare. Please note some properties can be set only during creation. + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the file share to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string shareName, FileShareData fileShare, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + if (fileShare == null) + { + throw new ArgumentNullException(nameof(fileShare)); + } + + var operation = await StartCreateOrUpdateAsync(shareName, fileShare, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileShare. Please note some properties can be set only during creation. + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the file share to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string shareName, FileShareData fileShare, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + if (fileShare == null) + { + throw new ArgumentNullException(nameof(fileShare)); + } + + var originalResponse = _restClient.Create(Id.ResourceGroupName, Id.Parent.Name, shareName, fileShare, cancellationToken: cancellationToken); + return new FileSharesCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a FileShare. Please note some properties can be set only during creation. + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// Properties of the file share to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string shareName, FileShareData fileShare, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + if (fileShare == null) + { + throw new ArgumentNullException(nameof(fileShare)); + } + + var originalResponse = await _restClient.CreateAsync(Id.ResourceGroupName, Id.Parent.Name, shareName, fileShare, cancellationToken: cancellationToken).ConfigureAwait(false); + return new FileSharesCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string shareName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.Get"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, shareName, cancellationToken: cancellationToken); + return Response.FromValue(new FileShare(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the file share within the specified storage account. File share names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string shareName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.Get"); + scope.Start(); + try + { + if (shareName == null) + { + throw new ArgumentNullException(nameof(shareName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, shareName, cancellationToken: cancellationToken); + return Response.FromValue(new FileShare(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new FileShare(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new FileShare(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new FileShareOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new FileShare(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new FileShare(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new FileShareOperations(genericResource).Get().Value); + } + + /// Filters the list of FileShare for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(FileShareOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of FileShare for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("FileShareContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(FileShareOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/FileShareOperations.cs b/samples/Azure.Management.Storage/Generated/FileShareOperations.cs index 01a6679daa7..8f71c2057fb 100644 --- a/samples/Azure.Management.Storage/Generated/FileShareOperations.cs +++ b/samples/Azure.Management.Storage/Generated/FileShareOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific FileShare. public partial class FileShareOperations : ResourceOperationsBase { - /// Initializes a new instance of FileShareOperations for mocking. + /// Initializes a new instance of the class for mocking. protected FileShareOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a FileShare. + internal FileShareOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected FileShareOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/ManagementPolicyContainer.cs b/samples/Azure.Management.Storage/Generated/ManagementPolicyContainer.cs index 1d0a1215772..d9f8fb52344 100644 --- a/samples/Azure.Management.Storage/Generated/ManagementPolicyContainer.cs +++ b/samples/Azure.Management.Storage/Generated/ManagementPolicyContainer.cs @@ -5,23 +5,262 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of ManagementPolicy and their operations over a StorageAccount. - public partial class ManagementPolicyContainer + public partial class ManagementPolicyContainer : ResourceContainerBase { - /// Initializes a new instance of ManagementPolicyContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ManagementPolicyContainer() { } - internal ManagementPolicyContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ManagementPolicyContainer class. + /// The resource representing the parent resource. + internal ManagementPolicyContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ManagementPoliciesRestOperations _restClient => new ManagementPoliciesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ManagementPolicy. Please note some properties can be set only during creation. + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// The Storage Account ManagementPolicy, in JSON format. See more details in: https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(ManagementPolicyName managementPolicyName, ManagementPolicySchema policy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.CreateOrUpdate"); + scope.Start(); + try + { + return StartCreateOrUpdate(managementPolicyName, policy, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ManagementPolicy. Please note some properties can be set only during creation. + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// The Storage Account ManagementPolicy, in JSON format. See more details in: https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(ManagementPolicyName managementPolicyName, ManagementPolicySchema policy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.CreateOrUpdate"); + scope.Start(); + try + { + var operation = await StartCreateOrUpdateAsync(managementPolicyName, policy, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ManagementPolicy. Please note some properties can be set only during creation. + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// The Storage Account ManagementPolicy, in JSON format. See more details in: https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(ManagementPolicyName managementPolicyName, ManagementPolicySchema policy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Name, managementPolicyName, policy, cancellationToken: cancellationToken); + return new ManagementPoliciesCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ManagementPolicy. Please note some properties can be set only during creation. + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// The Storage Account ManagementPolicy, in JSON format. See more details in: https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(ManagementPolicyName managementPolicyName, ManagementPolicySchema policy = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Name, managementPolicyName, policy, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ManagementPoliciesCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string managementPolicyName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.Get"); + scope.Start(); + try + { + if (managementPolicyName == null) + { + throw new ArgumentNullException(nameof(managementPolicyName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, managementPolicyName, cancellationToken: cancellationToken); + return Response.FromValue(new ManagementPolicy(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the Storage Account Management Policy. It should always be 'default'. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string managementPolicyName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.Get"); + scope.Start(); + try + { + if (managementPolicyName == null) + { + throw new ArgumentNullException(nameof(managementPolicyName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, managementPolicyName, cancellationToken: cancellationToken); + return Response.FromValue(new ManagementPolicy(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ManagementPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ManagementPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ManagementPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ManagementPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of ManagementPolicy for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ManagementPolicyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ManagementPolicy for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ManagementPolicyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ManagementPolicyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/ManagementPolicyOperations.cs b/samples/Azure.Management.Storage/Generated/ManagementPolicyOperations.cs index 2b9de20fc67..afc01984cf3 100644 --- a/samples/Azure.Management.Storage/Generated/ManagementPolicyOperations.cs +++ b/samples/Azure.Management.Storage/Generated/ManagementPolicyOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific ManagementPolicy. public partial class ManagementPolicyOperations : ResourceOperationsBase { - /// Initializes a new instance of ManagementPolicyOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ManagementPolicyOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ManagementPolicy. + internal ManagementPolicyOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ManagementPolicyOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/Models/FileShareItems.Serialization.cs b/samples/Azure.Management.Storage/Generated/Models/FileShareItems.Serialization.cs index 3759a230eda..1a875a67d50 100644 --- a/samples/Azure.Management.Storage/Generated/Models/FileShareItems.Serialization.cs +++ b/samples/Azure.Management.Storage/Generated/Models/FileShareItems.Serialization.cs @@ -15,7 +15,7 @@ internal partial class FileShareItems { internal static FileShareItems DeserializeFileShareItems(JsonElement element) { - Optional> value = default; + Optional> value = default; Optional nextLink = default; foreach (var property in element.EnumerateObject()) { @@ -26,10 +26,10 @@ internal static FileShareItems DeserializeFileShareItems(JsonElement element) property.ThrowNonNullablePropertyIsNull(); continue; } - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(FileShareItem.DeserializeFileShareItem(item)); + array.Add(FileShareData.DeserializeFileShareData(item)); } value = array; continue; diff --git a/samples/Azure.Management.Storage/Generated/Models/FileShareItems.cs b/samples/Azure.Management.Storage/Generated/Models/FileShareItems.cs index 5f18b0ebd6b..631106aa17b 100644 --- a/samples/Azure.Management.Storage/Generated/Models/FileShareItems.cs +++ b/samples/Azure.Management.Storage/Generated/Models/FileShareItems.cs @@ -16,20 +16,20 @@ internal partial class FileShareItems /// Initializes a new instance of FileShareItems. internal FileShareItems() { - Value = new ChangeTrackingList(); + Value = new ChangeTrackingList(); } /// Initializes a new instance of FileShareItems. /// List of file shares returned. /// Request URL that can be used to query next page of shares. Returned when total number of requested shares exceed maximum page size. - internal FileShareItems(IReadOnlyList value, string nextLink) + internal FileShareItems(IReadOnlyList value, string nextLink) { Value = value; NextLink = nextLink; } /// List of file shares returned. - public IReadOnlyList Value { get; } + public IReadOnlyList Value { get; } /// Request URL that can be used to query next page of shares. Returned when total number of requested shares exceed maximum page size. public string NextLink { get; } } diff --git a/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.Serialization.cs b/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.Serialization.cs index c16988de6c1..9903cb196ed 100644 --- a/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.Serialization.cs +++ b/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.Serialization.cs @@ -15,7 +15,7 @@ internal partial class ListContainerItems { internal static ListContainerItems DeserializeListContainerItems(JsonElement element) { - Optional> value = default; + Optional> value = default; Optional nextLink = default; foreach (var property in element.EnumerateObject()) { @@ -26,10 +26,10 @@ internal static ListContainerItems DeserializeListContainerItems(JsonElement ele property.ThrowNonNullablePropertyIsNull(); continue; } - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(ListContainerItem.DeserializeListContainerItem(item)); + array.Add(BlobContainerData.DeserializeBlobContainerData(item)); } value = array; continue; diff --git a/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.cs b/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.cs index b874851eac3..6b9783fe613 100644 --- a/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.cs +++ b/samples/Azure.Management.Storage/Generated/Models/ListContainerItems.cs @@ -16,20 +16,20 @@ internal partial class ListContainerItems /// Initializes a new instance of ListContainerItems. internal ListContainerItems() { - Value = new ChangeTrackingList(); + Value = new ChangeTrackingList(); } /// Initializes a new instance of ListContainerItems. /// List of blobs containers returned. /// Request URL that can be used to query next page of containers. Returned when total number of requested containers exceed maximum page size. - internal ListContainerItems(IReadOnlyList value, string nextLink) + internal ListContainerItems(IReadOnlyList value, string nextLink) { Value = value; NextLink = nextLink; } /// List of blobs containers returned. - public IReadOnlyList Value { get; } + public IReadOnlyList Value { get; } /// Request URL that can be used to query next page of containers. Returned when total number of requested containers exceed maximum page size. public string NextLink { get; } } diff --git a/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyContainer.cs b/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyContainer.cs index 46b9036d803..29e65c337d6 100644 --- a/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyContainer.cs +++ b/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyContainer.cs @@ -5,23 +5,327 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of ObjectReplicationPolicy and their operations over a StorageAccount. - public partial class ObjectReplicationPolicyContainer + public partial class ObjectReplicationPolicyContainer : ResourceContainerBase { - /// Initializes a new instance of ObjectReplicationPolicyContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ObjectReplicationPolicyContainer() { } - internal ObjectReplicationPolicyContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ObjectReplicationPolicyContainer class. + /// The resource representing the parent resource. + internal ObjectReplicationPolicyContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ObjectReplicationPoliciesRestOperations _restClient => new ObjectReplicationPoliciesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ObjectReplicationPolicy. Please note some properties can be set only during creation. + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// The object replication policy set to a storage account. A unique policy ID will be created if absent. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string objectReplicationPolicyId, ObjectReplicationPolicyData properties, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + if (properties == null) + { + throw new ArgumentNullException(nameof(properties)); + } + + return StartCreateOrUpdate(objectReplicationPolicyId, properties, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ObjectReplicationPolicy. Please note some properties can be set only during creation. + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// The object replication policy set to a storage account. A unique policy ID will be created if absent. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string objectReplicationPolicyId, ObjectReplicationPolicyData properties, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + if (properties == null) + { + throw new ArgumentNullException(nameof(properties)); + } + + var operation = await StartCreateOrUpdateAsync(objectReplicationPolicyId, properties, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ObjectReplicationPolicy. Please note some properties can be set only during creation. + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// The object replication policy set to a storage account. A unique policy ID will be created if absent. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string objectReplicationPolicyId, ObjectReplicationPolicyData properties, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + if (properties == null) + { + throw new ArgumentNullException(nameof(properties)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Name, objectReplicationPolicyId, properties, cancellationToken: cancellationToken); + return new ObjectReplicationPoliciesCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ObjectReplicationPolicy. Please note some properties can be set only during creation. + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// The object replication policy set to a storage account. A unique policy ID will be created if absent. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string objectReplicationPolicyId, ObjectReplicationPolicyData properties, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + if (properties == null) + { + throw new ArgumentNullException(nameof(properties)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Name, objectReplicationPolicyId, properties, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ObjectReplicationPoliciesCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string objectReplicationPolicyId, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.Get"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, objectReplicationPolicyId, cancellationToken: cancellationToken); + return Response.FromValue(new ObjectReplicationPolicy(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The ID of object replication policy or 'default' if the policy ID is unknown. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string objectReplicationPolicyId, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.Get"); + scope.Start(); + try + { + if (objectReplicationPolicyId == null) + { + throw new ArgumentNullException(nameof(objectReplicationPolicyId)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, objectReplicationPolicyId, cancellationToken: cancellationToken); + return Response.FromValue(new ObjectReplicationPolicy(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new ObjectReplicationPolicy(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ObjectReplicationPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new ObjectReplicationPolicy(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ObjectReplicationPolicyOperations(genericResource).Get().Value); + } + + /// Filters the list of ObjectReplicationPolicy for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ObjectReplicationPolicyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ObjectReplicationPolicy for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ObjectReplicationPolicyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ObjectReplicationPolicyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyOperations.cs b/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyOperations.cs index 9f015cf7a00..3e336263ad0 100644 --- a/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyOperations.cs +++ b/samples/Azure.Management.Storage/Generated/ObjectReplicationPolicyOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific ObjectReplicationPolicy. public partial class ObjectReplicationPolicyOperations : ResourceOperationsBase { - /// Initializes a new instance of ObjectReplicationPolicyOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ObjectReplicationPolicyOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ObjectReplicationPolicy. + internal ObjectReplicationPolicyOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ObjectReplicationPolicyOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionContainer.cs b/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionContainer.cs index 39b418a50d1..e0729891e45 100644 --- a/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionContainer.cs +++ b/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionContainer.cs @@ -5,23 +5,286 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of PrivateEndpointConnection and their operations over a StorageAccount. - public partial class PrivateEndpointConnectionContainer + public partial class PrivateEndpointConnectionContainer : ResourceContainerBase { - /// Initializes a new instance of PrivateEndpointConnectionContainer for mocking. + /// Initializes a new instance of the class for mocking. protected PrivateEndpointConnectionContainer() { } - internal PrivateEndpointConnectionContainer(ResourceOperationsBase parent) + /// Initializes a new instance of PrivateEndpointConnectionContainer class. + /// The resource representing the parent resource. + internal PrivateEndpointConnectionContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private PrivateEndpointConnectionsRestOperations _restClient => new PrivateEndpointConnectionsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a PrivateEndpointConnection. Please note some properties can be set only during creation. + /// The name of the private endpoint connection associated with the Storage Account. + /// The resource of private end point. + /// A collection of information about the state of the connection between service consumer and provider. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string privateEndpointConnectionName, PrivateEndpoint privateEndpoint = null, PrivateLinkServiceConnectionState privateLinkServiceConnectionState = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + return StartCreateOrUpdate(privateEndpointConnectionName, privateEndpoint, privateLinkServiceConnectionState, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a PrivateEndpointConnection. Please note some properties can be set only during creation. + /// The name of the private endpoint connection associated with the Storage Account. + /// The resource of private end point. + /// A collection of information about the state of the connection between service consumer and provider. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string privateEndpointConnectionName, PrivateEndpoint privateEndpoint = null, PrivateLinkServiceConnectionState privateLinkServiceConnectionState = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + var operation = await StartCreateOrUpdateAsync(privateEndpointConnectionName, privateEndpoint, privateLinkServiceConnectionState, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a PrivateEndpointConnection. Please note some properties can be set only during creation. + /// The name of the private endpoint connection associated with the Storage Account. + /// The resource of private end point. + /// A collection of information about the state of the connection between service consumer and provider. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string privateEndpointConnectionName, PrivateEndpoint privateEndpoint = null, PrivateLinkServiceConnectionState privateLinkServiceConnectionState = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, Id.Parent.Name, privateEndpointConnectionName, privateEndpoint, privateLinkServiceConnectionState, cancellationToken: cancellationToken); + return new PrivateEndpointConnectionsPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a PrivateEndpointConnection. Please note some properties can be set only during creation. + /// The name of the private endpoint connection associated with the Storage Account. + /// The resource of private end point. + /// A collection of information about the state of the connection between service consumer and provider. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string privateEndpointConnectionName, PrivateEndpoint privateEndpoint = null, PrivateLinkServiceConnectionState privateLinkServiceConnectionState = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, Id.Parent.Name, privateEndpointConnectionName, privateEndpoint, privateLinkServiceConnectionState, cancellationToken: cancellationToken).ConfigureAwait(false); + return new PrivateEndpointConnectionsPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the private endpoint connection associated with the Storage Account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string privateEndpointConnectionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.Get"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, privateEndpointConnectionName, cancellationToken: cancellationToken); + return Response.FromValue(new PrivateEndpointConnection(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the private endpoint connection associated with the Storage Account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string privateEndpointConnectionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.Get"); + scope.Start(); + try + { + if (privateEndpointConnectionName == null) + { + throw new ArgumentNullException(nameof(privateEndpointConnectionName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, privateEndpointConnectionName, cancellationToken: cancellationToken); + return Response.FromValue(new PrivateEndpointConnection(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new PrivateEndpointConnectionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new PrivateEndpointConnectionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new PrivateEndpointConnectionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new PrivateEndpointConnectionOperations(genericResource).Get().Value); + } + + /// Filters the list of PrivateEndpointConnection for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(PrivateEndpointConnectionOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of PrivateEndpointConnection for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateEndpointConnectionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(PrivateEndpointConnectionOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionOperations.cs b/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionOperations.cs index cbbb9fadb63..5f3680a7e79 100644 --- a/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionOperations.cs +++ b/samples/Azure.Management.Storage/Generated/PrivateEndpointConnectionOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific PrivateEndpointConnection. public partial class PrivateEndpointConnectionOperations : ResourceOperationsBase { - /// Initializes a new instance of PrivateEndpointConnectionOperations for mocking. + /// Initializes a new instance of the class for mocking. protected PrivateEndpointConnectionOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a PrivateEndpointConnection. + internal PrivateEndpointConnectionOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected PrivateEndpointConnectionOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/PrivateLinkResourceContainer.cs b/samples/Azure.Management.Storage/Generated/PrivateLinkResourceContainer.cs index 25d5c20b6e4..06a704f69fd 100644 --- a/samples/Azure.Management.Storage/Generated/PrivateLinkResourceContainer.cs +++ b/samples/Azure.Management.Storage/Generated/PrivateLinkResourceContainer.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of PrivateLinkResource and their operations over a StorageAccount. - public partial class PrivateLinkResourceContainer + public partial class PrivateLinkResourceContainer : ContainerBase { - /// Initializes a new instance of PrivateLinkResourceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected PrivateLinkResourceContainer() { } - internal PrivateLinkResourceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of PrivateLinkResourceContainer class. + /// The resource representing the parent resource. + internal PrivateLinkResourceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private PrivateLinkResourcesRestOperations _restClient => new PrivateLinkResourcesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => StorageAccountOperations.ResourceType; + + // Container level operations. + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new PrivateLinkResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new PrivateLinkResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new PrivateLinkResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new PrivateLinkResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of PrivateLinkResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateLinkResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(PrivateLinkResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of PrivateLinkResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("PrivateLinkResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(PrivateLinkResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/PrivateLinkResourceOperations.cs b/samples/Azure.Management.Storage/Generated/PrivateLinkResourceOperations.cs index 16b18610c2d..49dc4b1d20a 100644 --- a/samples/Azure.Management.Storage/Generated/PrivateLinkResourceOperations.cs +++ b/samples/Azure.Management.Storage/Generated/PrivateLinkResourceOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific PrivateLinkResource. public partial class PrivateLinkResourceOperations : ResourceOperationsBase { - /// Initializes a new instance of PrivateLinkResourceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected PrivateLinkResourceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a PrivateLinkResource. + internal PrivateLinkResourceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected PrivateLinkResourceOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/Generated/StorageAccountContainer.cs b/samples/Azure.Management.Storage/Generated/StorageAccountContainer.cs index 1aad2eb7521..d7a68cf7984 100644 --- a/samples/Azure.Management.Storage/Generated/StorageAccountContainer.cs +++ b/samples/Azure.Management.Storage/Generated/StorageAccountContainer.cs @@ -5,23 +5,339 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Management.Storage.Models; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.Management.Storage { /// A class representing collection of StorageAccount and their operations over a Parent. - public partial class StorageAccountContainer + public partial class StorageAccountContainer : ResourceContainerBase { - /// Initializes a new instance of StorageAccountContainer for mocking. + /// Initializes a new instance of the class for mocking. protected StorageAccountContainer() { } - internal StorageAccountContainer(ResourceOperationsBase parent) + /// Initializes a new instance of StorageAccountContainer class. + /// The resource representing the parent resource. + internal StorageAccountContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private StorageAccountsRestOperations _restClient => new StorageAccountsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => "any"; + protected override ResourceType ValidResourceType => "any"; + + // Container level operations. + + /// The operation to create or update a StorageAccount. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The parameters to provide for the created account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string accountName, StorageAccountCreateParameters parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(accountName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a StorageAccount. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The parameters to provide for the created account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string accountName, StorageAccountCreateParameters parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(accountName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a StorageAccount. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The parameters to provide for the created account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string accountName, StorageAccountCreateParameters parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Create(Id.ResourceGroupName, accountName, parameters, cancellationToken: cancellationToken); + var operation = new StorageAccountsCreateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateRequest( + Id.ResourceGroupName, accountName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new StorageAccount(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a StorageAccount. Please note some properties can be set only during creation. + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// The parameters to provide for the created account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string accountName, StorageAccountCreateParameters parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateAsync(Id.ResourceGroupName, accountName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new StorageAccountsCreateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateRequest( + Id.ResourceGroupName, accountName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new StorageAccount(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = _restClient.GetProperties(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new StorageAccount(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string accountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.Get"); + scope.Start(); + try + { + if (accountName == null) + { + throw new ArgumentNullException(nameof(accountName)); + } + + var response = await _restClient.GetPropertiesAsync(Id.ResourceGroupName, accountName, cancellationToken: cancellationToken); + return Response.FromValue(new StorageAccount(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroup(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new StorageAccount(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new StorageAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new StorageAccount(Parent, value)), null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, null); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new StorageAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of StorageAccount for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(StorageAccountOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of StorageAccount for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("StorageAccountContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(StorageAccountOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.Management.Storage/Generated/StorageAccountOperations.cs b/samples/Azure.Management.Storage/Generated/StorageAccountOperations.cs index 083fbbd580f..ba561845687 100644 --- a/samples/Azure.Management.Storage/Generated/StorageAccountOperations.cs +++ b/samples/Azure.Management.Storage/Generated/StorageAccountOperations.cs @@ -17,12 +17,18 @@ namespace Azure.Management.Storage /// A class representing the operations that can be performed over a specific StorageAccount. public partial class StorageAccountOperations : ResourceOperationsBase { - /// Initializes a new instance of StorageAccountOperations for mocking. + /// Initializes a new instance of the class for mocking. protected StorageAccountOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a StorageAccount. + internal StorageAccountOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected StorageAccountOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.Management.Storage/readme.md b/samples/Azure.Management.Storage/readme.md index a69694e05ef..3079e045075 100644 --- a/samples/Azure.Management.Storage/readme.md +++ b/samples/Azure.Management.Storage/readme.md @@ -42,4 +42,10 @@ directive: - rename-model: from: FileServiceProperties to: FileService + - from: swagger-document + where: $.definitions.FileShareItems.properties.value.items["$ref"] + transform: return "#/definitions/FileShare" + - from: swagger-document + where: $.definitions.ListContainerItems.properties.value.items["$ref"] + transform: return "#/definitions/BlobContainer" ``` diff --git a/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetContainer.cs index 23822c3a6be..bf6fd2da34b 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetContainer.cs @@ -5,23 +5,356 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of AvailabilitySet and their operations over a ResourceGroup. - public partial class AvailabilitySetContainer + public partial class AvailabilitySetContainer : ResourceContainerBase { - /// Initializes a new instance of AvailabilitySetContainer for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetContainer() { } - internal AvailabilitySetContainer(ResourceOperationsBase parent) + /// Initializes a new instance of AvailabilitySetContainer class. + /// The resource representing the parent resource. + internal AvailabilitySetContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private AvailabilitySetsRestOperations _restClient => new AvailabilitySetsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(availabilitySetName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken); + return new AvailabilitySetsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new AvailabilitySetsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetOperations.cs index 71496e5c3bd..a29cd341f72 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/AvailabilitySetOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific AvailabilitySet. public partial class AvailabilitySetOperations : ResourceOperationsBase { - /// Initializes a new instance of AvailabilitySetOperations for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a AvailabilitySet. + internal AvailabilitySetOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected AvailabilitySetOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/Configuration.json b/samples/Azure.ResourceManager.Sample/Generated/Configuration.json index c05a65a0f8a..e9d5b0790a9 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/Configuration.json +++ b/samples/Azure.ResourceManager.Sample/Generated/Configuration.json @@ -30,7 +30,7 @@ "VirtualMachineImages": "VirtualMachineImage", "Usage": "NonResource", "VirtualMachineSizes": "NonResource", - "VirtualMachineScaleSetRollingUpgrades": "VirtualMachineScaleSetRollingUpgrade", + "VirtualMachineScaleSetRollingUpgrades": "NonResource", "LogAnalytics": "NonResource" }, "OperationGroupToParent": { diff --git a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostContainer.cs index 1c5621323be..08c63481496 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of DedicatedHost and their operations over a DedicatedHostGroup. - public partial class DedicatedHostContainer + public partial class DedicatedHostContainer : ResourceContainerBase { - /// Initializes a new instance of DedicatedHostContainer for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostContainer() { } - internal DedicatedHostContainer(ResourceOperationsBase parent) + /// Initializes a new instance of DedicatedHostContainer class. + /// The resource representing the parent resource. + internal DedicatedHostContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private DedicatedHostsRestOperations _restClient => new DedicatedHostsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => DedicatedHostGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => DedicatedHostGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(hostName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(hostName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Name, hostName, parameters, cancellationToken: cancellationToken); + var operation = new DedicatedHostsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, hostName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new DedicatedHost(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Name, hostName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new DedicatedHostsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, hostName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new DedicatedHost(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string hostName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.Get"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, hostName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHost(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string hostName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.Get"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, hostName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHost(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = _restClient.ListByHostGroup(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = _restClient.ListByHostGroupNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new DedicatedHostOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByHostGroupAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByHostGroupNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new DedicatedHostOperations(genericResource).Get().Value); + } + + /// Filters the list of DedicatedHost for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of DedicatedHost for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupContainer.cs index 991ad772ec6..5fe3fb23e47 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupContainer.cs @@ -5,23 +5,356 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of DedicatedHostGroup and their operations over a ResourceGroup. - public partial class DedicatedHostGroupContainer + public partial class DedicatedHostGroupContainer : ResourceContainerBase { - /// Initializes a new instance of DedicatedHostGroupContainer for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostGroupContainer() { } - internal DedicatedHostGroupContainer(ResourceOperationsBase parent) + /// Initializes a new instance of DedicatedHostGroupContainer class. + /// The resource representing the parent resource. + internal DedicatedHostGroupContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private DedicatedHostGroupsRestOperations _restClient => new DedicatedHostGroupsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(hostGroupName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(hostGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, hostGroupName, parameters, cancellationToken: cancellationToken); + return new DedicatedHostGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, hostGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new DedicatedHostGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string hostGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.Get"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, hostGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHostGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string hostGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.Get"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, hostGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHostGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroup(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHostGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroupNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHostGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHostGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHostGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of DedicatedHostGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of DedicatedHostGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupOperations.cs index b0e7c91cd18..e7b12fdbdae 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific DedicatedHostGroup. public partial class DedicatedHostGroupOperations : ResourceOperationsBase { - /// Initializes a new instance of DedicatedHostGroupOperations for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostGroupOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a DedicatedHostGroup. + internal DedicatedHostGroupOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected DedicatedHostGroupOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostOperations.cs index 87ea15c3590..64e47437d97 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific DedicatedHost. public partial class DedicatedHostOperations : ResourceOperationsBase { - /// Initializes a new instance of DedicatedHostOperations for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a DedicatedHost. + internal DedicatedHostOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected DedicatedHostOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/ImageContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/ImageContainer.cs index c018e6be801..24fbfb974ba 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/ImageContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/ImageContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of Image and their operations over a ResourceGroup. - public partial class ImageContainer + public partial class ImageContainer : ResourceContainerBase { - /// Initializes a new instance of ImageContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ImageContainer() { } - internal ImageContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ImageContainer class. + /// The resource representing the parent resource. + internal ImageContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ImagesRestOperations _restClient => new ImagesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a Image. Please note some properties can be set only during creation. + /// The name of the image. + /// Parameters supplied to the Create Image operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string imageName, ImageData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(imageName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Image. Please note some properties can be set only during creation. + /// The name of the image. + /// Parameters supplied to the Create Image operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string imageName, ImageData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(imageName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Image. Please note some properties can be set only during creation. + /// The name of the image. + /// Parameters supplied to the Create Image operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string imageName, ImageData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, imageName, parameters, cancellationToken: cancellationToken); + var operation = new ImagesCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, imageName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new Image(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Image. Please note some properties can be set only during creation. + /// The name of the image. + /// Parameters supplied to the Create Image operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string imageName, ImageData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, imageName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new ImagesCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, imageName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new Image(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the image. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string imageName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.Get"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, imageName, cancellationToken: cancellationToken); + return Response.FromValue(new Image(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the image. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string imageName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.Get"); + scope.Start(); + try + { + if (imageName == null) + { + throw new ArgumentNullException(nameof(imageName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, imageName, cancellationToken: cancellationToken); + return Response.FromValue(new Image(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroup(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new Image(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroupNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new Image(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new Image(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new Image(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ImageOperations(genericResource).Get().Value); + } + + /// Filters the list of Image for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of Image for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/ImageOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/ImageOperations.cs index b4e8b55d97b..40ba1d5a458 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/ImageOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/ImageOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific Image. public partial class ImageOperations : ResourceOperationsBase { - /// Initializes a new instance of ImageOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ImageOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a Image. + internal ImageOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ImageOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.Serialization.cs b/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.Serialization.cs similarity index 92% rename from samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.Serialization.cs rename to samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.Serialization.cs index a0e770402c9..9b95b0e208f 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.Serialization.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.Serialization.cs @@ -12,7 +12,7 @@ namespace Azure.ResourceManager.Sample { - public partial class VirtualMachineScaleSetRollingUpgradeData : IUtf8JsonSerializable + public partial class VirtualMachineScaleSetRollingUpgrade : IUtf8JsonSerializable { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { @@ -33,11 +33,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteEndObject(); } - internal static VirtualMachineScaleSetRollingUpgradeData DeserializeVirtualMachineScaleSetRollingUpgradeData(JsonElement element) + internal static VirtualMachineScaleSetRollingUpgrade DeserializeVirtualMachineScaleSetRollingUpgrade(JsonElement element) { IDictionary tags = default; LocationData location = default; - ResourceGroupResourceIdentifier id = default; + TenantResourceIdentifier id = default; string name = default; ResourceType type = default; Optional policy = default; @@ -129,7 +129,7 @@ internal static VirtualMachineScaleSetRollingUpgradeData DeserializeVirtualMachi continue; } } - return new VirtualMachineScaleSetRollingUpgradeData(id, name, type, location, tags, policy.Value, runningStatus.Value, progress.Value, error.Value); + return new VirtualMachineScaleSetRollingUpgrade(id, name, type, location, tags, policy.Value, runningStatus.Value, progress.Value, error.Value); } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.cs b/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.cs similarity index 72% rename from samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.cs rename to samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.cs index 38b97a7fa3f..a81785d58a7 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgradeData.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/Models/VirtualMachineScaleSetRollingUpgrade.cs @@ -10,16 +10,16 @@ namespace Azure.ResourceManager.Sample { - /// A class representing the VirtualMachineScaleSetRollingUpgrade data model. - public partial class VirtualMachineScaleSetRollingUpgradeData : TrackedResource + /// The status of the latest virtual machine scale set rolling upgrade. + public partial class VirtualMachineScaleSetRollingUpgrade : TrackedResource { - /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeData. + /// Initializes a new instance of VirtualMachineScaleSetRollingUpgrade. /// The location. - public VirtualMachineScaleSetRollingUpgradeData(LocationData location) : base(location) + public VirtualMachineScaleSetRollingUpgrade(LocationData location) : base(location) { } - /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeData. + /// Initializes a new instance of VirtualMachineScaleSetRollingUpgrade. /// The id. /// The name. /// The type. @@ -29,7 +29,7 @@ public VirtualMachineScaleSetRollingUpgradeData(LocationData location) : base(lo /// Information about the current running state of the overall upgrade. /// Information about the number of virtual machine instances in each upgrade state. /// Error details for this upgrade, if there are any. - internal VirtualMachineScaleSetRollingUpgradeData(ResourceGroupResourceIdentifier id, string name, ResourceType type, LocationData location, IDictionary tags, RollingUpgradePolicy policy, RollingUpgradeRunningStatus runningStatus, RollingUpgradeProgressInfo progress, ApiError error) : base(id, name, type, location, tags) + internal VirtualMachineScaleSetRollingUpgrade(TenantResourceIdentifier id, string name, ResourceType type, LocationData location, IDictionary tags, RollingUpgradePolicy policy, RollingUpgradeRunningStatus runningStatus, RollingUpgradeProgressInfo progress, ApiError error) : base(id, name, type, location, tags) { Policy = policy; RunningStatus = runningStatus; diff --git a/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupContainer.cs index 16852049b96..a1797b197d6 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupContainer.cs @@ -5,23 +5,356 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of ProximityPlacementGroup and their operations over a ResourceGroup. - public partial class ProximityPlacementGroupContainer + public partial class ProximityPlacementGroupContainer : ResourceContainerBase { - /// Initializes a new instance of ProximityPlacementGroupContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ProximityPlacementGroupContainer() { } - internal ProximityPlacementGroupContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ProximityPlacementGroupContainer class. + /// The resource representing the parent resource. + internal ProximityPlacementGroupContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ProximityPlacementGroupsRestOperations _restClient => new ProximityPlacementGroupsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ProximityPlacementGroup. Please note some properties can be set only during creation. + /// The name of the proximity placement group. + /// Parameters supplied to the Create Proximity Placement Group operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string proximityPlacementGroupName, ProximityPlacementGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(proximityPlacementGroupName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ProximityPlacementGroup. Please note some properties can be set only during creation. + /// The name of the proximity placement group. + /// Parameters supplied to the Create Proximity Placement Group operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string proximityPlacementGroupName, ProximityPlacementGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(proximityPlacementGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ProximityPlacementGroup. Please note some properties can be set only during creation. + /// The name of the proximity placement group. + /// Parameters supplied to the Create Proximity Placement Group operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string proximityPlacementGroupName, ProximityPlacementGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, proximityPlacementGroupName, parameters, cancellationToken: cancellationToken); + return new ProximityPlacementGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ProximityPlacementGroup. Please note some properties can be set only during creation. + /// The name of the proximity placement group. + /// Parameters supplied to the Create Proximity Placement Group operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string proximityPlacementGroupName, ProximityPlacementGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, proximityPlacementGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ProximityPlacementGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the proximity placement group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string proximityPlacementGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.Get"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, proximityPlacementGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new ProximityPlacementGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the proximity placement group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string proximityPlacementGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.Get"); + scope.Start(); + try + { + if (proximityPlacementGroupName == null) + { + throw new ArgumentNullException(nameof(proximityPlacementGroupName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, proximityPlacementGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new ProximityPlacementGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroup(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new ProximityPlacementGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroupNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new ProximityPlacementGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ProximityPlacementGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new ProximityPlacementGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new ProximityPlacementGroup(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ProximityPlacementGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of ProximityPlacementGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ProximityPlacementGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ProximityPlacementGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ProximityPlacementGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ProximityPlacementGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupOperations.cs index 1b2e511a63e..773f940817f 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/ProximityPlacementGroupOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific ProximityPlacementGroup. public partial class ProximityPlacementGroupOperations : ResourceOperationsBase { - /// Initializes a new instance of ProximityPlacementGroupOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ProximityPlacementGroupOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ProximityPlacementGroup. + internal ProximityPlacementGroupOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ProximityPlacementGroupOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyContainer.cs index e9fc04a7fc2..5289b426f0d 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyContainer.cs @@ -5,23 +5,356 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of SshPublicKey and their operations over a ResourceGroup. - public partial class SshPublicKeyContainer + public partial class SshPublicKeyContainer : ResourceContainerBase { - /// Initializes a new instance of SshPublicKeyContainer for mocking. + /// Initializes a new instance of the class for mocking. protected SshPublicKeyContainer() { } - internal SshPublicKeyContainer(ResourceOperationsBase parent) + /// Initializes a new instance of SshPublicKeyContainer class. + /// The resource representing the parent resource. + internal SshPublicKeyContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private SshPublicKeysRestOperations _restClient => new SshPublicKeysRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a SshPublicKey. Please note some properties can be set only during creation. + /// The name of the SSH public key. + /// Parameters supplied to create the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string sshPublicKeyName, SshPublicKeyData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(sshPublicKeyName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SshPublicKey. Please note some properties can be set only during creation. + /// The name of the SSH public key. + /// Parameters supplied to create the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string sshPublicKeyName, SshPublicKeyData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(sshPublicKeyName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SshPublicKey. Please note some properties can be set only during creation. + /// The name of the SSH public key. + /// Parameters supplied to create the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string sshPublicKeyName, SshPublicKeyData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Create(Id.ResourceGroupName, sshPublicKeyName, parameters, cancellationToken: cancellationToken); + return new SshPublicKeysCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SshPublicKey. Please note some properties can be set only during creation. + /// The name of the SSH public key. + /// Parameters supplied to create the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string sshPublicKeyName, SshPublicKeyData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateAsync(Id.ResourceGroupName, sshPublicKeyName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new SshPublicKeysCreateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string sshPublicKeyName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.Get"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, sshPublicKeyName, cancellationToken: cancellationToken); + return Response.FromValue(new SshPublicKey(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the SSH public key. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string sshPublicKeyName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.Get"); + scope.Start(); + try + { + if (sshPublicKeyName == null) + { + throw new ArgumentNullException(nameof(sshPublicKeyName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, sshPublicKeyName, cancellationToken: cancellationToken); + return Response.FromValue(new SshPublicKey(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroup(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new SshPublicKey(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = _restClient.ListByResourceGroupNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new SshPublicKey(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SshPublicKeyOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new SshPublicKey(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListByResourceGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByResourceGroupNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new SshPublicKey(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SshPublicKeyOperations(genericResource).Get().Value); + } + + /// Filters the list of SshPublicKey for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SshPublicKeyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of SshPublicKey for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SshPublicKeyContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SshPublicKeyOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyOperations.cs index 0512c5d93e4..c32d921a731 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/SshPublicKeyOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific SshPublicKey. public partial class SshPublicKeyOperations : ResourceOperationsBase { - /// Initializes a new instance of SshPublicKeyOperations for mocking. + /// Initializes a new instance of the class for mocking. protected SshPublicKeyOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a SshPublicKey. + internal SshPublicKeyOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected SshPublicKeyOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineContainer.cs index 0024cebdff1..79261338907 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachine and their operations over a ResourceGroup. - public partial class VirtualMachineContainer + public partial class VirtualMachineContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineContainer() { } - internal VirtualMachineContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineContainer class. + /// The resource representing the parent resource. + internal VirtualMachineContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachinesRestOperations _restClient => new VirtualMachinesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a VirtualMachine. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string vmName, VirtualMachineData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(vmName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachine. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string vmName, VirtualMachineData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(vmName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachine. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string vmName, VirtualMachineData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, vmName, parameters, cancellationToken: cancellationToken); + var operation = new VirtualMachinesCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachine(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachine. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string vmName, VirtualMachineData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, vmName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new VirtualMachinesCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachine(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the virtual machine. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string vmName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.Get"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, vmName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachine(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the virtual machine. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string vmName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.Get"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, vmName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachine(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachine(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachine(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachine(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachine(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachine for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachine for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionContainer.cs index 555487437f4..b3dd9c1316f 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionContainer.cs @@ -5,23 +5,309 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineExtension and their operations over a VirtualMachineScaleSet. - public partial class VirtualMachineExtensionContainer + public partial class VirtualMachineExtensionContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineExtensionContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionContainer() { } - internal VirtualMachineExtensionContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineExtensionContainer class. + /// The resource representing the parent resource. + internal VirtualMachineExtensionContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineScaleSetVMExtensionsRestOperations _restClient => new VirtualMachineScaleSetVMExtensionsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + protected override ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a VirtualMachineExtension. Please note some properties can be set only during creation. + /// The name of the virtual machine extension. + /// Parameters supplied to the Create Virtual Machine Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string vmExtensionName, VirtualMachineExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + return StartCreateOrUpdate(vmExtensionName, extensionParameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineExtension. Please note some properties can be set only during creation. + /// The name of the virtual machine extension. + /// Parameters supplied to the Create Virtual Machine Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string vmExtensionName, VirtualMachineExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var operation = await StartCreateOrUpdateAsync(vmExtensionName, extensionParameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineExtension. Please note some properties can be set only during creation. + /// The name of the virtual machine extension. + /// Parameters supplied to the Create Virtual Machine Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string vmExtensionName, VirtualMachineExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, extensionParameters, cancellationToken: cancellationToken); + var operation = new VirtualMachineScaleSetVMExtensionsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, extensionParameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineExtension(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineExtension. Please note some properties can be set only during creation. + /// The name of the virtual machine extension. + /// Parameters supplied to the Create Virtual Machine Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string vmExtensionName, VirtualMachineExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, extensionParameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new VirtualMachineScaleSetVMExtensionsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, extensionParameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineExtension(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the virtual machine extension. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string vmExtensionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.Get"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtension(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the virtual machine extension. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string vmExtensionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.Get"); + scope.Start(); + try + { + if (vmExtensionName == null) + { + throw new ArgumentNullException(nameof(vmExtensionName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, vmExtensionName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtension(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineExtension for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtension.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineExtension for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtension.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageContainer.cs index e147759debc..41532d4c33a 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineExtensionImage and their operations over a Parent. - public partial class VirtualMachineExtensionImageContainer + public partial class VirtualMachineExtensionImageContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineExtensionImageContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionImageContainer() { } - internal VirtualMachineExtensionImageContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineExtensionImageContainer class. + /// The resource representing the parent resource. + internal VirtualMachineExtensionImageContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineExtensionImagesRestOperations _restClient => new VirtualMachineExtensionImagesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => "Microsoft.Compute/locations/publishers"; + protected override ResourceType ValidResourceType => "Microsoft.Compute/locations/publishers"; + + // Container level operations. + + /// + /// The String to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = _restClient.Get(Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtensionImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The String to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = await _restClient.GetAsync(Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtensionImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineExtensionImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtensionImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineExtensionImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtensionImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageOperations.cs index 63f6c1dffa2..1c38fa380eb 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionImageOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineExtensionImage. public partial class VirtualMachineExtensionImageOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineExtensionImageOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionImageOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineExtensionImage. + internal VirtualMachineExtensionImageOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineExtensionImageOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionOperations.cs index ebb4614c7b7..78959c56ae5 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineExtensionOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineExtension. public partial class VirtualMachineExtensionOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineExtensionOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineExtension. + internal VirtualMachineExtensionOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineExtensionOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageContainer.cs index 088ccd75c1d..56803973367 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineImage and their operations over a Parent. - public partial class VirtualMachineImageContainer + public partial class VirtualMachineImageContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineImageContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineImageContainer() { } - internal VirtualMachineImageContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineImageContainer class. + /// The resource representing the parent resource. + internal VirtualMachineImageContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineImagesRestOperations _restClient => new VirtualMachineImagesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => "Microsoft.Compute/locations"; + protected override ResourceType ValidResourceType => "Microsoft.Compute/locations"; + + // Container level operations. + + /// + /// A valid image SKU version. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = _restClient.Get(Id.Parent.Parent.Parent.Parent.Name, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// A valid image SKU version. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = await _restClient.GetAsync(Id.Parent.Parent.Parent.Parent.Name, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineImageOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageOperations.cs index efbd2831940..94604270573 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineImageOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineImage. public partial class VirtualMachineImageOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineImageOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineImageOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineImage. + internal VirtualMachineImageOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineImageOperations(ResourceOperationsBase options, ResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineOperations.cs index bdabb51d067..ee49fe1d4d2 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachine. public partial class VirtualMachineOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachine. + internal VirtualMachineOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetContainer.cs index 1208838200c..89d1b989a3d 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineScaleSet and their operations over a ResourceGroup. - public partial class VirtualMachineScaleSetContainer + public partial class VirtualMachineScaleSetContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineScaleSetContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetContainer() { } - internal VirtualMachineScaleSetContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineScaleSetContainer class. + /// The resource representing the parent resource. + internal VirtualMachineScaleSetContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineScaleSetsRestOperations _restClient => new VirtualMachineScaleSetsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a VirtualMachineScaleSet. Please note some properties can be set only during creation. + /// The name of the VM scale set to create or update. + /// The scale set object. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string vmScaleSetName, VirtualMachineScaleSetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(vmScaleSetName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSet. Please note some properties can be set only during creation. + /// The name of the VM scale set to create or update. + /// The scale set object. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string vmScaleSetName, VirtualMachineScaleSetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(vmScaleSetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSet. Please note some properties can be set only during creation. + /// The name of the VM scale set to create or update. + /// The scale set object. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string vmScaleSetName, VirtualMachineScaleSetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, vmScaleSetName, parameters, cancellationToken: cancellationToken); + var operation = new VirtualMachineScaleSetsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmScaleSetName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSet(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSet. Please note some properties can be set only during creation. + /// The name of the VM scale set to create or update. + /// The scale set object. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string vmScaleSetName, VirtualMachineScaleSetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, vmScaleSetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new VirtualMachineScaleSetsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmScaleSetName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSet(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the VM scale set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string vmScaleSetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.Get"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, vmScaleSetName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the VM scale set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string vmScaleSetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.Get"); + scope.Start(); + try + { + if (vmScaleSetName == null) + { + throw new ArgumentNullException(nameof(vmScaleSetName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, vmScaleSetName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineScaleSetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineScaleSetOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineScaleSet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineScaleSet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionContainer.cs index bc0aeea7fd4..91edfe4b833 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineScaleSetExtension and their operations over a VirtualMachineScaleSet. - public partial class VirtualMachineScaleSetExtensionContainer + public partial class VirtualMachineScaleSetExtensionContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineScaleSetExtensionContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetExtensionContainer() { } - internal VirtualMachineScaleSetExtensionContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineScaleSetExtensionContainer class. + /// The resource representing the parent resource. + internal VirtualMachineScaleSetExtensionContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineScaleSetExtensionsRestOperations _restClient => new VirtualMachineScaleSetExtensionsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + protected override ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a VirtualMachineScaleSetExtension. Please note some properties can be set only during creation. + /// The name of the VM scale set extension. + /// Parameters supplied to the Create VM scale set Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string vmssExtensionName, VirtualMachineScaleSetExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + return StartCreateOrUpdate(vmssExtensionName, extensionParameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetExtension. Please note some properties can be set only during creation. + /// The name of the VM scale set extension. + /// Parameters supplied to the Create VM scale set Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string vmssExtensionName, VirtualMachineScaleSetExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var operation = await StartCreateOrUpdateAsync(vmssExtensionName, extensionParameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetExtension. Please note some properties can be set only during creation. + /// The name of the VM scale set extension. + /// Parameters supplied to the Create VM scale set Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string vmssExtensionName, VirtualMachineScaleSetExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, extensionParameters, cancellationToken: cancellationToken); + var operation = new VirtualMachineScaleSetExtensionsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, extensionParameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSetExtension(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetExtension. Please note some properties can be set only during creation. + /// The name of the VM scale set extension. + /// Parameters supplied to the Create VM scale set Extension operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string vmssExtensionName, VirtualMachineScaleSetExtensionData extensionParameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + if (extensionParameters == null) + { + throw new ArgumentNullException(nameof(extensionParameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, extensionParameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new VirtualMachineScaleSetExtensionsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, extensionParameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSetExtension(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the VM scale set extension. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string vmssExtensionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.Get"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSetExtension(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the VM scale set extension. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string vmssExtensionName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.Get"); + scope.Start(); + try + { + if (vmssExtensionName == null) + { + throw new ArgumentNullException(nameof(vmssExtensionName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, vmssExtensionName, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSetExtension(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetExtension(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetExtension(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineScaleSetExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetExtension(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetExtension(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineScaleSetExtensionOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineScaleSetExtension for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetExtensionOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineScaleSetExtension for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetExtensionContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetExtensionOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionOperations.cs index c2367211f91..8971ad559e1 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetExtensionOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineScaleSetExtension. public partial class VirtualMachineScaleSetExtensionOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineScaleSetExtensionOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetExtensionOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineScaleSetExtension. + internal VirtualMachineScaleSetExtensionOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineScaleSetExtensionOperations(ResourceOperationsBase options, ResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetOperations.cs index 88274bddb50..e1f0dea4eb8 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineScaleSet. public partial class VirtualMachineScaleSetOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineScaleSetOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineScaleSet. + internal VirtualMachineScaleSetOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineScaleSetOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgrade.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgrade.cs deleted file mode 100644 index 887295f6898..00000000000 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgrade.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Threading; -using System.Threading.Tasks; -using Azure.ResourceManager.Core; - -namespace Azure.ResourceManager.Sample -{ - /// A Class representing a VirtualMachineScaleSetRollingUpgrade along with the instance operations that can be performed on it. - public class VirtualMachineScaleSetRollingUpgrade : VirtualMachineScaleSetRollingUpgradeOperations - { - /// Initializes a new instance of the class. - /// The client parameters to use in these operations. - /// The resource that is the target of operations. - internal VirtualMachineScaleSetRollingUpgrade(ResourceOperationsBase options, VirtualMachineScaleSetRollingUpgradeData resource) : base(options, resource.Id) - { - Data = resource; - } - - /// Gets or sets the VirtualMachineScaleSetRollingUpgradeData. - public VirtualMachineScaleSetRollingUpgradeData Data { get; private set; } - - /// - protected override VirtualMachineScaleSetRollingUpgrade GetResource(CancellationToken cancellation = default) - { - return this; - } - - /// - protected override Task GetResourceAsync(CancellationToken cancellation = default) - { - return Task.FromResult(this); - } - } -} diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeContainer.cs deleted file mode 100644 index ccb5c66b8e8..00000000000 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeContainer.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using Azure.ResourceManager.Core; - -namespace Azure.ResourceManager.Sample -{ - /// A class representing collection of VirtualMachineScaleSetRollingUpgrade and their operations over a VirtualMachineScaleSet. - public partial class VirtualMachineScaleSetRollingUpgradeContainer - { - /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeContainer for mocking. - protected VirtualMachineScaleSetRollingUpgradeContainer() - { - } - - internal VirtualMachineScaleSetRollingUpgradeContainer(ResourceOperationsBase parent) - { - } - - /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; - } -} diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeOperations.cs deleted file mode 100644 index da5e8a1e36b..00000000000 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradeOperations.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Azure; -using Azure.ResourceManager.Core; - -namespace Azure.ResourceManager.Sample -{ - /// A class representing the operations that can be performed over a specific VirtualMachineScaleSetRollingUpgrade. - public partial class VirtualMachineScaleSetRollingUpgradeOperations : ResourceOperationsBase - { - /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeOperations for mocking. - protected VirtualMachineScaleSetRollingUpgradeOperations() - { - } - - /// Initializes a new instance of class. - /// The client parameters to use in these operations. - /// The identifier of the resource that is the target of operations. - protected VirtualMachineScaleSetRollingUpgradeOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) - { - } - - public static readonly ResourceType ResourceType = "Microsoft.Compute/virtualMachineScaleSets/rollingUpgrades"; - protected override ResourceType ValidResourceType => ResourceType; - - /// - public override Response Get(CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - /// - public override Task> GetAsync(CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - - /// Lists all available geo-locations. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// A collection of location that may take multiple service requests to iterate over. - public IEnumerable ListAvailableLocations(CancellationToken cancellationToken = default) - { - return ListAvailableLocations(ResourceType); - } - - /// Lists all available geo-locations. - /// A token to allow the caller to cancel the call to the service. The default value is . - /// An async collection of location that may take multiple service requests to iterate over. - /// The default subscription id is null. - public async Task> ListAvailableLocationsAsync(CancellationToken cancellationToken = default) - { - return await ListAvailableLocationsAsync(ResourceType, cancellationToken); - } - } -} diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradesRestOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradesRestOperations.cs index afa7971d840..218b3e2ca69 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradesRestOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetRollingUpgradesRestOperations.cs @@ -299,7 +299,7 @@ internal HttpMessage CreateGetLatestRequest(string resourceGroupName, string vmS /// The name of the VM scale set. /// The cancellation token to use. /// or is null. - public async Task> GetLatestAsync(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationToken = default) + public async Task> GetLatestAsync(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { @@ -316,9 +316,9 @@ public async Task> GetLatestA { case 200: { - VirtualMachineScaleSetRollingUpgradeData value = default; + VirtualMachineScaleSetRollingUpgrade value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = VirtualMachineScaleSetRollingUpgradeData.DeserializeVirtualMachineScaleSetRollingUpgradeData(document.RootElement); + value = VirtualMachineScaleSetRollingUpgrade.DeserializeVirtualMachineScaleSetRollingUpgrade(document.RootElement); return Response.FromValue(value, message.Response); } default: @@ -331,7 +331,7 @@ public async Task> GetLatestA /// The name of the VM scale set. /// The cancellation token to use. /// or is null. - public Response GetLatest(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationToken = default) + public Response GetLatest(string resourceGroupName, string vmScaleSetName, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { @@ -348,9 +348,9 @@ public Response GetLatest(string resou { case 200: { - VirtualMachineScaleSetRollingUpgradeData value = default; + VirtualMachineScaleSetRollingUpgrade value = default; using var document = JsonDocument.Parse(message.Response.ContentStream); - value = VirtualMachineScaleSetRollingUpgradeData.DeserializeVirtualMachineScaleSetRollingUpgradeData(document.RootElement); + value = VirtualMachineScaleSetRollingUpgrade.DeserializeVirtualMachineScaleSetRollingUpgrade(document.RootElement); return Response.FromValue(value, message.Response); } default: diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMContainer.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMContainer.cs index 875c2c36b44..1128bf298cb 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMContainer.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace Azure.ResourceManager.Sample { /// A class representing collection of VirtualMachineScaleSetVM and their operations over a VirtualMachineScaleSet. - public partial class VirtualMachineScaleSetVMContainer + public partial class VirtualMachineScaleSetVMContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineScaleSetVMContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetVMContainer() { } - internal VirtualMachineScaleSetVMContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineScaleSetVMContainer class. + /// The resource representing the parent resource. + internal VirtualMachineScaleSetVMContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineScaleSetVMsRestOperations _restClient => new VirtualMachineScaleSetVMsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + protected override ResourceType ValidResourceType => VirtualMachineScaleSetOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a VirtualMachineScaleSetVM. Please note some properties can be set only during creation. + /// The instance ID of the virtual machine. + /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string instanceId, VirtualMachineScaleSetVMData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(instanceId, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetVM. Please note some properties can be set only during creation. + /// The instance ID of the virtual machine. + /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string instanceId, VirtualMachineScaleSetVMData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(instanceId, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetVM. Please note some properties can be set only during creation. + /// The instance ID of the virtual machine. + /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string instanceId, VirtualMachineScaleSetVMData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Update(Id.ResourceGroupName, Id.Parent.Name, instanceId, parameters, cancellationToken: cancellationToken); + var operation = new VirtualMachineScaleSetVMsUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, instanceId, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSetVM(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a VirtualMachineScaleSetVM. Please note some properties can be set only during creation. + /// The instance ID of the virtual machine. + /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string instanceId, VirtualMachineScaleSetVMData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.UpdateAsync(Id.ResourceGroupName, Id.Parent.Name, instanceId, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new VirtualMachineScaleSetVMsUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, instanceId, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new VirtualMachineScaleSetVM(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The instance ID of the virtual machine. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string instanceId, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.Get"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, instanceId, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSetVM(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The instance ID of the virtual machine. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string instanceId, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.Get"); + scope.Start(); + try + { + if (instanceId == null) + { + throw new ArgumentNullException(nameof(instanceId)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, instanceId, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineScaleSetVM(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetVM(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetVM(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineScaleSetVMOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetVM(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new VirtualMachineScaleSetVM(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineScaleSetVMOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineScaleSetVM for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetVMOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineScaleSetVM for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineScaleSetVMContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineScaleSetVMOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMOperations.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMOperations.cs index 989c38cc424..d7c36a71d43 100644 --- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMOperations.cs +++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVMOperations.cs @@ -17,12 +17,18 @@ namespace Azure.ResourceManager.Sample /// A class representing the operations that can be performed over a specific VirtualMachineScaleSetVM. public partial class VirtualMachineScaleSetVMOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineScaleSetVMOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineScaleSetVMOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineScaleSetVM. + internal VirtualMachineScaleSetVMOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineScaleSetVMOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/samples/Azure.ResourceManager.Sample/readme.md b/samples/Azure.ResourceManager.Sample/readme.md index 2a93de4d1bb..88e29eeebbc 100644 --- a/samples/Azure.ResourceManager.Sample/readme.md +++ b/samples/Azure.ResourceManager.Sample/readme.md @@ -25,7 +25,7 @@ operation-group-to-resource: VirtualMachineImages: VirtualMachineImage Usage: NonResource VirtualMachineSizes: NonResource - VirtualMachineScaleSetRollingUpgrades: VirtualMachineScaleSetRollingUpgrade + VirtualMachineScaleSetRollingUpgrades: NonResource LogAnalytics: NonResource operation-group-to-parent: LogAnalytics: subscriptions diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/DocumentationWriterExtensions.cs b/src/AutoRest.CSharp/Common/Generation/Writers/DocumentationWriterExtensions.cs index 5a766cc1dc1..247e462324b 100644 --- a/src/AutoRest.CSharp/Common/Generation/Writers/DocumentationWriterExtensions.cs +++ b/src/AutoRest.CSharp/Common/Generation/Writers/DocumentationWriterExtensions.cs @@ -41,6 +41,17 @@ public static CodeWriter WriteXmlDocumentationParameter(this CodeWriter writer, return writer.WriteDocumentationLines($"", "", text, skipWhenEmpty: false); } + /// + /// Writes XML documentation for a parameter of a method using a "param" tag. + /// + /// Writer to which code is written to. + /// The definition of the parameter, including name and description. + /// + public static CodeWriter WriteXmlDocumentationParameter(this CodeWriter writer, Parameter parameter) + { + return writer.WriteXmlDocumentationParameter(parameter.Name, parameter.Description); + } + public static CodeWriter WriteXmlDocumentationException(this CodeWriter writer, Type exception, string? description) { return writer.WriteDocumentationLines($"", "", description, skipWhenEmpty: false); diff --git a/src/AutoRest.CSharp/Common/Output/Models/Requests/RestClientMethod.cs b/src/AutoRest.CSharp/Common/Output/Models/Requests/RestClientMethod.cs index 04a91925c5b..82d4169ca52 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Requests/RestClientMethod.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Requests/RestClientMethod.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using AutoRest.CSharp.Generation.Types; +using AutoRest.CSharp.Input; using AutoRest.CSharp.Output.Models.Responses; using AutoRest.CSharp.Output.Models.Shared; @@ -9,7 +10,7 @@ namespace AutoRest.CSharp.Output.Models.Requests { internal class RestClientMethod { - public RestClientMethod(string name, string? description, CSharpType? returnType, Request request, Parameter[] parameters, Response[] responses, DataPlaneResponseHeaderGroupType? headerModel, bool bufferResponse, string accessibility) + public RestClientMethod(string name, string? description, CSharpType? returnType, Request request, Parameter[] parameters, Response[] responses, DataPlaneResponseHeaderGroupType? headerModel, bool bufferResponse, string accessibility, Operation? operation = null) { Name = name; Request = request; @@ -20,6 +21,7 @@ public RestClientMethod(string name, string? description, CSharpType? returnType HeaderModel = headerModel; BufferResponse = bufferResponse; Accessibility = accessibility; + Operation = operation; } public string Name { get; } @@ -31,5 +33,6 @@ public RestClientMethod(string name, string? description, CSharpType? returnType public bool BufferResponse { get; } public CSharpType? ReturnType { get; } public string Accessibility { get; } + public Operation? Operation { get; } } } diff --git a/src/AutoRest.CSharp/Common/Output/Models/RestClient.cs b/src/AutoRest.CSharp/Common/Output/Models/RestClient.cs index b356f0b4b36..f766dfccd60 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/RestClient.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/RestClient.cs @@ -173,7 +173,8 @@ protected static RestClientMethod BuildNextPageMethod(RestClientMethod method, O responses, method.HeaderModel, bufferResponse: true, - accessibility: "internal"); + accessibility: "internal", + operation); } public virtual RestClientMethod? GetNextOperationMethod(ServiceRequest request) diff --git a/src/AutoRest.CSharp/Common/Output/Models/RestClientBuilder.cs b/src/AutoRest.CSharp/Common/Output/Models/RestClientBuilder.cs index 6c05f520a68..7e14fde6d79 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/RestClientBuilder.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/RestClientBuilder.cs @@ -89,7 +89,8 @@ public RestClientMethod BuildMethod(Operation operation, HttpRequest httpRequest responses, responseHeaderModel, operation.Extensions?.BufferResponse ?? true, - accessibility: accessibility + accessibility: accessibility, + operation ); } diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs index a96c30aa5e5..299307315a3 100644 --- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs +++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs @@ -96,8 +96,21 @@ public MgmtOutputLibrary(CodeModel codeModel, BuildContext co } public ResourceData GetResourceData(OperationGroup operationGroup) => EnsureResourceData()[operationGroup]; + + /// + /// Looks up a object by . + /// + /// OperationGroup object. + /// The object associated with the operation group. public Resource GetArmResource(OperationGroup operationGroup) => EnsureArmResource()[operationGroup]; + /// + /// Looks up a object by . + /// + /// OperationGroup object. + /// The object associated with the operation group. + public MgmtRestClient GetRestClient(OperationGroup operationGroup) => EnsureRestClients()[operationGroup]; + public OperationGroup? GetOperationGroupBySchema(Schema schema) { List? operationGroups; @@ -106,6 +119,10 @@ public MgmtOutputLibrary(CodeModel codeModel, BuildContext co return null; } + internal LongRunningOperation GetLongRunningOperation(Operation op) => EnsureLongRunningOperations()[op]; + + internal NonLongRunningOperation GetNonLongRunningOperation(Operation op) => EnsureNonLongRunningOperations()[op]; + internal MgmtObjectType? GetMgmtObjectFromModelName(string name) { TypeProvider? provider = _nameToTypeProvider[name]; @@ -309,7 +326,7 @@ public override CSharpType FindTypeForSchema(Schema schema) public LongRunningOperationInfo FindLongRunningOperationInfo(OperationGroup operationGroup, Operation operation) { - var mgmtRestClient = FindRestClient(operationGroup); + var mgmtRestClient = GetRestClient(operationGroup); Debug.Assert(mgmtRestClient != null, "Unexpected. Unable find matching rest client."); @@ -370,11 +387,6 @@ private Dictionary BuildResourceModels() _ => throw new NotImplementedException() }; - public MgmtRestClient FindRestClient(OperationGroup operationGroup) - { - return EnsureRestClients()[operationGroup]; - } - private void DecorateOperationGroup() { foreach (var operationsGroup in _codeModel.OperationGroups) diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs index ed9f5cdc6a7..57a77959f6e 100644 --- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs +++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs @@ -21,7 +21,6 @@ public static void Execute(GeneratedCodeWorkspace project, CodeModel codeModel, var restClientWriter = new RestClientWriter(); var serializeWriter = new SerializationWriter(); var resourceOperationWriter = new ResourceOperationWriter(); - var resourceContainerWriter = new ResourceContainerWriter(); var armResourceWriter = new ResourceWriter(); var resourceGroupExtensionsWriter = new ResourceGroupExtensionsWriter(); var subscriptionExtensionsWriter = new SubscriptionExtensionsWriter(); @@ -58,7 +57,7 @@ public static void Execute(GeneratedCodeWorkspace project, CodeModel codeModel, foreach (var resourceContainer in context.Library.ResourceContainers) { var codeWriter = new CodeWriter(); - resourceContainerWriter.WriteContainer(codeWriter, resourceContainer); + new ResourceContainerWriter(codeWriter, resourceContainer, context.Library).WriteContainer(); project.AddGeneratedFile($"{resourceContainer.Type.Name}.cs", codeWriter.ToString()); } diff --git a/src/AutoRest.CSharp/Mgmt/Decorator/InheritanceChooser.cs b/src/AutoRest.CSharp/Mgmt/Decorator/InheritanceChooser.cs index 4ef362c715a..c204b6ccb31 100644 --- a/src/AutoRest.CSharp/Mgmt/Decorator/InheritanceChooser.cs +++ b/src/AutoRest.CSharp/Mgmt/Decorator/InheritanceChooser.cs @@ -8,6 +8,7 @@ using AutoRest.CSharp.AutoRest.Plugins; using AutoRest.CSharp.Generation.Types; using AutoRest.CSharp.Input; +using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.Mgmt.Generation; using AutoRest.CSharp.Mgmt.Output; using AutoRest.CSharp.Output.Models.Types; @@ -178,6 +179,14 @@ private static bool DoesPropertyExistInParent(ObjectTypeProperty childProperty, return true; } + /// + /// Tells if can be assigned to + /// by checking if there's an implicit type convertor in . + /// Todo: should we check childPropertyType as well since an implicit can be defined in either classes? + /// + /// The type to be assigned to. + /// The type to assign. + /// private static bool IsAssignable(System.Type parentPropertyType, CSharpType childPropertyType) { return parentPropertyType.GetMethods().Where(m => m.Name == "op_Implicit" && diff --git a/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs b/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs index 05f4e592391..dddd49f07a1 100644 --- a/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs +++ b/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs @@ -38,7 +38,7 @@ private static string ConstructOperationResourceType(OperationGroup operationsGr var method = GetBestMethod(operationsGroup); if (method == null) { - throw new ArgumentException($@"Could not set ResourceType for operations group {operationsGroup.Key} + throw new ArgumentException($@"Could not set ResourceType for operations group {operationsGroup.Key} Please try setting this value for this operations in the readme.md for this swagger in the operation-group-mapping section"); } var indexOfProvider = method.Path.IndexOf(ProviderSegment.Providers); diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ResourceContainerWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ResourceContainerWriter.cs index a9422d0b9a8..7d3c341d0aa 100644 --- a/src/AutoRest.CSharp/Mgmt/Generation/ResourceContainerWriter.cs +++ b/src/AutoRest.CSharp/Mgmt/Generation/ResourceContainerWriter.cs @@ -1,54 +1,418 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using AutoRest.CSharp.Output.Models.Requests; +using AutoRest.CSharp.Output.Models.Shared; +using Azure.Core; using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Input; -using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.Output.Models.Types; +using Azure.ResourceManager.Core.Resources; +using Azure; using Azure.ResourceManager.Core; -using AutoRest.CSharp.Mgmt.Decorator; +using Azure.Core.Pipeline; +using System.Threading.Tasks; +using AutoRest.CSharp.Common.Generation.Writers; +using AutoRest.CSharp.Output.Models.Types; +using AutoRest.CSharp.Generation.Types; +using AutoRest.CSharp.Mgmt.AutoRest; +using System.Diagnostics; namespace AutoRest.CSharp.Mgmt.Generation { - internal class ResourceContainerWriter + /// + /// Code writer for resource container. + /// A resource container should have 3 operations: + /// 1. CreateOrUpdate (4 variants) + /// 2. Get (2 variants) + /// 3. List (4 variants) + /// and the following builder methods: + /// 1. Construct + /// + internal class ResourceContainerWriter : ClientWriter { - private const string ClientDiagnosticsVariable = "clientDiagnostics"; - private const string PipelineVariable = "pipeline"; + private const string ClientDiagnosticsField = "_clientDiagnostics"; + private const string PipelineField = "_pipeline"; + private const string RestClientField = "_restClient"; + private CodeWriter _writer; + private ResourceContainer _resourceContainer; + private ResourceData _resourceData; + private MgmtRestClient _restClient; + private Resource _resource; + private ResourceOperation _resourceOperation; + private MgmtOutputLibrary _library; - public void WriteContainer(CodeWriter writer, ResourceContainer resourceContainer) + public ResourceContainerWriter(CodeWriter writer, ResourceContainer resourceContainer, MgmtOutputLibrary library) { - var cs = resourceContainer.Type; + _writer = writer; + _resourceContainer = resourceContainer; + var operationGroup = resourceContainer.OperationGroup; + _resourceData = library.GetResourceData(operationGroup); + _restClient = library.GetRestClient(operationGroup); + _resource = library.GetArmResource(operationGroup); + _resourceOperation = library.GetResourceOperation(operationGroup); + _library = library; + } + + public void WriteContainer() + { + _writer.UseNamespace(typeof(Task).Namespace!); // Explicitly adding `System.Threading.Tasks` because + // at build time I don't have the type information inside Task<> + + var cs = _resourceContainer.Type; var @namespace = cs.Namespace; - using (writer.Namespace(@namespace)) + using (_writer.Namespace(@namespace)) { - writer.WriteXmlDocumentationSummary(resourceContainer.Description); - using (writer.Scope($"{resourceContainer.Declaration.Accessibility} partial class {cs.Name}")) + _writer.WriteXmlDocumentationSummary(_resourceContainer.Description); + string baseClass = FindRestClientMethodByPrefix("Get", out _) + ? $"ResourceContainerBase<{_resourceContainer.ResourceIdentifierType}, {_resource.Type.Name}, {_resourceData.Type.Name}>" + : $"ContainerBase<{_resourceContainer.ResourceIdentifierType}>"; + using (_writer.Scope($"{_resourceContainer.Declaration.Accessibility} partial class {cs.Name:D} : {baseClass}")) { - WriteContainerCtors(writer, resourceContainer); + WriteContainerCtors(); + WriteFields(); + WriteIdProperty(); + WriteContainerProperties(); + WriteResourceOperations(); + WriteBuilders(); + } + } + } + + private void WriteContainerCtors() + { + string typeOfThis = _resourceContainer.Type.Name; + + // write protected default constructor + _writer.WriteXmlDocumentationSummary($"Initializes a new instance of the class for mocking."); + using (_writer.Scope($"protected {typeOfThis}()")) + { } + + // write "parent resource" constructor + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Initializes a new instance of {typeOfThis} class."); + var parent = "parent"; + _writer.WriteXmlDocumentationParameter(parent, "The resource representing the parent resource."); + using (_writer.Scope($"internal {typeOfThis}({typeof(ResourceOperationsBase)} {parent}) : base({parent})")) + { + _writer.Line($"{ClientDiagnosticsField} = new {typeof(ClientDiagnostics)}(ClientOptions);"); + // todo: after a shared pipeline field is implemented in the base class, replace this with that + _writer.Line($"{PipelineField} = {typeof(ManagementPipelineBuilder)}.Build(Credential, BaseUri, ClientOptions);"); + } + } + + private void WriteFields() + { + _writer.Line(); + _writer.Line($"private readonly {typeof(ClientDiagnostics)} {ClientDiagnosticsField};"); + _writer.Line($"private readonly {typeof(HttpPipeline)} {PipelineField};"); + + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Represents the REST operations."); + // subscriptionId might not always be needed. For example `RestOperations` does not have it. + var subIdIfNeeded = _restClient.Parameters.FirstOrDefault()?.Name == "subscriptionId" ? ", Id.SubscriptionId" : ""; + _writer.Line($"private {_restClient.Type} {RestClientField} => new {_restClient.Type}({ClientDiagnosticsField}, {PipelineField}{subIdIfNeeded});"); + } + + private void WriteIdProperty() + { + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Typed Resource Identifier for the container."); + _writer.Line($"public new {typeof(ResourceGroupResourceIdentifier)} Id => base.Id as {typeof(ResourceGroupResourceIdentifier)};"); + } + + private void WriteResourceOperations() + { + _writer.Line(); + _writer.LineRaw($"// Container level operations."); + + // To generate resource operations, we need to find out the correct REST client methods to call. + // We must look for CreateOrUpdate by HTTP method because it may be named differently from `CreateOrUpdate`. + if (FindRestClientMethodByHttpMethod(RequestMethod.Put, out var restClientMethod)) + { + WriteCreateOrUpdateVariants(restClientMethod); + } + + // We must look for Get by method name because HTTP GET may map to >1 methods (get/list) + if (FindRestClientMethodByPrefix("Get", out restClientMethod)) + { + WriteGetVariants(restClientMethod); + } + + WriteListVariants(); + } + + private bool FindRestClientMethodByHttpMethod(RequestMethod httpMethod, out RestClientMethod restMethod) + { + restMethod = _restClient.Methods.FirstOrDefault(m => m.Request.HttpMethod.Equals(httpMethod)); + return restMethod != null; + } + + private bool FindRestClientMethodByPrefix(string prefix, out RestClientMethod restMethod) + { + restMethod = _restClient.Methods.FirstOrDefault(method => method.Name.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)); + return restMethod != null; + } + + private void WriteCreateOrUpdateVariants(RestClientMethod restClientMethod) + { + Debug.Assert(restClientMethod.Operation != null); + var parameterMapping = BuildParameterMapping(restClientMethod); + IEnumerable passThruParameters = parameterMapping.Where(p => p.IsPassThru).Select(p => p.Parameter); - WriteContainerProperties(writer, resourceContainer); + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"The operation to create or update a {_resource.Type.Name}. Please note some properties can be set only during creation."); + WriteContainerMethodScope(false, $"{typeof(Response)}<{_resource.Type.Name}>", "CreateOrUpdate", passThruParameters, writer => + { + _writer.Append($"return StartCreateOrUpdate("); + foreach (var parameter in passThruParameters) + { + _writer.AppendRaw($"{parameter.Name}, "); + } + _writer.Line($"cancellationToken: cancellationToken).WaitForCompletion() as {typeof(Response)}<{_resource.Type}>;"); + }); + + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"The operation to create or update a {_resource.Type.Name}. Please note some properties can be set only during creation."); + WriteContainerMethodScope(true, $"{typeof(Task)}<{typeof(Response)}<{_resource.Type.Name}>>", "CreateOrUpdate", passThruParameters, writer => + { + _writer.Append($"var operation = await StartCreateOrUpdateAsync("); + foreach (var parameter in passThruParameters) + { + _writer.AppendRaw($"{parameter.Name}, "); + } + _writer.Line($"cancellationToken: cancellationToken).ConfigureAwait(false);"); + _writer.Line($"return await operation.WaitForCompletionAsync() as {typeof(Response)}<{_resource.Type}>;"); + }); + + var isLongRunning = restClientMethod.Operation.IsLongRunning; + CSharpType lroObjectType = isLongRunning + ? _library.GetLongRunningOperation(restClientMethod.Operation).Type + : _library.GetNonLongRunningOperation(restClientMethod.Operation).Type; + + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"The operation to create or update a {_resource.Type.Name}. Please note some properties can be set only during creation."); + WriteContainerMethodScope(false, $"Operation<{_resource.Type.Name}>", "StartCreateOrUpdate", passThruParameters, writer => + { + _writer.Append($"var originalResponse = {RestClientField}.{restClientMethod.Name}("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.Line($"cancellationToken: cancellationToken);"); + if (isLongRunning) + { + _writer.Line($"var operation = new {lroObjectType}("); + _writer.Line($"{ClientDiagnosticsField}, {PipelineField}, {RestClientField}.Create{restClientMethod.Name}Request("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.RemoveTrailingComma(); + _writer.Line($").Request,"); + _writer.Line($"originalResponse);"); + _writer.Line($"return new PhArmOperation<{_resource.Type}, {_resourceData.Type}>("); + _writer.Line($"operation,"); + _writer.Line($"data => new {_resource.Type}(Parent, data));"); + } + else + { + _writer.Append($"return new {lroObjectType}("); + _writer.Append($"Parent,"); + _writer.Line($"originalResponse);"); + } + }); + + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"The operation to create or update a {_resource.Type.Name}. Please note some properties can be set only during creation."); + WriteContainerMethodScope(true, $"{typeof(Task)}>", "StartCreateOrUpdate", passThruParameters, writer => + { + _writer.Append($"var originalResponse = await {RestClientField}.{restClientMethod.Name}Async("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.Line($"cancellationToken: cancellationToken).ConfigureAwait(false);"); + if (isLongRunning) + { + _writer.Line($"var operation = new {lroObjectType}("); + _writer.Line($"{ClientDiagnosticsField}, {PipelineField}, {RestClientField}.Create{restClientMethod.Name}Request("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.RemoveTrailingComma(); + _writer.Line($").Request,"); + _writer.Line($"originalResponse);"); + _writer.Line($"return new PhArmOperation<{_resource.Type}, {_resourceData.Type}>("); + _writer.Line($"operation,"); + _writer.Line($"data => new {_resource.Type}(Parent, data));"); } + else + { + _writer.Append($"return new {lroObjectType}("); + _writer.Append($"Parent,"); + _writer.Line($"originalResponse);"); + } + }); + } + + /// + /// Write some scaffolding for container operation methods. + /// + /// + /// Must be string. + /// Method name in its sync form. + /// Must not contain cancellationToken. + /// Main logic of the method writer. + /// + private void WriteContainerMethodScope(bool isAsync, FormattableString returnType, string syncMethodName, IEnumerable parameters, CodeWriterDelegate inner, bool isOverride = false) + { + if (isOverride) + { + _writer.WriteXmlDocumentationInheritDoc(); } + foreach (var parameter in parameters) + { + _writer.WriteXmlDocumentationParameter(parameter); + } + + const string cancellationTokenParameter = "cancellationToken"; + _writer.WriteXmlDocumentationParameter(cancellationTokenParameter, @"A token to allow the caller to cancel the call to the service. The default value is ."); + + _writer.Append($"public {(isAsync ? "async " : string.Empty)}{(isOverride ? "override " : string.Empty)}{returnType} {CreateMethodName(syncMethodName, isAsync)}("); + foreach (var parameter in parameters) + { + _writer.WriteParameter(parameter); + } + _writer.Append($"{typeof(CancellationToken)} {cancellationTokenParameter} = default)"); + using var _ = _writer.Scope(); + WriteDiagnosticScope(_writer, new Diagnostic($"{_resourceContainer.Type.Name}.{syncMethodName}"), ClientDiagnosticsField, writer => + { + _writer.WriteParameterNullChecks(parameters.ToList()); + inner(_writer); + }); } - private void WriteContainerCtors(CodeWriter writer, ResourceContainer resourceContainer) + /// + /// Builds the mapping between resource operations in Container class and that in RestOperations class. + /// For example `DedicatedHostRestClient.CreateOrUpdate()` + /// | resourceGroupName | hostGroupName | hostName | parameters | + /// | ---------------------- | ---------------- | -------- | ---------- | + /// | "Id.ResourceGroupName" | "Id.Parent.Name" | hostName | parameters | + /// + /// Represents a method in RestOperations class. + private IEnumerable BuildParameterMapping(RestClientMethod method) { - writer.WriteXmlDocumentationSummary($"Initializes a new instance of {resourceContainer.Type.Name} for mocking."); - using (writer.Scope($"protected {resourceContainer.Type.Name:D}()")) + var parameterMapping = new List(); + var dotParent = ".Parent"; + var parentNameStack = new Stack(); + + // loop through parameters of REST client method, map the leading string-like parameters to + // Id.ResourceGroupName, Id.ResourceGroupName.Parent.Name, Id.ResourceGroupName.Parent.Parent.Name... + // special case: type is enum and you can convert string to it (model-as-string), we should handle it as string + // special case 2: in paging scenarios, `nextLink` needs to be handled specially, so here we just ignore it + foreach (var parameter in method.Parameters) + { + bool passThru = true; + string valueExpression = string.Empty; + if (string.Equals(parameter.Name, "nextLink", StringComparison.InvariantCultureIgnoreCase)) + { + continue; + } + else if (IsStringLike(parameter.Type) && IsMandatory(parameter)) + { + passThru = false; + if (string.Equals(parameter.Name, "resourceGroupName", StringComparison.InvariantCultureIgnoreCase)) + { + valueExpression = "Id.ResourceGroupName"; + } + else + { + parentNameStack.Push($"Id{dotParent}.Name"); + dotParent += ".Parent"; + } + } + else + { + passThru = true; + } + parameterMapping.Add(new ParameterMapping(parameter, passThru, valueExpression)); + } + + // if the method needs resource name (typically all non-list methods), we should make it pass-thru + // 1. make last string-like parameter (typically the resource name) pass-through from container method + // 2. ignoring optional parameters such as `expand` + if (!method.Name.StartsWith("List", StringComparison.InvariantCultureIgnoreCase)) { + var lastString = parameterMapping.LastOrDefault(parameter => IsStringLike(parameter.Parameter.Type) && IsMandatory(parameter.Parameter)); + if (lastString.Parameter != null && !lastString.Parameter.Name.Equals("resourceGroupName", StringComparison.InvariantCultureIgnoreCase)) + { + lastString.IsPassThru = true; + parentNameStack.Pop(); + } } - writer.Line(); - using (writer.Scope($"internal {resourceContainer.Type.Name}({typeof(ResourceOperationsBase)} parent)")) + // set the arguments for name parameters reversely: Id.Parent.Name, Id.Parent.Parent.Name, ... + foreach (var parameter in parameterMapping) + { + if (IsMandatory(parameter.Parameter) && !parameter.IsPassThru && string.IsNullOrEmpty(parameter.ValueExpression)) + { + parameter.ValueExpression = parentNameStack.Pop(); + } + } + + return parameterMapping; + } + + private bool IsMandatory(Parameter parameter) => parameter.DefaultValue is null; + + /// + /// Represents how a parameter of rest operation is mapped to a parameter of a container method or an expression. + /// + private class ParameterMapping + { + /// + /// The parameter object in . + /// + public Parameter Parameter; + /// + /// Should the parameter be passed through from the method in container class? + /// + public bool IsPassThru; + /// + /// if not pass-through, this is the value to pass in . + /// + public string ValueExpression; + + public ParameterMapping(Parameter parameter, bool isPassThru, string valueExpression) { + Parameter = parameter; + IsPassThru = isPassThru; + ValueExpression = valueExpression; } - writer.Line(); } - private void WriteContainerProperties(CodeWriter writer, ResourceContainer resourceContainer) + /// + /// Is the input type string or an Enum that is modeled as string. + /// + /// Type to check. + /// Is the input type string or an Enum that is modeled as string. + private bool IsStringLike(CSharp.Generation.Types.CSharpType type) + { + return type.Equals(typeof(string)) || type.Implementation is EnumType enumType && enumType.BaseType.Equals(typeof(string)); + } + + private void WriteContainerProperties() { - var resourceType = resourceContainer.GetValidResourceValue(); + var resourceType = _resourceContainer.GetValidResourceValue(); // TODO: Remove this if condition after https://dev.azure.com/azure-mgmt-ex/DotNET%20Management%20SDK/_workitems/edit/5800 if (!resourceType.Contains(".ResourceType")) @@ -56,8 +420,236 @@ private void WriteContainerProperties(CodeWriter writer, ResourceContainer resou resourceType = $"\"{resourceType}\""; } - writer.WriteXmlDocumentationSummary($"Gets the valid resource type for this object"); - writer.Line($"protected {typeof(ResourceType)} ValidResourceType => {resourceType};"); + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Gets the valid resource type for this object"); + _writer.Line($"protected override {typeof(ResourceType)} ValidResourceType => {resourceType};"); + } + + private void WriteGetVariants(RestClientMethod method) + { + var parameterMapping = BuildParameterMapping(method); + // some Get() contains extra non-name parameters which if added to method signature, + // would break the inheritance to ResourceContainerBase + // e.g. `expand` when getting image in compute RP + parameterMapping = parameterMapping.Where(mapping => IsMandatory(mapping.Parameter)); + + var methodName = "Get"; + var scopeName = methodName; + + IEnumerable passThruParameters = parameterMapping.Where(p => p.IsPassThru).Select(parameter => + { + if (IsStringLike(parameter.Parameter.Type)) + { + // for string-like parameters, we shall write them as string as base class + return new Parameter( + parameter.Parameter.Name, + parameter.Parameter.Description, + new CSharp.Generation.Types.CSharpType(typeof(string)), + parameter.Parameter.DefaultValue, + parameter.Parameter.ValidateNotNull, + parameter.Parameter.IsApiVersionParameter + ); + } + else + { + return parameter.Parameter; + } + }); + + _writer.Line(); + WriteContainerMethodScope(false, $"{typeof(Response)}<{_resource.Type.Name}>", "Get", passThruParameters, writer => + { + _writer.Append($"var response = {RestClientField}.{method.Name}("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.Line($"cancellationToken: cancellationToken);"); + _writer.Line($"return {typeof(Response)}.FromValue(new {_resource.Type}(Parent, response.Value), response.GetRawResponse());"); + }, isOverride: true); + + _writer.Line(); + WriteContainerMethodScope(true, $"{typeof(Task)}<{typeof(Response)}<{_resource.Type.Name}>>", "Get", passThruParameters, writer => + { + _writer.Append($"var response = await {RestClientField}.{method.Name}Async("); + foreach (var parameter in parameterMapping) + { + _writer.AppendRaw(parameter.IsPassThru ? parameter.Parameter.Name : parameter.ValueExpression); + _writer.AppendRaw(", "); + } + _writer.Line($"cancellationToken: cancellationToken);"); + _writer.Line($"return {typeof(Response)}.FromValue(new {_resource.Type}(Parent, response.Value), response.GetRawResponse());"); + }, isOverride: true); + } + + private void WriteListVariants() + { + WriteList(async: false); + WriteList(async: true); + WriteListAsGenericResource(async: false); + WriteListAsGenericResource(async: true); + } + + private void WriteList(bool async) + { + // if we find a proper *list* method that supports *paging*, + // we should generate paging logic (PageableHelpers.CreateEnumerable) + // else we just call ListAsGenericResource to get the list then call Get on every resource + PagingMethod list = FindListPagingMethod(); + + var methodName = CreateMethodName("List", async); + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Filters the list of for this resource group."); + _writer.WriteXmlDocumentationParameter("top", "The number of results to return."); + _writer.WriteXmlDocumentationParameter("cancellationToken", "A token to allow the caller to cancel the call to the service. The default value is ."); + string returnText = $"{(async ? "An async" : "A")} collection of that may take multiple service requests to iterate over."; + _writer.WriteXmlDocumentation("returns", returnText); + var returnType = async + ? new CSharpType(typeof(AsyncPageable<>), _resource.Type) + : new CSharpType(typeof(Pageable<>), _resource.Type); + var asyncText = async ? "Async" : string.Empty; + using (_writer.Scope($"public {returnType} {methodName}(int? top = null, {typeof(CancellationToken)} cancellationToken = default)")) + { + if (list != null) + { + WriteContainerPagingOperation(list, async); + } + else + { + _writer.Line($"var results = ListAsGenericResource{asyncText}(null, top, cancellationToken);"); + _writer.Line($"return new PhWrapping{asyncText}Pageable(results, genericResource => new {_resourceOperation.Type}(genericResource).Get().Value);"); + } + } + + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group."); + _writer.WriteXmlDocumentationParameter("nameFilter", "The filter used in this operation."); + _writer.WriteXmlDocumentationParameter("top", "The number of results to return."); + _writer.WriteXmlDocumentationParameter("cancellationToken", "A token to allow the caller to cancel the call to the service. The default value is ."); + _writer.WriteXmlDocumentation("returns", returnText); + using (_writer.Scope($"public {returnType} {methodName}(string nameFilter, int? top = null, {typeof(CancellationToken)} cancellationToken = default)")) + { + _writer.Line($"var results = ListAsGenericResource{asyncText}(null, top, cancellationToken);"); + _writer.Line($"return new PhWrapping{asyncText}Pageable(results, genericResource => new {_resourceOperation.Type}(genericResource).Get().Value);"); + } + } + + private PagingMethod FindListPagingMethod() + { + return _resourceContainer.PagingMethods.FirstOrDefault(m => m.Name.Equals("ListByResourceGroup", StringComparison.InvariantCultureIgnoreCase)) + ?? _resourceContainer.PagingMethods.FirstOrDefault(m => m.Name.Equals("List", StringComparison.InvariantCultureIgnoreCase)) + ?? _resourceContainer.PagingMethods.FirstOrDefault(m => m.Name.StartsWith("List", StringComparison.InvariantCultureIgnoreCase)); + } + + /// + /// Write paging method using `PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunction)` pattern. + /// + /// Paging method that contains rest methods. + /// Should the method be written sync or async. + private void WriteContainerPagingOperation(PagingMethod pagingMethod, bool async) + { + var parameters = pagingMethod.Method.Parameters; + + var pagedResourceType = new CSharpType(typeof(Page<>), _resource.Type); + var returnType = async ? new CSharpType(typeof(Task<>), pagedResourceType) : pagedResourceType; + + var nextLinkName = pagingMethod.PagingResponse.NextLinkProperty?.Declaration.Name; + var itemName = pagingMethod.PagingResponse.ItemProperty.Declaration.Name; + + var continuationTokenText = nextLinkName != null ? $"response.Value.{nextLinkName}" : "null"; + var asyncText = async ? "async" : string.Empty; + var awaitText = async ? "await" : string.Empty; + var configureAwaitText = async ? ".ConfigureAwait(false)" : string.Empty; + using (_writer.Scope($"{asyncText} {returnType} FirstPageFunc({typeof(int?)} pageSizeHint)")) + { + // no null-checks because all are optional + WriteDiagnosticScope(_writer, pagingMethod.Diagnostics, ClientDiagnosticsField, writer => + { + writer.Append($"var response = {awaitText} {RestClientField}.{CreateMethodName(pagingMethod.Method.Name, async)}("); + foreach (var parameter in BuildParameterMapping(pagingMethod.Method).Where(p => IsMandatory(p.Parameter))) + { + writer.Append($"{parameter.ValueExpression}, "); + } + + writer.Line($"cancellationToken: cancellationToken){configureAwaitText};"); + + this._writer.UseNamespace("System.Linq"); + // need the Select() for converting XXXResourceData to XXXResource + writer.Line($"return {typeof(Page)}.FromValues(response.Value.{itemName}.Select(value => new {_resource.Type}(Parent, value)), {continuationTokenText}, response.GetRawResponse());"); + }); + } + + var nextPageFunctionName = "null"; + if (pagingMethod.NextPageMethod != null) + { + nextPageFunctionName = "NextPageFunc"; + var nextPageParameters = pagingMethod.NextPageMethod.Parameters; + using (_writer.Scope($"{asyncText} {returnType} {nextPageFunctionName}({typeof(string)} nextLink, {typeof(int?)} pageSizeHint)")) + { + WriteDiagnosticScope(_writer, pagingMethod.Diagnostics, ClientDiagnosticsField, writer => + { + writer.Append($"var response = {awaitText} {RestClientField}.{CreateMethodName(pagingMethod.NextPageMethod.Name, async)}(nextLink, "); + foreach (var parameter in BuildParameterMapping(pagingMethod.NextPageMethod).Where(p => IsMandatory(p.Parameter))) + { + writer.Append($"{parameter.ValueExpression}, "); + } + writer.Line($"cancellationToken: cancellationToken){configureAwaitText};"); + writer.Line($"return {typeof(Page)}.FromValues(response.Value.{itemName}.Select(value => new {_resource.Type}(Parent, value)), {continuationTokenText}, response.GetRawResponse());"); + }); + } + } + _writer.Line($"return {typeof(PageableHelpers)}.Create{(async ? "Async" : string.Empty)}Enumerable(FirstPageFunc, {nextPageFunctionName});"); + } + + private void WriteListAsGenericResource(bool async) + { + const string syncMethodName = "ListAsGenericResource"; + var methodName = CreateMethodName(syncMethodName, async); + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Filters the list of {_resource.Type.Name} for this resource group represented as generic resources."); + _writer.WriteXmlDocumentationParameter("nameFilter", "The filter used in this operation."); + _writer.WriteXmlDocumentationParameter("top", "The number of results to return."); + _writer.WriteXmlDocumentationParameter("cancellationToken", "A token to allow the caller to cancel the call to the service. The default value is ."); + _writer.WriteXmlDocumentation("returns", $"{(async ? "An async" : "A")} collection of resource that may take multiple service requests to iterate over."); + CSharpType returnType = new CSharpType(async ? typeof(AsyncPageable<>) : typeof(Pageable<>), typeof(GenericResource)); + using (_writer.Scope($"public {returnType} {methodName}(string nameFilter, int? top = null, {typeof(CancellationToken)} cancellationToken = default)")) + { + WriteDiagnosticScope(_writer, new Diagnostic($"{_resourceContainer.Type.Name}.{syncMethodName}"), ClientDiagnosticsField, writer => + { + _writer.Line($"var filters = new {typeof(ResourceFilterCollection)}({_resource.Type}.ResourceType);"); + _writer.Line($"filters.SubstringFilter = nameFilter;"); + string asyncText = async ? "Async" : string.Empty; + _writer.Line($"return {typeof(ResourceListOperations)}.ListAtContext{asyncText}(Parent as {typeof(ResourceGroupOperations)}, filters, top, cancellationToken);"); + }); + } + } + + private void WriteListAsGenericResourceAsync() + { + var methodName = CreateMethodName("ListAsGenericResource", true); + _writer.Line(); + _writer.WriteXmlDocumentationSummary($"Filters the list of {_resource.Type.Name} for this resource group represented as generic resources."); + _writer.WriteXmlDocumentationParameter("nameFilter", "The filter used in this operation."); + _writer.WriteXmlDocumentationParameter("top", "The number of results to return."); + _writer.WriteXmlDocumentationParameter("cancellationToken", "A token to allow the caller to cancel the call to the service. The default value is ."); + _writer.WriteXmlDocumentation("returns", $"An async collection of resource that may take multiple service requests to iterate over."); + using (_writer.Scope($"public {typeof(AsyncPageable)} {methodName}(string nameFilter, int? top = null, {typeof(CancellationToken)} cancellationToken = default)")) + { + WriteDiagnosticScope(_writer, new Diagnostic($"{_resourceContainer.Type.Name}.{"ListAsGenericResource"}"), ClientDiagnosticsField, writer => + { + _writer.Line($"var filters = new {typeof(ResourceFilterCollection)}({_resource.Type}.ResourceType);"); + _writer.Line($"filters.SubstringFilter = nameFilter;"); + _writer.Line($"return {typeof(ResourceListOperations)}.ListAtContextAsync(Parent as {typeof(ResourceGroupOperations)}, filters, top, cancellationToken);"); + }); + } + } + + private void WriteBuilders() + { + _writer.Line(); + _writer.Line($"// Builders."); + _writer.LineRaw($"// public ArmBuilder<{_resourceContainer.ResourceIdentifierType}, {_resource.Type.Name}, {_resourceData.Type.Name}> Construct() {{ }}"); } } } diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ResourceOperationWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ResourceOperationWriter.cs index d99e9a9c26d..82c36661944 100644 --- a/src/AutoRest.CSharp/Mgmt/Generation/ResourceOperationWriter.cs +++ b/src/AutoRest.CSharp/Mgmt/Generation/ResourceOperationWriter.cs @@ -37,20 +37,27 @@ public void WriteClient(CodeWriter writer, ResourceOperation resourceOperation, private void WriteClientCtors(CodeWriter writer, ResourceOperation resourceOperation) { - writer.WriteXmlDocumentationSummary($"Initializes a new instance of {resourceOperation.Type.Name} for mocking."); - using (writer.Scope($"protected {resourceOperation.Type.Name}()")) - { + var typeOfThis = resourceOperation.Type.Name; - } + // write an internal default constructor + writer.WriteXmlDocumentationSummary($"Initializes a new instance of the class for mocking."); + using (writer.Scope($"protected {typeOfThis}()")) + { } + // write "generic resource" constructor writer.Line(); - writer.WriteXmlDocumentationSummary($"Initializes a new instance of class."); + writer.WriteXmlDocumentationSummary($"Initializes a new instance of the class."); + writer.WriteXmlDocumentationParameter("genericOperations", $"An instance of that has an id for a {resourceOperation.ResourceName}."); + using (writer.Scope($"internal {typeOfThis}({typeof(GenericResourceOperations)} genericOperations) : base(genericOperations, genericOperations.Id)")) + { } + + // write "resource + id" constructor + writer.Line(); + writer.WriteXmlDocumentationSummary($"Initializes a new instance of the class."); writer.WriteXmlDocumentationParameter("options", "The client parameters to use in these operations."); writer.WriteXmlDocumentationParameter("id", "The identifier of the resource that is the target of operations."); - using (writer.Scope($"protected {resourceOperation.Type.Name}({typeof(ResourceOperationsBase)} options, {resourceOperation.ResourceIdentifierType} id) : base(options, id)")) - { - - } + using (writer.Scope($"protected {typeOfThis}({typeof(ResourceOperationsBase)} options, {resourceOperation.ResourceIdentifierType} id) : base(options, id)")) + { } } private void WriteClientProperties(CodeWriter writer, ResourceOperation resourceOperation, MgmtConfiguration config) @@ -58,7 +65,7 @@ private void WriteClientProperties(CodeWriter writer, ResourceOperation resource writer.Line(); writer.Line($"public static readonly {typeof(ResourceType)} ResourceType = \"{resourceOperation.OperationGroup.ResourceType(config)}\";"); writer.Line($"protected override {typeof(ResourceType)} ValidResourceType => ResourceType;"); - } + } private void WriteClientMethods(CodeWriter writer, ResourceOperation resourceOperation) { diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ResourceWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ResourceWriter.cs index da300d01281..f2667f48d11 100644 --- a/src/AutoRest.CSharp/Mgmt/Generation/ResourceWriter.cs +++ b/src/AutoRest.CSharp/Mgmt/Generation/ResourceWriter.cs @@ -8,6 +8,7 @@ using Azure.ResourceManager.Core; using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.Output.Models.Types; +using AutoRest.CSharp.Mgmt.Decorator; namespace AutoRest.CSharp.Mgmt.Generation { @@ -28,7 +29,10 @@ public void WriteResource(CodeWriter writer, Resource resource, BuildContext class."); writer.WriteXmlDocumentationParameter("options", "The client parameters to use in these operations."); writer.WriteXmlDocumentationParameter("resource", "The resource that is the target of operations."); - using (writer.Scope($"internal {cs.Name}({typeof(ResourceOperationsBase)} options, {resourceDataObject.Type} resource) : base(options, resource.Id)")) + // inherits the default constructor when it is not a resource + var resourceData = context.Library.GetResourceData(resource.OperationGroup); + var baseConstructor = resourceData.IsResource() ? $" : base(options, resource.Id)" : string.Empty; + using (writer.Scope($"internal {cs.Name}({typeof(ResourceOperationsBase)} options, {resourceDataObject.Type} resource){baseConstructor}")) { writer.LineRaw("Data = resource;"); } diff --git a/src/AutoRest.CSharp/Mgmt/Output/ResourceData.cs b/src/AutoRest.CSharp/Mgmt/Output/ResourceData.cs index 4b6c836ebac..430a34f81b5 100644 --- a/src/AutoRest.CSharp/Mgmt/Output/ResourceData.cs +++ b/src/AutoRest.CSharp/Mgmt/Output/ResourceData.cs @@ -8,6 +8,7 @@ using AutoRest.CSharp.Mgmt.Decorator; using AutoRest.CSharp.Output.Builders; using AutoRest.CSharp.Output.Models.Types; +using Azure.ResourceManager.Core; namespace AutoRest.CSharp.Mgmt.Output { @@ -26,5 +27,21 @@ protected string CreateDescription(OperationGroup operationGroup, string clientP $"A class representing the {clientPrefix} data model. " : BuilderHelpers.EscapeXmlDescription(operationGroup.Language.Default.Description); } + + /// + /// Tells if a [Resource]Data is a resource by checking if it inherits any of: + /// Resource, TrackedResource, SubResource, or SubResourceWritable. + /// + /// + /// + internal bool IsResource() + { + return EnumerateHierarchy() + .Where(t => t.Inherits != null) + .Select(t => t.Inherits!) + .Any(csharpType => + csharpType.Namespace == "Azure.ResourceManager.Core" + && (csharpType.Name == nameof(Resource) || csharpType.Name == "TrackedResource" || csharpType.Name == nameof(SubResource) || csharpType.Name == nameof(SubResourceWritable))); + } } } diff --git a/src/AutoRest.CSharp/Mgmt/Output/ResourceOperation.cs b/src/AutoRest.CSharp/Mgmt/Output/ResourceOperation.cs index 0025f45b1b5..5633614379e 100644 --- a/src/AutoRest.CSharp/Mgmt/Output/ResourceOperation.cs +++ b/src/AutoRest.CSharp/Mgmt/Output/ResourceOperation.cs @@ -49,7 +49,7 @@ public ResourceOperation(OperationGroup operationGroup, BuildContext BuilderHelpers.EscapeXmlDescription(CreateDescription(OperationGroup, _prefix)); - public MgmtRestClient RestClient => _restClient ??= _context.Library.FindRestClient(OperationGroup); + public MgmtRestClient RestClient => _restClient ??= _context.Library.GetRestClient(OperationGroup); public string ResourceIdentifierType => _resourceIdentifierType ??= OperationGroup.GetResourceIdentifierType( _context.Library.GetResourceData(OperationGroup), diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Container.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Container.cs index f0649645b85..73c5a5520b0 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Container.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Container.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ExactMatchInheritance { /// A class representing collection of ExactMatchModel1 and their operations over a ResourceGroup. - public partial class ExactMatchModel1Container + public partial class ExactMatchModel1Container : ContainerBase { - /// Initializes a new instance of ExactMatchModel1Container for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel1Container() { } - internal ExactMatchModel1Container(ResourceOperationsBase parent) + /// Initializes a new instance of ExactMatchModel1Container class. + /// The resource representing the parent resource. + internal ExactMatchModel1Container(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ExactMatchModel1SRestOperations _restClient => new ExactMatchModel1SRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ExactMatchModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string exactMatchModel1SName, ExactMatchModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel1SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(exactMatchModel1SName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string exactMatchModel1SName, ExactMatchModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel1SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(exactMatchModel1SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string exactMatchModel1SName, ExactMatchModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel1SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, exactMatchModel1SName, parameters, cancellationToken: cancellationToken); + return new ExactMatchModel1SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string exactMatchModel1SName, ExactMatchModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel1SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, exactMatchModel1SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ExactMatchModel1SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of ExactMatchModel1 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel1Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ExactMatchModel1 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel1Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel1Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Operations.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Operations.cs index 966e1b49131..92a7d8f68e2 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Operations.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel1Operations.cs @@ -17,12 +17,18 @@ namespace ExactMatchInheritance /// A class representing the operations that can be performed over a specific ExactMatchModel1. public partial class ExactMatchModel1Operations : ResourceOperationsBase { - /// Initializes a new instance of ExactMatchModel1Operations for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel1Operations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ExactMatchModel1. + internal ExactMatchModel1Operations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ExactMatchModel1Operations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Container.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Container.cs index 759209179ec..af6f96e6661 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Container.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Container.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ExactMatchInheritance { /// A class representing collection of ExactMatchModel3 and their operations over a ResourceGroup. - public partial class ExactMatchModel3Container + public partial class ExactMatchModel3Container : ContainerBase { - /// Initializes a new instance of ExactMatchModel3Container for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel3Container() { } - internal ExactMatchModel3Container(ResourceOperationsBase parent) + /// Initializes a new instance of ExactMatchModel3Container class. + /// The resource representing the parent resource. + internal ExactMatchModel3Container(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ExactMatchModel3SRestOperations _restClient => new ExactMatchModel3SRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ExactMatchModel3. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel3 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string exactMatchModel3SName, ExactMatchModel3Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel3SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel3SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(exactMatchModel3SName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel3. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel3 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string exactMatchModel3SName, ExactMatchModel3Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel3SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel3SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(exactMatchModel3SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel3. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel3 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string exactMatchModel3SName, ExactMatchModel3Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel3SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel3SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, exactMatchModel3SName, parameters, cancellationToken: cancellationToken); + return new ExactMatchModel3SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel3. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel3 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string exactMatchModel3SName, ExactMatchModel3Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel3SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel3SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, exactMatchModel3SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ExactMatchModel3SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel3Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel3Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel3Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel3Operations(genericResource).Get().Value); + } + + /// Filters the list of ExactMatchModel3 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel3Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ExactMatchModel3 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel3Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel3Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Operations.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Operations.cs index db0db62a1ac..dcad5ce851a 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Operations.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel3Operations.cs @@ -17,12 +17,18 @@ namespace ExactMatchInheritance /// A class representing the operations that can be performed over a specific ExactMatchModel3. public partial class ExactMatchModel3Operations : ResourceOperationsBase { - /// Initializes a new instance of ExactMatchModel3Operations for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel3Operations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ExactMatchModel3. + internal ExactMatchModel3Operations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ExactMatchModel3Operations(ResourceOperationsBase options, ResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Container.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Container.cs index a5247799d31..e42704ae4b9 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Container.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Container.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ExactMatchInheritance { /// A class representing collection of ExactMatchModel5 and their operations over a ResourceGroup. - public partial class ExactMatchModel5Container + public partial class ExactMatchModel5Container : ContainerBase { - /// Initializes a new instance of ExactMatchModel5Container for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel5Container() { } - internal ExactMatchModel5Container(ResourceOperationsBase parent) + /// Initializes a new instance of ExactMatchModel5Container class. + /// The resource representing the parent resource. + internal ExactMatchModel5Container(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ExactMatchModel5SRestOperations _restClient => new ExactMatchModel5SRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ExactMatchModel5. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel5 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string exactMatchModel5SName, ExactMatchModel5Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel5SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel5SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(exactMatchModel5SName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel5. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel5 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string exactMatchModel5SName, ExactMatchModel5Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.CreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel5SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel5SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(exactMatchModel5SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel5. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel5 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string exactMatchModel5SName, ExactMatchModel5Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel5SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel5SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, exactMatchModel5SName, parameters, cancellationToken: cancellationToken); + return new ExactMatchModel5SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ExactMatchModel5. Please note some properties can be set only during creation. + /// The String to use. + /// The ExactMatchModel5 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string exactMatchModel5SName, ExactMatchModel5Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (exactMatchModel5SName == null) + { + throw new ArgumentNullException(nameof(exactMatchModel5SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, exactMatchModel5SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ExactMatchModel5SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel5Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ExactMatchModel5Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel5Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ExactMatchModel5Operations(genericResource).Get().Value); + } + + /// Filters the list of ExactMatchModel5 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel5Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ExactMatchModel5 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ExactMatchModel5Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ExactMatchModel5Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Operations.cs b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Operations.cs index 4249a089584..e82d374a1fc 100644 --- a/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Operations.cs +++ b/test/TestProjects/ExactMatchInheritance/Generated/ExactMatchModel5Operations.cs @@ -17,12 +17,18 @@ namespace ExactMatchInheritance /// A class representing the operations that can be performed over a specific ExactMatchModel5. public partial class ExactMatchModel5Operations : ResourceOperationsBase { - /// Initializes a new instance of ExactMatchModel5Operations for mocking. + /// Initializes a new instance of the class for mocking. protected ExactMatchModel5Operations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ExactMatchModel5. + internal ExactMatchModel5Operations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ExactMatchModel5Operations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/MgmtParent/Generated/AvailabilitySetContainer.cs b/test/TestProjects/MgmtParent/Generated/AvailabilitySetContainer.cs index 2df83dd55be..4ca74411f67 100644 --- a/test/TestProjects/MgmtParent/Generated/AvailabilitySetContainer.cs +++ b/test/TestProjects/MgmtParent/Generated/AvailabilitySetContainer.cs @@ -5,23 +5,356 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace MgmtParent { /// A class representing collection of AvailabilitySet and their operations over a ResourceGroup. - public partial class AvailabilitySetContainer + public partial class AvailabilitySetContainer : ResourceContainerBase { - /// Initializes a new instance of AvailabilitySetContainer for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetContainer() { } - internal AvailabilitySetContainer(ResourceOperationsBase parent) + /// Initializes a new instance of AvailabilitySetContainer class. + /// The resource representing the parent resource. + internal AvailabilitySetContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private AvailabilitySetsRestOperations _restClient => new AvailabilitySetsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(availabilitySetName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken); + return new AvailabilitySetsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a AvailabilitySet. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string availabilitySetName, AvailabilitySetData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new AvailabilitySetsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = _restClient.List(Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = _restClient.ListNextPage(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListAsync(Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.List"); + scope.Start(); + try + { + var response = await _restClient.ListNextPageAsync(nextLink, Id.ResourceGroupName, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new AvailabilitySet(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/MgmtParent/Generated/AvailabilitySetOperations.cs b/test/TestProjects/MgmtParent/Generated/AvailabilitySetOperations.cs index a6fd7c06adb..b953489862c 100644 --- a/test/TestProjects/MgmtParent/Generated/AvailabilitySetOperations.cs +++ b/test/TestProjects/MgmtParent/Generated/AvailabilitySetOperations.cs @@ -17,12 +17,18 @@ namespace MgmtParent /// A class representing the operations that can be performed over a specific AvailabilitySet. public partial class AvailabilitySetOperations : ResourceOperationsBase { - /// Initializes a new instance of AvailabilitySetOperations for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a AvailabilitySet. + internal AvailabilitySetOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected AvailabilitySetOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/MgmtParent/Generated/DedicatedHostContainer.cs b/test/TestProjects/MgmtParent/Generated/DedicatedHostContainer.cs index b6de19aa045..7c666e728c6 100644 --- a/test/TestProjects/MgmtParent/Generated/DedicatedHostContainer.cs +++ b/test/TestProjects/MgmtParent/Generated/DedicatedHostContainer.cs @@ -5,23 +5,368 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace MgmtParent { /// A class representing collection of DedicatedHost and their operations over a DedicatedHostGroup. - public partial class DedicatedHostContainer + public partial class DedicatedHostContainer : ResourceContainerBase { - /// Initializes a new instance of DedicatedHostContainer for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostContainer() { } - internal DedicatedHostContainer(ResourceOperationsBase parent) + /// Initializes a new instance of DedicatedHostContainer class. + /// The resource representing the parent resource. + internal DedicatedHostContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private DedicatedHostsRestOperations _restClient => new DedicatedHostsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => DedicatedHostGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => DedicatedHostGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(hostName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(hostName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Parent.Name, hostName, parameters, cancellationToken: cancellationToken); + var operation = new DedicatedHostsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, hostName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new DedicatedHost(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHost. Please note some properties can be set only during creation. + /// The name of the dedicated host . + /// Parameters supplied to the Create Dedicated Host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string hostName, DedicatedHostData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, Id.Parent.Name, hostName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new DedicatedHostsCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, Id.Parent.Name, hostName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new DedicatedHost(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string hostName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.Get"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, Id.Parent.Name, hostName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHost(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string hostName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.Get"); + scope.Start(); + try + { + if (hostName == null) + { + throw new ArgumentNullException(nameof(hostName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, Id.Parent.Name, hostName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHost(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = _restClient.ListByHostGroup(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = _restClient.ListByHostGroupNextPage(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new DedicatedHostOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByHostGroupAsync(Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListByHostGroup"); + scope.Start(); + try + { + var response = await _restClient.ListByHostGroupNextPageAsync(nextLink, Id.ResourceGroupName, Id.Parent.Name, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new DedicatedHost(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new DedicatedHostOperations(genericResource).Get().Value); + } + + /// Filters the list of DedicatedHost for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of DedicatedHost for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupContainer.cs b/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupContainer.cs index 07b0996b248..dcdde3b8b77 100644 --- a/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupContainer.cs +++ b/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupContainer.cs @@ -5,23 +5,297 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace MgmtParent { /// A class representing collection of DedicatedHostGroup and their operations over a ResourceGroup. - public partial class DedicatedHostGroupContainer + public partial class DedicatedHostGroupContainer : ResourceContainerBase { - /// Initializes a new instance of DedicatedHostGroupContainer for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostGroupContainer() { } - internal DedicatedHostGroupContainer(ResourceOperationsBase parent) + /// Initializes a new instance of DedicatedHostGroupContainer class. + /// The resource representing the parent resource. + internal DedicatedHostGroupContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private DedicatedHostGroupsRestOperations _restClient => new DedicatedHostGroupsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(hostGroupName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(hostGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, hostGroupName, parameters, cancellationToken: cancellationToken); + return new DedicatedHostGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a DedicatedHostGroup. Please note some properties can be set only during creation. + /// The name of the dedicated host group. + /// Parameters supplied to the Create Dedicated Host Group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string hostGroupName, DedicatedHostGroupData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, hostGroupName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new DedicatedHostGroupsCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string hostGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.Get"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, hostGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHostGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the dedicated host group. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string hostGroupName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.Get"); + scope.Start(); + try + { + if (hostGroupName == null) + { + throw new ArgumentNullException(nameof(hostGroupName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, hostGroupName, cancellationToken: cancellationToken); + return Response.FromValue(new DedicatedHostGroup(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new DedicatedHostGroupOperations(genericResource).Get().Value); + } + + /// Filters the list of DedicatedHostGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of DedicatedHostGroup for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("DedicatedHostGroupContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(DedicatedHostGroupOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupOperations.cs b/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupOperations.cs index 1f6b6dc0b1b..74b34f04cfa 100644 --- a/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupOperations.cs +++ b/test/TestProjects/MgmtParent/Generated/DedicatedHostGroupOperations.cs @@ -17,12 +17,18 @@ namespace MgmtParent /// A class representing the operations that can be performed over a specific DedicatedHostGroup. public partial class DedicatedHostGroupOperations : ResourceOperationsBase { - /// Initializes a new instance of DedicatedHostGroupOperations for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostGroupOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a DedicatedHostGroup. + internal DedicatedHostGroupOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected DedicatedHostGroupOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/MgmtParent/Generated/DedicatedHostOperations.cs b/test/TestProjects/MgmtParent/Generated/DedicatedHostOperations.cs index 9b3c64c8663..cd4f61cfd9e 100644 --- a/test/TestProjects/MgmtParent/Generated/DedicatedHostOperations.cs +++ b/test/TestProjects/MgmtParent/Generated/DedicatedHostOperations.cs @@ -17,12 +17,18 @@ namespace MgmtParent /// A class representing the operations that can be performed over a specific DedicatedHost. public partial class DedicatedHostOperations : ResourceOperationsBase { - /// Initializes a new instance of DedicatedHostOperations for mocking. + /// Initializes a new instance of the class for mocking. protected DedicatedHostOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a DedicatedHost. + internal DedicatedHostOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected DedicatedHostOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageContainer.cs b/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageContainer.cs index 039f6eecfc3..4011ff7cd8b 100644 --- a/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageContainer.cs +++ b/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace MgmtParent { /// A class representing collection of VirtualMachineExtensionImage and their operations over a Parent. - public partial class VirtualMachineExtensionImageContainer + public partial class VirtualMachineExtensionImageContainer : ResourceContainerBase { - /// Initializes a new instance of VirtualMachineExtensionImageContainer for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionImageContainer() { } - internal VirtualMachineExtensionImageContainer(ResourceOperationsBase parent) + /// Initializes a new instance of VirtualMachineExtensionImageContainer class. + /// The resource representing the parent resource. + internal VirtualMachineExtensionImageContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private VirtualMachineExtensionImagesRestOperations _restClient => new VirtualMachineExtensionImagesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => "Microsoft.Compute/locations/publishers"; + protected override ResourceType ValidResourceType => "Microsoft.Compute/locations/publishers"; + + // Container level operations. + + /// + /// The String to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = _restClient.Get(Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtensionImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The String to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string version, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.Get"); + scope.Start(); + try + { + if (version == null) + { + throw new ArgumentNullException(nameof(version)); + } + + var response = await _restClient.GetAsync(Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, version, cancellationToken: cancellationToken); + return Response.FromValue(new VirtualMachineExtensionImage(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new VirtualMachineExtensionImageOperations(genericResource).Get().Value); + } + + /// Filters the list of VirtualMachineExtensionImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtensionImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of VirtualMachineExtensionImage for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("VirtualMachineExtensionImageContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(VirtualMachineExtensionImageOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageOperations.cs b/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageOperations.cs index bb101d832a3..fa29c430306 100644 --- a/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageOperations.cs +++ b/test/TestProjects/MgmtParent/Generated/VirtualMachineExtensionImageOperations.cs @@ -17,12 +17,18 @@ namespace MgmtParent /// A class representing the operations that can be performed over a specific VirtualMachineExtensionImage. public partial class VirtualMachineExtensionImageOperations : ResourceOperationsBase { - /// Initializes a new instance of VirtualMachineExtensionImageOperations for mocking. + /// Initializes a new instance of the class for mocking. protected VirtualMachineExtensionImageOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a VirtualMachineExtensionImage. + internal VirtualMachineExtensionImageOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected VirtualMachineExtensionImageOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetContainer.cs b/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetContainer.cs index 00b1f25c9a8..aa4940af41b 100644 --- a/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetContainer.cs +++ b/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace OperationGroupMappings { /// A class representing collection of AvailabilitySet and their operations over a ResourceGroup. - public partial class AvailabilitySetContainer + public partial class AvailabilitySetContainer : ResourceContainerBase { - /// Initializes a new instance of AvailabilitySetContainer for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetContainer() { } - internal AvailabilitySetContainer(ResourceOperationsBase parent) + /// Initializes a new instance of AvailabilitySetContainer class. + /// The resource representing the parent resource. + internal AvailabilitySetContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private AvailabilitySetsRestOperations _restClient => new AvailabilitySetsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = _restClient.Get(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The name of the availability set. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string availabilitySetName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.Get"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + + var response = await _restClient.GetAsync(Id.ResourceGroupName, availabilitySetName, cancellationToken: cancellationToken); + return Response.FromValue(new AvailabilitySet(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AvailabilitySetOperations(genericResource).Get().Value); + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of AvailabilitySet for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AvailabilitySetContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AvailabilitySetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetOperations.cs b/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetOperations.cs index 8600f75b3f1..e1b4f5e1602 100644 --- a/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetOperations.cs +++ b/test/TestProjects/OperationGroupMappings/Generated/AvailabilitySetOperations.cs @@ -17,12 +17,18 @@ namespace OperationGroupMappings /// A class representing the operations that can be performed over a specific AvailabilitySet. public partial class AvailabilitySetOperations : ResourceOperationsBase { - /// Initializes a new instance of AvailabilitySetOperations for mocking. + /// Initializes a new instance of the class for mocking. protected AvailabilitySetOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a AvailabilitySet. + internal AvailabilitySetOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected AvailabilitySetOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataContainer.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataContainer.cs index 8c7948a65c0..d2217fca97b 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataContainer.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataContainer.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ResourceIdentifierChooser { /// A class representing collection of ModelData and their operations over a ResourceGroup. - public partial class ModelDataContainer + public partial class ModelDataContainer : ContainerBase { - /// Initializes a new instance of ModelDataContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ModelDataContainer() { } - internal ModelDataContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ModelDataContainer class. + /// The resource representing the parent resource. + internal ModelDataContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ModelDatasRestOperations _restClient => new ModelDatasRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ModelData. Please note some properties can be set only during creation. + /// The String to use. + /// The ModelData to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string modelDatasName, ModelDataData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (modelDatasName == null) + { + throw new ArgumentNullException(nameof(modelDatasName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(modelDatasName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ModelData. Please note some properties can be set only during creation. + /// The String to use. + /// The ModelData to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string modelDatasName, ModelDataData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (modelDatasName == null) + { + throw new ArgumentNullException(nameof(modelDatasName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(modelDatasName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ModelData. Please note some properties can be set only during creation. + /// The String to use. + /// The ModelData to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string modelDatasName, ModelDataData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (modelDatasName == null) + { + throw new ArgumentNullException(nameof(modelDatasName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, modelDatasName, parameters, cancellationToken: cancellationToken); + return new ModelDatasPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ModelData. Please note some properties can be set only during creation. + /// The String to use. + /// The ModelData to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string modelDatasName, ModelDataData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (modelDatasName == null) + { + throw new ArgumentNullException(nameof(modelDatasName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, modelDatasName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ModelDatasPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ModelDataOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ModelDataOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ModelDataOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ModelDataOperations(genericResource).Get().Value); + } + + /// Filters the list of ModelData for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ModelDataOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ModelData for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ModelDataContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ModelDataOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataOperations.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataOperations.cs index 3d8a47ce307..97570cdfde5 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataOperations.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ModelDataOperations.cs @@ -17,12 +17,18 @@ namespace ResourceIdentifierChooser /// A class representing the operations that can be performed over a specific ModelData. public partial class ModelDataOperations : ResourceOperationsBase { - /// Initializes a new instance of ModelDataOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ModelDataOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ModelData. + internal ModelDataOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ModelDataOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceContainer.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceContainer.cs index 57edcb85259..0181fb69766 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceContainer.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceContainer.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ResourceIdentifierChooser { /// A class representing collection of ResourceGroupResource and their operations over a ResourceGroup. - public partial class ResourceGroupResourceContainer + public partial class ResourceGroupResourceContainer : ContainerBase { - /// Initializes a new instance of ResourceGroupResourceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ResourceGroupResourceContainer() { } - internal ResourceGroupResourceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ResourceGroupResourceContainer class. + /// The resource representing the parent resource. + internal ResourceGroupResourceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ResourceGroupResourcesRestOperations _restClient => new ResourceGroupResourcesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ResourceGroupResource. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceGroupResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string resourceGroupResourcesName, ResourceGroupResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (resourceGroupResourcesName == null) + { + throw new ArgumentNullException(nameof(resourceGroupResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(resourceGroupResourcesName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceGroupResource. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceGroupResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string resourceGroupResourcesName, ResourceGroupResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (resourceGroupResourcesName == null) + { + throw new ArgumentNullException(nameof(resourceGroupResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(resourceGroupResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceGroupResource. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceGroupResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string resourceGroupResourcesName, ResourceGroupResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (resourceGroupResourcesName == null) + { + throw new ArgumentNullException(nameof(resourceGroupResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, resourceGroupResourcesName, parameters, cancellationToken: cancellationToken); + return new ResourceGroupResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceGroupResource. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceGroupResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string resourceGroupResourcesName, ResourceGroupResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (resourceGroupResourcesName == null) + { + throw new ArgumentNullException(nameof(resourceGroupResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, resourceGroupResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ResourceGroupResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ResourceGroupResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ResourceGroupResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ResourceGroupResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ResourceGroupResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of ResourceGroupResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ResourceGroupResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ResourceGroupResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceGroupResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ResourceGroupResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceOperations.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceOperations.cs index a78d026cfe0..64ab1404a54 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceOperations.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceGroupResourceOperations.cs @@ -17,12 +17,18 @@ namespace ResourceIdentifierChooser /// A class representing the operations that can be performed over a specific ResourceGroupResource. public partial class ResourceGroupResourceOperations : ResourceOperationsBase { - /// Initializes a new instance of ResourceGroupResourceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ResourceGroupResourceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ResourceGroupResource. + internal ResourceGroupResourceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ResourceGroupResourceOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelContainer.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelContainer.cs index be453a5c003..1c6e013ac6a 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelContainer.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelContainer.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ResourceIdentifierChooser { /// A class representing collection of ResourceLevel and their operations over a ResourceGroup. - public partial class ResourceLevelContainer + public partial class ResourceLevelContainer : ContainerBase { - /// Initializes a new instance of ResourceLevelContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ResourceLevelContainer() { } - internal ResourceLevelContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ResourceLevelContainer class. + /// The resource representing the parent resource. + internal ResourceLevelContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ResourceLevelsRestOperations _restClient => new ResourceLevelsRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a ResourceLevel. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceLevel to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string resourceLevelsName, ResourceLevelData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (resourceLevelsName == null) + { + throw new ArgumentNullException(nameof(resourceLevelsName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(resourceLevelsName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceLevel. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceLevel to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string resourceLevelsName, ResourceLevelData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (resourceLevelsName == null) + { + throw new ArgumentNullException(nameof(resourceLevelsName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(resourceLevelsName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceLevel. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceLevel to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string resourceLevelsName, ResourceLevelData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (resourceLevelsName == null) + { + throw new ArgumentNullException(nameof(resourceLevelsName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, resourceLevelsName, parameters, cancellationToken: cancellationToken); + return new ResourceLevelsPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a ResourceLevel. Please note some properties can be set only during creation. + /// The String to use. + /// The ResourceLevel to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string resourceLevelsName, ResourceLevelData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (resourceLevelsName == null) + { + throw new ArgumentNullException(nameof(resourceLevelsName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, resourceLevelsName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ResourceLevelsPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ResourceLevelOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ResourceLevelOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ResourceLevelOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ResourceLevelOperations(genericResource).Get().Value); + } + + /// Filters the list of ResourceLevel for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ResourceLevelOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of ResourceLevel for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ResourceLevelContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ResourceLevelOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelOperations.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelOperations.cs index 763621cc1ec..634c44ddca8 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelOperations.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/ResourceLevelOperations.cs @@ -17,12 +17,18 @@ namespace ResourceIdentifierChooser /// A class representing the operations that can be performed over a specific ResourceLevel. public partial class ResourceLevelOperations : ResourceOperationsBase { - /// Initializes a new instance of ResourceLevelOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ResourceLevelOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a ResourceLevel. + internal ResourceLevelOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ResourceLevelOperations(ResourceOperationsBase options, ResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceContainer.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceContainer.cs index f6f657b9aa7..e251d469486 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceContainer.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceContainer.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ResourceIdentifierChooser { /// A class representing collection of SubscriptionLevelResource and their operations over a Subscription. - public partial class SubscriptionLevelResourceContainer + public partial class SubscriptionLevelResourceContainer : ContainerBase { - /// Initializes a new instance of SubscriptionLevelResourceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected SubscriptionLevelResourceContainer() { } - internal SubscriptionLevelResourceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of SubscriptionLevelResourceContainer class. + /// The resource representing the parent resource. + internal SubscriptionLevelResourceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private SubscriptionLevelResourcesRestOperations _restClient => new SubscriptionLevelResourcesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a SubscriptionLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The SubscriptionLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string subscriptionLevelResourcesName, SubscriptionLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (subscriptionLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(subscriptionLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(subscriptionLevelResourcesName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SubscriptionLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The SubscriptionLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string subscriptionLevelResourcesName, SubscriptionLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (subscriptionLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(subscriptionLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(subscriptionLevelResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SubscriptionLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The SubscriptionLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string subscriptionLevelResourcesName, SubscriptionLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (subscriptionLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(subscriptionLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, subscriptionLevelResourcesName, parameters, cancellationToken: cancellationToken); + return new SubscriptionLevelResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SubscriptionLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The SubscriptionLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string subscriptionLevelResourcesName, SubscriptionLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (subscriptionLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(subscriptionLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, subscriptionLevelResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new SubscriptionLevelResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SubscriptionLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SubscriptionLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SubscriptionLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SubscriptionLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of SubscriptionLevelResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SubscriptionLevelResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of SubscriptionLevelResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SubscriptionLevelResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SubscriptionLevelResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceOperations.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceOperations.cs index 70b16563c7f..64d1a6a84f4 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceOperations.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/SubscriptionLevelResourceOperations.cs @@ -17,12 +17,18 @@ namespace ResourceIdentifierChooser /// A class representing the operations that can be performed over a specific SubscriptionLevelResource. public partial class SubscriptionLevelResourceOperations : ResourceOperationsBase { - /// Initializes a new instance of SubscriptionLevelResourceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected SubscriptionLevelResourceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a SubscriptionLevelResource. + internal SubscriptionLevelResourceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected SubscriptionLevelResourceOperations(ResourceOperationsBase options, SubscriptionResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceContainer.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceContainer.cs index c0e38da3df1..756ae997932 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceContainer.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceContainer.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace ResourceIdentifierChooser { /// A class representing collection of TenantLevelResource and their operations over a Tenant. - public partial class TenantLevelResourceContainer + public partial class TenantLevelResourceContainer : ContainerBase { - /// Initializes a new instance of TenantLevelResourceContainer for mocking. + /// Initializes a new instance of the class for mocking. protected TenantLevelResourceContainer() { } - internal TenantLevelResourceContainer(ResourceOperationsBase parent) + /// Initializes a new instance of TenantLevelResourceContainer class. + /// The resource representing the parent resource. + internal TenantLevelResourceContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private TenantLevelResourcesRestOperations _restClient => new TenantLevelResourcesRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + + // Container level operations. + + /// The operation to create or update a TenantLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The TenantLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string tenantLevelResourcesName, TenantLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (tenantLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(tenantLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(tenantLevelResourcesName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a TenantLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The TenantLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string tenantLevelResourcesName, TenantLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (tenantLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(tenantLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(tenantLevelResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a TenantLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The TenantLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string tenantLevelResourcesName, TenantLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (tenantLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(tenantLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, tenantLevelResourcesName, parameters, cancellationToken: cancellationToken); + return new TenantLevelResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a TenantLevelResource. Please note some properties can be set only during creation. + /// The String to use. + /// The TenantLevelResource to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string tenantLevelResourcesName, TenantLevelResourceData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (tenantLevelResourcesName == null) + { + throw new ArgumentNullException(nameof(tenantLevelResourcesName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, tenantLevelResourcesName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new TenantLevelResourcesPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new TenantLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new TenantLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new TenantLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new TenantLevelResourceOperations(genericResource).Get().Value); + } + + /// Filters the list of TenantLevelResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(TenantLevelResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of TenantLevelResource for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("TenantLevelResourceContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(TenantLevelResourceOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceOperations.cs b/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceOperations.cs index 7d291aa31ca..b913292cf51 100644 --- a/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceOperations.cs +++ b/test/TestProjects/ResourceIdentifierChooser/Generated/TenantLevelResourceOperations.cs @@ -17,12 +17,18 @@ namespace ResourceIdentifierChooser /// A class representing the operations that can be performed over a specific TenantLevelResource. public partial class TenantLevelResourceOperations : ResourceOperationsBase { - /// Initializes a new instance of TenantLevelResourceOperations for mocking. + /// Initializes a new instance of the class for mocking. protected TenantLevelResourceOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a TenantLevelResource. + internal TenantLevelResourceOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected TenantLevelResourceOperations(ResourceOperationsBase options, TenantResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/SubscriptionExtensions/Generated/OvenContainer.cs b/test/TestProjects/SubscriptionExtensions/Generated/OvenContainer.cs index d71bf7d8e7b..f32fdf43e64 100644 --- a/test/TestProjects/SubscriptionExtensions/Generated/OvenContainer.cs +++ b/test/TestProjects/SubscriptionExtensions/Generated/OvenContainer.cs @@ -5,23 +5,321 @@ #nullable disable +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; +using SubscriptionExtensions.Models; namespace SubscriptionExtensions { /// A class representing collection of Oven and their operations over a ResourceGroup. - public partial class OvenContainer + public partial class OvenContainer : ContainerBase { - /// Initializes a new instance of OvenContainer for mocking. + /// Initializes a new instance of the class for mocking. protected OvenContainer() { } - internal OvenContainer(ResourceOperationsBase parent) + /// Initializes a new instance of OvenContainer class. + /// The resource representing the parent resource. + internal OvenContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private OvensRestOperations _restClient => new OvensRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a Oven. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string vmName, OvenData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(vmName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Oven. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string vmName, OvenData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(vmName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Oven. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string vmName, OvenData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, vmName, parameters, cancellationToken: cancellationToken); + var operation = new OvensCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new Oven(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Oven. Please note some properties can be set only during creation. + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string vmName, OvenData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (vmName == null) + { + throw new ArgumentNullException(nameof(vmName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, vmName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var operation = new OvensCreateOrUpdateOperation( + _clientDiagnostics, _pipeline, _restClient.CreateCreateOrUpdateRequest( + Id.ResourceGroupName, vmName, parameters).Request, + originalResponse); + return new PhArmOperation( + operation, + data => new Oven(Parent, data)); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + Page FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAll"); + scope.Start(); + try + { + var response = _restClient.ListAll(cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new Oven(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + Page NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAll"); + scope.Start(); + try + { + var response = _restClient.ListAllNextPage(nextLink, cancellationToken: cancellationToken); + return Page.FromValues(response.Value.Value.Select(value => new Oven(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new OvenOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + async Task> FirstPageFunc(int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAll"); + scope.Start(); + try + { + var response = await _restClient.ListAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new Oven(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + async Task> NextPageFunc(string nextLink, int? pageSizeHint) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAll"); + scope.Start(); + try + { + var response = await _restClient.ListAllNextPageAsync(nextLink, cancellationToken: cancellationToken).ConfigureAwait(false); + return Page.FromValues(response.Value.Value.Select(value => new Oven(Parent, value)), response.Value.NextLink, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new OvenOperations(genericResource).Get().Value); + } + + /// Filters the list of Oven for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(OvenOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of Oven for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("OvenContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(OvenOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/SubscriptionExtensions/Generated/OvenOperations.cs b/test/TestProjects/SubscriptionExtensions/Generated/OvenOperations.cs index f3b134bafe4..da9f8fa7b9c 100644 --- a/test/TestProjects/SubscriptionExtensions/Generated/OvenOperations.cs +++ b/test/TestProjects/SubscriptionExtensions/Generated/OvenOperations.cs @@ -17,12 +17,18 @@ namespace SubscriptionExtensions /// A class representing the operations that can be performed over a specific Oven. public partial class OvenOperations : ResourceOperationsBase { - /// Initializes a new instance of OvenOperations for mocking. + /// Initializes a new instance of the class for mocking. protected OvenOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a Oven. + internal OvenOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected OvenOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/SubscriptionExtensions/Generated/ToasterContainer.cs b/test/TestProjects/SubscriptionExtensions/Generated/ToasterContainer.cs index 1973c040ac4..7e7c88a2f87 100644 --- a/test/TestProjects/SubscriptionExtensions/Generated/ToasterContainer.cs +++ b/test/TestProjects/SubscriptionExtensions/Generated/ToasterContainer.cs @@ -5,23 +5,250 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; +using SubscriptionExtensions.Models; namespace SubscriptionExtensions { /// A class representing collection of Toaster and their operations over a Subscription. - public partial class ToasterContainer + public partial class ToasterContainer : ContainerBase { - /// Initializes a new instance of ToasterContainer for mocking. + /// Initializes a new instance of the class for mocking. protected ToasterContainer() { } - internal ToasterContainer(ResourceOperationsBase parent) + /// Initializes a new instance of ToasterContainer class. + /// The resource representing the parent resource. + internal ToasterContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private ToastersRestOperations _restClient => new ToastersRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a Toaster. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string availabilitySetName, ToasterData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(availabilitySetName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Toaster. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string availabilitySetName, ToasterData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.CreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Toaster. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string availabilitySetName, ToasterData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.CreateOrUpdate(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken); + return new ToastersCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a Toaster. Please note some properties can be set only during creation. + /// The name of the availability set. + /// Parameters supplied to the Create Availability Set operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string availabilitySetName, ToasterData parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.StartCreateOrUpdate"); + scope.Start(); + try + { + if (availabilitySetName == null) + { + throw new ArgumentNullException(nameof(availabilitySetName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.CreateOrUpdateAsync(Id.ResourceGroupName, availabilitySetName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new ToastersCreateOrUpdateOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ToasterOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new ToasterOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ToasterOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new ToasterOperations(genericResource).Get().Value); + } + + /// Filters the list of Toaster for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ToasterOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of Toaster for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("ToasterContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(ToasterOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/SubscriptionExtensions/Generated/ToasterOperations.cs b/test/TestProjects/SubscriptionExtensions/Generated/ToasterOperations.cs index 77dcd20e2cc..b04e6d3d994 100644 --- a/test/TestProjects/SubscriptionExtensions/Generated/ToasterOperations.cs +++ b/test/TestProjects/SubscriptionExtensions/Generated/ToasterOperations.cs @@ -17,12 +17,18 @@ namespace SubscriptionExtensions /// A class representing the operations that can be performed over a specific Toaster. public partial class ToasterOperations : ResourceOperationsBase { - /// Initializes a new instance of ToasterOperations for mocking. + /// Initializes a new instance of the class for mocking. protected ToasterOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a Toaster. + internal ToasterOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected ToasterOperations(ResourceOperationsBase options, SubscriptionResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Container.cs b/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Container.cs index 405a3725033..62f39eeb2e6 100644 --- a/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Container.cs +++ b/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Container.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace SupersetInheritance { /// A class representing collection of SupersetModel1 and their operations over a ResourceGroup. - public partial class SupersetModel1Container + public partial class SupersetModel1Container : ContainerBase { - /// Initializes a new instance of SupersetModel1Container for mocking. + /// Initializes a new instance of the class for mocking. protected SupersetModel1Container() { } - internal SupersetModel1Container(ResourceOperationsBase parent) + /// Initializes a new instance of SupersetModel1Container class. + /// The resource representing the parent resource. + internal SupersetModel1Container(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private SupersetModel1SRestOperations _restClient => new SupersetModel1SRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a SupersetModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string supersetModel1SName, SupersetModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.CreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel1SName == null) + { + throw new ArgumentNullException(nameof(supersetModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(supersetModel1SName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string supersetModel1SName, SupersetModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.CreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel1SName == null) + { + throw new ArgumentNullException(nameof(supersetModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(supersetModel1SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string supersetModel1SName, SupersetModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel1SName == null) + { + throw new ArgumentNullException(nameof(supersetModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, supersetModel1SName, parameters, cancellationToken: cancellationToken); + return new SupersetModel1SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel1. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel1 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string supersetModel1SName, SupersetModel1Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel1SName == null) + { + throw new ArgumentNullException(nameof(supersetModel1SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, supersetModel1SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new SupersetModel1SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SupersetModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SupersetModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SupersetModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SupersetModel1Operations(genericResource).Get().Value); + } + + /// Filters the list of SupersetModel1 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SupersetModel1Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of SupersetModel1 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel1Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SupersetModel1Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Operations.cs b/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Operations.cs index 6cf01ab285f..83a48346509 100644 --- a/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Operations.cs +++ b/test/TestProjects/SupersetInheritance/Generated/SupersetModel1Operations.cs @@ -17,12 +17,18 @@ namespace SupersetInheritance /// A class representing the operations that can be performed over a specific SupersetModel1. public partial class SupersetModel1Operations : ResourceOperationsBase { - /// Initializes a new instance of SupersetModel1Operations for mocking. + /// Initializes a new instance of the class for mocking. protected SupersetModel1Operations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a SupersetModel1. + internal SupersetModel1Operations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected SupersetModel1Operations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Container.cs b/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Container.cs index 67d0b342e7a..65be024c676 100644 --- a/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Container.cs +++ b/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Container.cs @@ -5,23 +5,249 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace SupersetInheritance { /// A class representing collection of SupersetModel4 and their operations over a ResourceGroup. - public partial class SupersetModel4Container + public partial class SupersetModel4Container : ContainerBase { - /// Initializes a new instance of SupersetModel4Container for mocking. + /// Initializes a new instance of the class for mocking. protected SupersetModel4Container() { } - internal SupersetModel4Container(ResourceOperationsBase parent) + /// Initializes a new instance of SupersetModel4Container class. + /// The resource representing the parent resource. + internal SupersetModel4Container(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private SupersetModel4SRestOperations _restClient => new SupersetModel4SRestOperations(_clientDiagnostics, _pipeline, Id.SubscriptionId); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + // Container level operations. + + /// The operation to create or update a SupersetModel4. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel4 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Response CreateOrUpdate(string supersetModel4SName, SupersetModel4Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.CreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel4SName == null) + { + throw new ArgumentNullException(nameof(supersetModel4SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + return StartCreateOrUpdate(supersetModel4SName, parameters, cancellationToken: cancellationToken).WaitForCompletion() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel4. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel4 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> CreateOrUpdateAsync(string supersetModel4SName, SupersetModel4Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.CreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel4SName == null) + { + throw new ArgumentNullException(nameof(supersetModel4SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var operation = await StartCreateOrUpdateAsync(supersetModel4SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return await operation.WaitForCompletionAsync() as Response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel4. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel4 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public Operation StartCreateOrUpdate(string supersetModel4SName, SupersetModel4Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel4SName == null) + { + throw new ArgumentNullException(nameof(supersetModel4SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = _restClient.Put(Id.ResourceGroupName, supersetModel4SName, parameters, cancellationToken: cancellationToken); + return new SupersetModel4SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// The operation to create or update a SupersetModel4. Please note some properties can be set only during creation. + /// The String to use. + /// The SupersetModel4 to use. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async Task> StartCreateOrUpdateAsync(string supersetModel4SName, SupersetModel4Data parameters, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.StartCreateOrUpdate"); + scope.Start(); + try + { + if (supersetModel4SName == null) + { + throw new ArgumentNullException(nameof(supersetModel4SName)); + } + if (parameters == null) + { + throw new ArgumentNullException(nameof(parameters)); + } + + var originalResponse = await _restClient.PutAsync(Id.ResourceGroupName, supersetModel4SName, parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + return new SupersetModel4SPutOperation(Parent, originalResponse); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SupersetModel4Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new SupersetModel4Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SupersetModel4Operations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new SupersetModel4Operations(genericResource).Get().Value); + } + + /// Filters the list of SupersetModel4 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SupersetModel4Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of SupersetModel4 for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("SupersetModel4Container.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(SupersetModel4Operations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Operations.cs b/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Operations.cs index 3da8b31d850..7bdfba5f420 100644 --- a/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Operations.cs +++ b/test/TestProjects/SupersetInheritance/Generated/SupersetModel4Operations.cs @@ -17,12 +17,18 @@ namespace SupersetInheritance /// A class representing the operations that can be performed over a specific SupersetModel4. public partial class SupersetModel4Operations : ResourceOperationsBase { - /// Initializes a new instance of SupersetModel4Operations for mocking. + /// Initializes a new instance of the class for mocking. protected SupersetModel4Operations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a SupersetModel4. + internal SupersetModel4Operations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected SupersetModel4Operations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/TenantOnly/Generated/AgreementContainer.cs b/test/TestProjects/TenantOnly/Generated/AgreementContainer.cs index ebefb67e843..4b9007be648 100644 --- a/test/TestProjects/TenantOnly/Generated/AgreementContainer.cs +++ b/test/TestProjects/TenantOnly/Generated/AgreementContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace TenantOnly { /// A class representing collection of Agreement and their operations over a BillingAccount. - public partial class AgreementContainer + public partial class AgreementContainer : ResourceContainerBase { - /// Initializes a new instance of AgreementContainer for mocking. + /// Initializes a new instance of the class for mocking. protected AgreementContainer() { } - internal AgreementContainer(ResourceOperationsBase parent) + /// Initializes a new instance of AgreementContainer class. + /// The resource representing the parent resource. + internal AgreementContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private AgreementsRestOperations _restClient => new AgreementsRestOperations(_clientDiagnostics, _pipeline); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => BillingAccountOperations.ResourceType; + protected override ResourceType ValidResourceType => BillingAccountOperations.ResourceType; + + // Container level operations. + + /// + /// The ID that uniquely identifies an agreement. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string agreementName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AgreementContainer.Get"); + scope.Start(); + try + { + if (agreementName == null) + { + throw new ArgumentNullException(nameof(agreementName)); + } + + var response = _restClient.Get(Id.Parent.Name, agreementName, cancellationToken: cancellationToken); + return Response.FromValue(new Agreement(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The ID that uniquely identifies an agreement. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string agreementName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AgreementContainer.Get"); + scope.Start(); + try + { + if (agreementName == null) + { + throw new ArgumentNullException(nameof(agreementName)); + } + + var response = await _restClient.GetAsync(Id.Parent.Name, agreementName, cancellationToken: cancellationToken); + return Response.FromValue(new Agreement(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AgreementOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new AgreementOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AgreementOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new AgreementOperations(genericResource).Get().Value); + } + + /// Filters the list of Agreement for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AgreementContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AgreementOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of Agreement for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("AgreementContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(AgreementOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/TenantOnly/Generated/AgreementOperations.cs b/test/TestProjects/TenantOnly/Generated/AgreementOperations.cs index 2959f6452ac..57572da258f 100644 --- a/test/TestProjects/TenantOnly/Generated/AgreementOperations.cs +++ b/test/TestProjects/TenantOnly/Generated/AgreementOperations.cs @@ -17,12 +17,18 @@ namespace TenantOnly /// A class representing the operations that can be performed over a specific Agreement. public partial class AgreementOperations : ResourceOperationsBase { - /// Initializes a new instance of AgreementOperations for mocking. + /// Initializes a new instance of the class for mocking. protected AgreementOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a Agreement. + internal AgreementOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected AgreementOperations(ResourceOperationsBase options, ResourceGroupResourceIdentifier id) : base(options, id) diff --git a/test/TestProjects/TenantOnly/Generated/BillingAccountContainer.cs b/test/TestProjects/TenantOnly/Generated/BillingAccountContainer.cs index f0158505b35..68c12b506d0 100644 --- a/test/TestProjects/TenantOnly/Generated/BillingAccountContainer.cs +++ b/test/TestProjects/TenantOnly/Generated/BillingAccountContainer.cs @@ -5,23 +5,182 @@ #nullable disable +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; namespace TenantOnly { /// A class representing collection of BillingAccount and their operations over a Tenant. - public partial class BillingAccountContainer + public partial class BillingAccountContainer : ResourceContainerBase { - /// Initializes a new instance of BillingAccountContainer for mocking. + /// Initializes a new instance of the class for mocking. protected BillingAccountContainer() { } - internal BillingAccountContainer(ResourceOperationsBase parent) + /// Initializes a new instance of BillingAccountContainer class. + /// The resource representing the parent resource. + internal BillingAccountContainer(ResourceOperationsBase parent) : base(parent) { + _clientDiagnostics = new ClientDiagnostics(ClientOptions); + _pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); } + private readonly ClientDiagnostics _clientDiagnostics; + private readonly HttpPipeline _pipeline; + + /// Represents the REST operations. + private BillingAccountsRestOperations _restClient => new BillingAccountsRestOperations(_clientDiagnostics, _pipeline); + + /// Typed Resource Identifier for the container. + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + /// Gets the valid resource type for this object. - protected ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + protected override ResourceType ValidResourceType => ResourceIdentifier.RootResourceIdentifier.ResourceType; + + // Container level operations. + + /// + /// The ID that uniquely identifies a billing account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public override Response Get(string billingAccountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BillingAccountContainer.Get"); + scope.Start(); + try + { + if (billingAccountName == null) + { + throw new ArgumentNullException(nameof(billingAccountName)); + } + + var response = _restClient.Get(billingAccountName, cancellationToken: cancellationToken); + return Response.FromValue(new BillingAccount(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// The ID that uniquely identifies a billing account. + /// A token to allow the caller to cancel the call to the service. The default value is . + public async override Task> GetAsync(string billingAccountName, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BillingAccountContainer.Get"); + scope.Start(); + try + { + if (billingAccountName == null) + { + throw new ArgumentNullException(nameof(billingAccountName)); + } + + var response = await _restClient.GetAsync(billingAccountName, cancellationToken: cancellationToken); + return Response.FromValue(new BillingAccount(Parent, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new BillingAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(null, top, cancellationToken); + return new PhWrappingPageable(results, genericResource => new BillingAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new BillingAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of for this resource group. Makes an additional network call to retrieve the full data model for each resource group. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(null, top, cancellationToken); + return new PhWrappingAsyncPageable(results, genericResource => new BillingAccountOperations(genericResource).Get().Value); + } + + /// Filters the list of BillingAccount for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BillingAccountContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BillingAccountOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Filters the list of BillingAccount for this resource group represented as generic resources. + /// The filter used in this operation. + /// The number of results to return. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + using var scope = _clientDiagnostics.CreateScope("BillingAccountContainer.ListAsGenericResource"); + scope.Start(); + try + { + var filters = new ResourceFilterCollection(BillingAccountOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // Builders. + // public ArmBuilder Construct() { } } } diff --git a/test/TestProjects/TenantOnly/Generated/BillingAccountOperations.cs b/test/TestProjects/TenantOnly/Generated/BillingAccountOperations.cs index 6e64256276e..87d7fc1fe0e 100644 --- a/test/TestProjects/TenantOnly/Generated/BillingAccountOperations.cs +++ b/test/TestProjects/TenantOnly/Generated/BillingAccountOperations.cs @@ -17,12 +17,18 @@ namespace TenantOnly /// A class representing the operations that can be performed over a specific BillingAccount. public partial class BillingAccountOperations : ResourceOperationsBase { - /// Initializes a new instance of BillingAccountOperations for mocking. + /// Initializes a new instance of the class for mocking. protected BillingAccountOperations() { } - /// Initializes a new instance of class. + /// Initializes a new instance of the class. + /// An instance of that has an id for a BillingAccount. + internal BillingAccountOperations(GenericResourceOperations genericOperations) : base(genericOperations, genericOperations.Id) + { + } + + /// Initializes a new instance of the class. /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. protected BillingAccountOperations(ResourceOperationsBase options, TenantResourceIdentifier id) : base(options, id)