diff --git a/@azure-typespec/http-client-csharp-mgmt/Microsoft.StorageDiscovery.sln b/@azure-typespec/http-client-csharp-mgmt/Microsoft.StorageDiscovery.sln new file mode 100644 index 000000000000..bd0e67160b89 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/Microsoft.StorageDiscovery.sln @@ -0,0 +1,48 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.StorageDiscovery", "src\Microsoft.StorageDiscovery.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MicrosoftStorageDiscoveryExtensions.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MicrosoftStorageDiscoveryExtensions.cs new file mode 100644 index 000000000000..2719f50c9169 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MicrosoftStorageDiscoveryExtensions.cs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Microsoft.StorageDiscovery.Mocking; + +namespace Microsoft.StorageDiscovery +{ + /// A class to add extension methods to Microsoft.StorageDiscovery. + public static partial class MicrosoftStorageDiscoveryExtensions + { + /// + private static MockableMicrosoftStorageDiscoveryArmClient GetMockableMicrosoftStorageDiscoveryArmClient(ArmClient client) + { + return client.GetCachedClient(client0 => new MockableMicrosoftStorageDiscoveryArmClient(client0, ResourceIdentifier.Root)); + } + + /// + private static MockableMicrosoftStorageDiscoveryResourceGroupResource GetMockableMicrosoftStorageDiscoveryResourceGroupResource(ResourceGroupResource resourceGroupResource) + { + return resourceGroupResource.GetCachedClient(client => new MockableMicrosoftStorageDiscoveryResourceGroupResource(client, resourceGroupResource.Id)); + } + + /// + private static MockableMicrosoftStorageDiscoverySubscriptionResource GetMockableMicrosoftStorageDiscoverySubscriptionResource(SubscriptionResource subscriptionResource) + { + return subscriptionResource.GetCachedClient(client => new MockableMicrosoftStorageDiscoverySubscriptionResource(client, subscriptionResource.Id)); + } + + /// Gets an object representing a along with the instance operations that can be performed on it but with no data. + /// The the method will execute against. + /// The resource ID of the resource to get. + /// is null. + /// Returns a object. + public static StorageDiscoveryWorkspaceResource GetStorageDiscoveryWorkspaceResource(this ArmClient client, ResourceIdentifier id) + { + Argument.AssertNotNull(client, nameof(client)); + + return GetMockableMicrosoftStorageDiscoveryArmClient(client).GetStorageDiscoveryWorkspaceResource(id); + } + + /// Gets a collection of StorageDiscoveryWorkspaces in the . + /// The the method will execute against. + /// is null. + /// An object representing collection of StorageDiscoveryWorkspaces and their operations over a StorageDiscoveryWorkspaceResource. + public static StorageDiscoveryWorkspaceCollection GetStorageDiscoveryWorkspaces(this ResourceGroupResource resourceGroupResource) + { + Argument.AssertNotNull(resourceGroupResource, nameof(resourceGroupResource)); + + return GetMockableMicrosoftStorageDiscoveryResourceGroupResource(resourceGroupResource).GetStorageDiscoveryWorkspaces(); + } + + /// Get a StorageDiscoveryWorkspace. + /// The the method will execute against. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + [ForwardsClientCalls] + public static async Task> GetStorageDiscoveryWorkspaceAsync(this ResourceGroupResource resourceGroupResource, string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupResource, nameof(resourceGroupResource)); + + return await GetMockableMicrosoftStorageDiscoveryResourceGroupResource(resourceGroupResource).GetStorageDiscoveryWorkspaceAsync(storageDiscoveryWorkspaceName, cancellationToken).ConfigureAwait(false); + } + + /// Get a StorageDiscoveryWorkspace. + /// The the method will execute against. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + [ForwardsClientCalls] + public static Response GetStorageDiscoveryWorkspace(this ResourceGroupResource resourceGroupResource, string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupResource, nameof(resourceGroupResource)); + + return GetMockableMicrosoftStorageDiscoveryResourceGroupResource(resourceGroupResource).GetStorageDiscoveryWorkspace(storageDiscoveryWorkspaceName, cancellationToken); + } + + /// List StorageDiscoveryWorkspace resources by subscription ID. + /// The the method will execute against. + /// The cancellation token to use. + /// is null. + /// A collection of that may take multiple service requests to iterate over. + public static AsyncPageable GetStorageDiscoveryWorkspacesAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return GetMockableMicrosoftStorageDiscoverySubscriptionResource(subscriptionResource).GetStorageDiscoveryWorkspacesAsync(cancellationToken); + } + + /// List StorageDiscoveryWorkspace resources by subscription ID. + /// The the method will execute against. + /// The cancellation token to use. + /// is null. + /// A collection of that may take multiple service requests to iterate over. + public static Pageable GetStorageDiscoveryWorkspaces(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return GetMockableMicrosoftStorageDiscoverySubscriptionResource(subscriptionResource).GetStorageDiscoveryWorkspaces(cancellationToken); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryArmClient.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryArmClient.cs new file mode 100644 index 000000000000..bd7e1121450e --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryArmClient.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core; +using Azure.ResourceManager; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Mocking +{ + /// A class to add extension methods to . + public partial class MockableMicrosoftStorageDiscoveryArmClient : ArmResource + { + /// Initializes a new instance of MockableMicrosoftStorageDiscoveryArmClient for mocking. + protected MockableMicrosoftStorageDiscoveryArmClient() + { + } + + /// 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. + internal MockableMicrosoftStorageDiscoveryArmClient(ArmClient client, ResourceIdentifier id) : base(client, id) + { + } + + /// Gets an object representing a along with the instance operations that can be performed on it but with no data. + /// The resource ID of the resource to get. + /// Returns a object. + public virtual StorageDiscoveryWorkspaceResource GetStorageDiscoveryWorkspaceResource(ResourceIdentifier id) + { + StorageDiscoveryWorkspaceResource.ValidateResourceId(id); + return new StorageDiscoveryWorkspaceResource(Client, id); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryResourceGroupResource.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryResourceGroupResource.cs new file mode 100644 index 000000000000..3379329555cc --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoveryResourceGroupResource.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Mocking +{ + /// A class to add extension methods to . + public partial class MockableMicrosoftStorageDiscoveryResourceGroupResource : ArmResource + { + /// Initializes a new instance of MockableMicrosoftStorageDiscoveryResourceGroupResource for mocking. + protected MockableMicrosoftStorageDiscoveryResourceGroupResource() + { + } + + /// 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. + internal MockableMicrosoftStorageDiscoveryResourceGroupResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + } + + /// Gets a collection of StorageDiscoveryWorkspaces in the . + /// An object representing collection of StorageDiscoveryWorkspaces and their operations over a StorageDiscoveryWorkspaceResource. + public virtual StorageDiscoveryWorkspaceCollection GetStorageDiscoveryWorkspaces() + { + return GetCachedClient(client => new StorageDiscoveryWorkspaceCollection(client, Id)); + } + + /// Get a StorageDiscoveryWorkspace. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + [ForwardsClientCalls] + public virtual async Task> GetStorageDiscoveryWorkspaceAsync(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + return await GetStorageDiscoveryWorkspaces().GetAsync(storageDiscoveryWorkspaceName, cancellationToken).ConfigureAwait(false); + } + + /// Get a StorageDiscoveryWorkspace. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + [ForwardsClientCalls] + public virtual Response GetStorageDiscoveryWorkspace(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + return GetStorageDiscoveryWorkspaces().Get(storageDiscoveryWorkspaceName, cancellationToken); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoverySubscriptionResource.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoverySubscriptionResource.cs new file mode 100644 index 000000000000..9095113771ea --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Extensions/MockableMicrosoftStorageDiscoverySubscriptionResource.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Mocking +{ + /// A class to add extension methods to . + public partial class MockableMicrosoftStorageDiscoverySubscriptionResource : ArmResource + { + private ClientDiagnostics _storageDiscoveryWorkspacesClientDiagnostics; + private StorageDiscoveryWorkspaces _storageDiscoveryWorkspacesRestClient; + + /// Initializes a new instance of MockableMicrosoftStorageDiscoverySubscriptionResource for mocking. + protected MockableMicrosoftStorageDiscoverySubscriptionResource() + { + } + + /// 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. + internal MockableMicrosoftStorageDiscoverySubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + } + + private ClientDiagnostics StorageDiscoveryWorkspacesClientDiagnostics => _storageDiscoveryWorkspacesClientDiagnostics ??= new ClientDiagnostics("Microsoft.StorageDiscovery.Mocking", ProviderConstants.DefaultProviderNamespace, Diagnostics); + + private StorageDiscoveryWorkspaces StorageDiscoveryWorkspacesRestClient => _storageDiscoveryWorkspacesRestClient ??= new StorageDiscoveryWorkspaces(StorageDiscoveryWorkspacesClientDiagnostics, Pipeline, Endpoint, "2025-09-01"); + + /// List StorageDiscoveryWorkspace resources by subscription ID. + /// The cancellation token to use. + /// A collection of that may take multiple service requests to iterate over. + public virtual AsyncPageable GetStorageDiscoveryWorkspacesAsync(CancellationToken cancellationToken = default) + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + return new AsyncPageableWrapper(new StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT(StorageDiscoveryWorkspacesRestClient, Guid.Parse(Id.SubscriptionId), context), data => new StorageDiscoveryWorkspaceResource(Client, data)); + } + + /// List StorageDiscoveryWorkspace resources by subscription ID. + /// The cancellation token to use. + /// A collection of that may take multiple service requests to iterate over. + public virtual Pageable GetStorageDiscoveryWorkspaces(CancellationToken cancellationToken = default) + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + return new PageableWrapper(new StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT(StorageDiscoveryWorkspacesRestClient, Guid.Parse(Id.SubscriptionId), context), data => new StorageDiscoveryWorkspaceResource(Client, data)); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Argument.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Argument.cs new file mode 100644 index 000000000000..c7260eec7a9c --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Argument.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class Argument + { + /// The value. + /// The name. + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + /// The value. + /// The name. + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + /// The value. + /// The name. + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + /// The value. + /// The name. + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/AsyncPageableWrapper.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/AsyncPageableWrapper.cs new file mode 100644 index 000000000000..0deac7b7e634 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/AsyncPageableWrapper.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; + +namespace Microsoft.StorageDiscovery +{ + internal partial class AsyncPageableWrapper : AsyncPageable + { + /// The source async pageable value of type AsyncPageable<T>. + private AsyncPageable _source; + /// The converter function from T to U. + private Func _converter; + + /// Initializes a new instance of the AsyncPageableWrapper class. + /// The source async pageable value of type AsyncPageable<T>. + /// The converter function from T to U. + public AsyncPageableWrapper(AsyncPageable source, Func converter) + { + _source = source; + _converter = converter; + } + + /// Converts the pages from AsyncPageable to Page. + /// A continuation token from a previous response. + /// An optional hint to specify the desired size of each page. + /// An enumerable of pages containing converted items of type U. + public override async IAsyncEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + await foreach (Page page in _source.AsPages(continuationToken, pageSizeHint).ConfigureAwait(false)) + { + List convertedItems = new List(); + foreach (T item in page.Values) + { + convertedItems.Add(_converter.Invoke(item)); + } + yield return Page.FromValues(convertedItems, page.ContinuationToken, page.GetRawResponse()); + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingDictionary.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 000000000000..44660b537314 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.StorageDiscovery +{ + internal partial class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary + where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + /// The inner dictionary. + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + /// The inner dictionary. + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + /// Gets the IsUndefined. + public bool IsUndefined => _innerDictionary == null; + + /// Gets the Count. + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + /// Gets the IsReadOnly. + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + /// Gets the Keys. + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + /// Gets the Values. + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + /// Gets or sets the value associated with the specified key. + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + /// Gets the Keys. + IEnumerable IReadOnlyDictionary.Keys => Keys; + + /// Gets the Values. + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// The item to add. + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + /// The item to search for. + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + /// The array to copy. + /// The index. + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + /// The item to remove. + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + /// The key. + /// The value to add. + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + /// The key to search for. + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + /// The key. + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + /// The key to search for. + /// The value. + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingList.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 000000000000..94f96904e4ee --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,168 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.StorageDiscovery +{ + internal partial class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + /// The inner list. + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + /// The inner list. + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + /// Gets the IsUndefined. + public bool IsUndefined => _innerList == null; + + /// Gets the Count. + public int Count => IsUndefined ? 0 : EnsureList().Count; + + /// Gets the IsReadOnly. + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + /// Gets or sets the value associated with the specified key. + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// The item to add. + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + /// The item. + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + /// The array to copy to. + /// The array index. + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + /// The item. + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + /// The item. + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + /// The inner list. + /// The item. + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + /// The inner list. + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ClientPipelineExtensions.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ClientPipelineExtensions.cs new file mode 100644 index 000000000000..1a84f9bfc76f --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ClientPipelineExtensions.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class ClientPipelineExtensions + { + public static async ValueTask ProcessMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + await pipeline.SendAsync(message, userCancellationToken).ConfigureAwait(false); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static Response ProcessMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + pipeline.Send(message, userCancellationToken); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static async ValueTask> ProcessHeadAsBoolMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = await pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + + public static Response ProcessHeadAsBoolMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = pipeline.ProcessMessage(message, context); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenMemberAttribute.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenMemberAttribute.cs new file mode 100644 index 000000000000..c5d2e6a19e26 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenMemberAttribute.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.StorageDiscovery +{ + [AttributeUsage((AttributeTargets.Property | AttributeTargets.Field))] + internal partial class CodeGenMemberAttribute : CodeGenTypeAttribute + { + /// The original name of the member. + public CodeGenMemberAttribute(string originalName) : base(originalName) + { + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSerializationAttribute.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSerializationAttribute.cs new file mode 100644 index 000000000000..20b926cc781d --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSerializationAttribute.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.StorageDiscovery +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Struct), AllowMultiple = true, Inherited = true)] + internal partial class CodeGenSerializationAttribute : Attribute + { + /// The property name which these hooks apply to. + public CodeGenSerializationAttribute(string propertyName) + { + PropertyName = propertyName; + } + + /// The property name which these hooks apply to. + /// The serialization name of the property. + public CodeGenSerializationAttribute(string propertyName, string propertySerializationName) + { + PropertyName = propertyName; + PropertySerializationName = propertySerializationName; + } + + /// Gets or sets the property name which these hooks should apply to. + public string PropertyName { get; } + + /// Gets or sets the serialization name of the property. + public string PropertySerializationName { get; set; } + + /// + /// Gets or sets the method name to use when serializing the property value (property name excluded). + /// The signature of the serialization hook method must be or compatible with when invoking: private void SerializeHook(Utf8JsonWriter writer); + /// + public string SerializationValueHook { get; set; } + + /// + /// Gets or sets the method name to use when deserializing the property value from the JSON. + /// private static void DeserializationHook(JsonProperty property, ref TypeOfTheProperty propertyValue); // if the property is required + /// private static void DeserializationHook(JsonProperty property, ref Optional<TypeOfTheProperty> propertyValue); // if the property is optional + /// + public string DeserializationValueHook { get; set; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSuppressAttribute.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSuppressAttribute.cs new file mode 100644 index 000000000000..dad1dd66a81d --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenSuppressAttribute.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.StorageDiscovery +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct), AllowMultiple = true)] + internal partial class CodeGenSuppressAttribute : Attribute + { + /// The member to suppress. + /// The types of the parameters of the member. + public CodeGenSuppressAttribute(string member, params Type[] parameters) + { + Member = member; + Parameters = parameters; + } + + /// Gets the Member. + public string Member { get; } + + /// Gets the Parameters. + public Type[] Parameters { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenTypeAttribute.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenTypeAttribute.cs new file mode 100644 index 000000000000..23b88c4ed4ce --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/CodeGenTypeAttribute.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.StorageDiscovery +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct))] + internal partial class CodeGenTypeAttribute : Attribute + { + /// The original name of the type. + public CodeGenTypeAttribute(string originalName) + { + OriginalName = originalName; + } + + /// Gets the OriginalName. + public string OriginalName { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ErrorResult.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ErrorResult.cs new file mode 100644 index 000000000000..7236b57f3963 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ErrorResult.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; + +namespace Microsoft.StorageDiscovery +{ + internal partial class ErrorResult : Response + { + private readonly Response _response; + private readonly RequestFailedException _exception; + + public ErrorResult(Response response, RequestFailedException exception) + { + _response = response; + _exception = exception; + } + + /// Gets the Value. + public override T Value => throw _exception; + + /// + public override Response GetRawResponse() + { + return _response; + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ModelSerializationExtensions.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 000000000000..84f97c482758 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,258 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class ModelSerializationExtensions + { + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + internal static readonly JsonDocumentOptions JsonDocumentOptions = new JsonDocumentOptions + { + MaxDepth = 256 + }; + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + Dictionary dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + List list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + string text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty @property) + { + throw new JsonException($"A property '{@property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + string value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Optional.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Optional.cs new file mode 100644 index 000000000000..92f2b0fbfb13 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Optional.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(string value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/PageableWrapper.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/PageableWrapper.cs new file mode 100644 index 000000000000..f6e33c5e1205 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/PageableWrapper.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure; + +namespace Microsoft.StorageDiscovery +{ + internal partial class PageableWrapper : Pageable + { + /// The source pageable value of type Pageable<T>. + private Pageable _source; + /// The converter function from T to U. + private Func _converter; + + /// Initializes a new instance of the PageableWrapper class. + /// The source pageable value of type Pageable<T>. + /// The converter function from T to U. + public PageableWrapper(Pageable source, Func converter) + { + _source = source; + _converter = converter; + } + + /// Converts the pages from Pageable to Page. + /// A continuation token from a previous response. + /// An optional hint to specify the desired size of each page. + /// An enumerable of pages containing converted items of type U. + public override IEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + foreach (Page page in _source.AsPages(continuationToken, pageSizeHint)) + { + List convertedItems = new List(); + foreach (T item in page.Values) + { + convertedItems.Add(_converter.Invoke(item)); + } + yield return Page.FromValues(convertedItems, page.ContinuationToken, page.GetRawResponse()); + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/RequestContextExtensions.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/RequestContextExtensions.cs new file mode 100644 index 000000000000..082087954f71 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/RequestContextExtensions.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using Azure; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class RequestContextExtensions + { + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + public static ValueTuple Parse(this RequestContext context) + { + if (context == null) + { + return (CancellationToken.None, ErrorOptions.Default); + } + return (context.CancellationToken, context.ErrorOptions); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/TypeFormatters.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/TypeFormatters.cs new file mode 100644 index 000000000000..e674c23dc925 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/TypeFormatters.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Xml; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Generated clients require it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked (value.Length + 2) / 3; + int size = checked (numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Utf8JsonRequestContent.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Utf8JsonRequestContent.cs new file mode 100644 index 000000000000..2bee3b406a8c --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Internal/Utf8JsonRequestContent.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Microsoft.StorageDiscovery +{ + internal partial class Utf8JsonRequestContent : RequestContent + { + private readonly MemoryStream _stream; + private readonly RequestContent _content; + + public Utf8JsonRequestContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + /// Gets the JsonWriter. + public Utf8JsonWriter JsonWriter { get; } + + /// The stream containing the data to be written. + /// The cancellation token to use. + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + /// The stream containing the data to be written. + /// The cancellation token to use. + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + /// + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperation.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperation.cs new file mode 100644 index 000000000000..76864cc17b8c --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperation.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryArmOperation : ArmOperation + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of StorageDiscoveryArmOperation for mocking. + protected StorageDiscoveryArmOperation() + { + } + + /// + /// The operation response. + /// The token to rehydrate the operation. + internal StorageDiscoveryArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + /// + /// The instance of . + /// The instance of . + /// The operation request. + /// The operation response. + /// The finalStateVia of the operation. + /// If should skip Api version override. + /// The Api version override value. + internal StorageDiscoveryArmOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + IOperation nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationImplementation) + { + _nextLinkOperation = nextLinkOperationImplementation; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal( + nextLinkOperation, + clientDiagnostics, + response, + "StorageDiscoveryArmOperation", + null, + new SequentialDelayStrategy()); + } + + /// Gets the Id. + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// Gets the HasCompleted. + public override bool HasCompleted => _operation.HasCompleted; + + /// The token to rehydrate a long-running operation. + private string GetOperationId(RehydrationToken? rehydrationToken) + { + return rehydrationToken?.Id; + } + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletionResponse(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(cancellationToken); + + /// + public override Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken); + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperationOfT.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperationOfT.cs new file mode 100644 index 000000000000..a91ac8329f5f --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/LongRunningOperation/StorageDiscoveryArmOperationOfT.cs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryArmOperation : ArmOperation + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of StorageDiscoveryArmOperation for mocking. + protected StorageDiscoveryArmOperation() + { + } + + /// + /// The operation response. + /// The token to rehydrate the operation. + internal StorageDiscoveryArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response.GetRawResponse(), response.Value); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + /// + /// The instance of . + /// The instance of . + /// The instance of . + /// The operation request. + /// The operation response. + /// The finalStateVia of the operation. + /// If should skip Api version override. + /// The Api version override value. + internal StorageDiscoveryArmOperation(IOperationSource source, ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + IOperation nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationImplementation) + { + _nextLinkOperation = nextLinkOperationImplementation; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal( + NextLinkOperationImplementation.Create(source, nextLinkOperation), + clientDiagnostics, + response, + "StorageDiscoveryArmOperation", + null, + new SequentialDelayStrategy()); + } + + /// Gets the Id. + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// Gets the Value. + public override T Value => _operation.Value; + + /// Gets the HasValue. + public override bool HasValue => _operation.HasValue; + + /// Gets the HasCompleted. + public override bool HasCompleted => _operation.HasCompleted; + + /// The token to rehydrate a long-running operation. + private string GetOperationId(RehydrationToken? rehydrationToken) + { + return rehydrationToken?.Id; + } + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletion(CancellationToken cancellationToken = default) => _operation.WaitForCompletion(cancellationToken); + + /// + public override Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletion(pollingInterval, cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken); + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/MicrosoftStorageDiscoveryModelFactory.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/MicrosoftStorageDiscoveryModelFactory.cs new file mode 100644 index 000000000000..9a734a84016c --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/MicrosoftStorageDiscoveryModelFactory.cs @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; +using Azure.ResourceManager.Models; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// A factory class for creating instances of the models for mocking. + public static partial class MicrosoftStorageDiscoveryModelFactory + { + /// A Storage Discovery Workspace resource. This resource configures the collection of storage account metrics. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// Resource tags. + /// The geo-location where the resource lives. + /// The resource-specific properties for this resource. + /// A new instance for mocking. + public static StorageDiscoveryWorkspaceData StorageDiscoveryWorkspaceData(ResourceIdentifier id = default, string name = default, ResourceType resourceType = default, SystemData systemData = default, IDictionary tags = default, AzureLocation location = default, StorageDiscoveryWorkspaceProperties properties = default) + { + tags ??= new ChangeTrackingDictionary(); + + return new StorageDiscoveryWorkspaceData( + id, + name, + resourceType, + systemData, + additionalBinaryDataProperties: null, + tags, + location, + properties); + } + + /// Storage Discovery Workspace Properties. + /// The storage discovery sku. + /// The description of the storage discovery workspace. + /// The view level storage discovery data estate. + /// The scopes of the storage discovery workspace. + /// The status of the last operation. + /// A new instance for mocking. + public static StorageDiscoveryWorkspaceProperties StorageDiscoveryWorkspaceProperties(StorageDiscoverySku? sku = default, string description = default, IEnumerable workspaceRoots = default, IEnumerable scopes = default, StorageDiscoveryProvisioningState? provisioningState = default) + { + workspaceRoots ??= new ChangeTrackingList(); + scopes ??= new ChangeTrackingList(); + + return new StorageDiscoveryWorkspaceProperties( + sku, + description, + workspaceRoots.ToList(), + scopes.ToList(), + provisioningState, + additionalBinaryDataProperties: null); + } + + /// Storage Discovery Scope. This had added validations. + /// Display name of the collection. + /// Resource types for the collection. + /// The storage account tags keys to filter. + /// Resource tags. + /// A new instance for mocking. + public static StorageDiscoveryScope StorageDiscoveryScope(string displayName = default, IEnumerable resourceTypes = default, IEnumerable tagKeysOnly = default, IDictionary tags = default) + { + resourceTypes ??= new ChangeTrackingList(); + tagKeysOnly ??= new ChangeTrackingList(); + tags ??= new ChangeTrackingDictionary(); + + return new StorageDiscoveryScope(displayName, resourceTypes.ToList(), tagKeysOnly.ToList(), tags, additionalBinaryDataProperties: null); + } + + /// The template for adding updateable properties. + /// Resource tags. + /// The resource-specific properties for this resource. + /// A new instance for mocking. + public static StorageDiscoveryWorkspacePatch StorageDiscoveryWorkspacePatch(IDictionary tags = default, StorageDiscoveryWorkspacePropertiesUpdate properties = default) + { + tags ??= new ChangeTrackingDictionary(); + + return new StorageDiscoveryWorkspacePatch(tags, properties, additionalBinaryDataProperties: null); + } + + /// The template for adding updateable properties. + /// The storage discovery sku. + /// The description of the storage discovery workspace. + /// The view level storage discovery data estate. + /// The scopes of the storage discovery workspace. + /// A new instance for mocking. + public static StorageDiscoveryWorkspacePropertiesUpdate StorageDiscoveryWorkspacePropertiesUpdate(StorageDiscoverySku? sku = default, string description = default, IEnumerable workspaceRoots = default, IEnumerable scopes = default) + { + workspaceRoots ??= new ChangeTrackingList(); + scopes ??= new ChangeTrackingList(); + + return new StorageDiscoveryWorkspacePropertiesUpdate(sku, description, workspaceRoots.ToList(), scopes.ToList(), additionalBinaryDataProperties: null); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/MicrosoftStorageDiscoveryContext.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/MicrosoftStorageDiscoveryContext.cs new file mode 100644 index 000000000000..dc3932a5ca10 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/MicrosoftStorageDiscoveryContext.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.ClientModel.Primitives; +using Azure.ResourceManager.Models; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + /// + /// Context class which will be filled in by the System.ClientModel.SourceGeneration. + /// For more information + /// + [ModelReaderWriterBuildable(typeof(StorageDiscoveryScope))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspaceData))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspaceListResult))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspacePatch))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspaceProperties))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspacePropertiesUpdate))] + [ModelReaderWriterBuildable(typeof(StorageDiscoveryWorkspaceResource))] + [ModelReaderWriterBuildable(typeof(SystemData))] + public partial class MicrosoftStorageDiscoveryContext : ModelReaderWriterContext + { + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryProvisioningState.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryProvisioningState.cs new file mode 100644 index 000000000000..86e45287d06a --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryProvisioningState.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The provisioning state of a resource type. + public readonly partial struct StorageDiscoveryProvisioningState : IEquatable + { + private readonly string _value; + /// Resource has been created. + private const string SucceededValue = "Succeeded"; + /// Resource creation failed. + private const string FailedValue = "Failed"; + /// Resource creation was canceled. + private const string CanceledValue = "Canceled"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public StorageDiscoveryProvisioningState(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Resource has been created. + public static StorageDiscoveryProvisioningState Succeeded { get; } = new StorageDiscoveryProvisioningState(SucceededValue); + + /// Resource creation failed. + public static StorageDiscoveryProvisioningState Failed { get; } = new StorageDiscoveryProvisioningState(FailedValue); + + /// Resource creation was canceled. + public static StorageDiscoveryProvisioningState Canceled { get; } = new StorageDiscoveryProvisioningState(CanceledValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(StorageDiscoveryProvisioningState left, StorageDiscoveryProvisioningState right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(StorageDiscoveryProvisioningState left, StorageDiscoveryProvisioningState right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoveryProvisioningState(string value) => new StorageDiscoveryProvisioningState(value); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoveryProvisioningState?(string value) => value == null ? null : new StorageDiscoveryProvisioningState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is StorageDiscoveryProvisioningState other && Equals(other); + + /// + public bool Equals(StorageDiscoveryProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryResourceType.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryResourceType.cs new file mode 100644 index 000000000000..cdd75df007ea --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryResourceType.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Resource Type. + public readonly partial struct StorageDiscoveryResourceType : IEquatable + { + private readonly string _value; + /// Storage Account Resource Type. + private const string StorageAccountsValue = "Microsoft.Storage/storageAccounts"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public StorageDiscoveryResourceType(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Storage Account Resource Type. + public static StorageDiscoveryResourceType StorageAccounts { get; } = new StorageDiscoveryResourceType(StorageAccountsValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(StorageDiscoveryResourceType left, StorageDiscoveryResourceType right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(StorageDiscoveryResourceType left, StorageDiscoveryResourceType right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoveryResourceType(string value) => new StorageDiscoveryResourceType(value); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoveryResourceType?(string value) => value == null ? null : new StorageDiscoveryResourceType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is StorageDiscoveryResourceType other && Equals(other); + + /// + public bool Equals(StorageDiscoveryResourceType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.Serialization.cs new file mode 100644 index 000000000000..805f8af76bb9 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.Serialization.cs @@ -0,0 +1,236 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Scope. This had added validations. + public partial class StorageDiscoveryScope : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal StorageDiscoveryScope() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryScope)} does not support writing '{format}' format."); + } + writer.WritePropertyName("displayName"u8); + writer.WriteStringValue(DisplayName); + writer.WritePropertyName("resourceTypes"u8); + writer.WriteStartArray(); + foreach (StorageDiscoveryResourceType item in ResourceTypes) + { + writer.WriteStringValue(item.ToString()); + } + writer.WriteEndArray(); + if (Optional.IsCollectionDefined(TagKeysOnly)) + { + writer.WritePropertyName("tagKeysOnly"u8); + writer.WriteStartArray(); + foreach (string item in TagKeysOnly) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Tags)) + { + writer.WritePropertyName("tags"u8); + writer.WriteStartObject(); + foreach (var item in Tags) + { + writer.WritePropertyName(item.Key); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryScope IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryScope JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryScope)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryScope(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryScope DeserializeStorageDiscoveryScope(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string displayName = default; + IList resourceTypes = default; + IList tagKeysOnly = default; + IDictionary tags = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("displayName"u8)) + { + displayName = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("resourceTypes"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(new StorageDiscoveryResourceType(item.GetString())); + } + resourceTypes = array; + continue; + } + if (prop.NameEquals("tagKeysOnly"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString()); + } + } + tagKeysOnly = array; + continue; + } + if (prop.NameEquals("tags"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } + } + tags = dictionary; + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryScope(displayName, resourceTypes, tagKeysOnly ?? new ChangeTrackingList(), tags ?? new ChangeTrackingDictionary(), additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryScope)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryScope IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryScope PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryScope(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryScope)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.cs new file mode 100644 index 000000000000..8fd8edf7046c --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryScope.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Scope. This had added validations. + public partial class StorageDiscoveryScope + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Display name of the collection. + /// Resource types for the collection. + /// or is null. + public StorageDiscoveryScope(string displayName, IEnumerable resourceTypes) + { + Argument.AssertNotNull(displayName, nameof(displayName)); + Argument.AssertNotNull(resourceTypes, nameof(resourceTypes)); + + DisplayName = displayName; + ResourceTypes = resourceTypes.ToList(); + TagKeysOnly = new ChangeTrackingList(); + Tags = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// Display name of the collection. + /// Resource types for the collection. + /// The storage account tags keys to filter. + /// Resource tags. + /// Keeps track of any properties unknown to the library. + internal StorageDiscoveryScope(string displayName, IList resourceTypes, IList tagKeysOnly, IDictionary tags, IDictionary additionalBinaryDataProperties) + { + DisplayName = displayName; + ResourceTypes = resourceTypes; + TagKeysOnly = tagKeysOnly; + Tags = tags; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Display name of the collection. + public string DisplayName { get; set; } + + /// Resource types for the collection. + public IList ResourceTypes { get; } + + /// The storage account tags keys to filter. + public IList TagKeysOnly { get; } + + /// Resource tags. + public IDictionary Tags { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoverySku.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoverySku.cs new file mode 100644 index 000000000000..a7468abda28f --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoverySku.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Sku. + public readonly partial struct StorageDiscoverySku : IEquatable + { + private readonly string _value; + /// Standard Sku. + private const string StandardValue = "Standard"; + /// Free Sku. + private const string FreeValue = "Free"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public StorageDiscoverySku(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Standard Sku. + public static StorageDiscoverySku Standard { get; } = new StorageDiscoverySku(StandardValue); + + /// Free Sku. + public static StorageDiscoverySku Free { get; } = new StorageDiscoverySku(FreeValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(StorageDiscoverySku left, StorageDiscoverySku right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(StorageDiscoverySku left, StorageDiscoverySku right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoverySku(string value) => new StorageDiscoverySku(value); + + /// Converts a string to a . + /// The value. + public static implicit operator StorageDiscoverySku?(string value) => value == null ? null : new StorageDiscoverySku(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is StorageDiscoverySku other && Equals(other); + + /// + public bool Equals(StorageDiscoverySku other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.Serialization.cs new file mode 100644 index 000000000000..bf008a929749 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.Serialization.cs @@ -0,0 +1,177 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The response of a StorageDiscoveryWorkspace list operation. + internal partial class StorageDiscoveryWorkspaceListResult : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal StorageDiscoveryWorkspaceListResult() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceListResult)} does not support writing '{format}' format."); + } + writer.WritePropertyName("value"u8); + writer.WriteStartArray(); + foreach (StorageDiscoveryWorkspaceData item in Value) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(NextLink)) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink.AbsoluteUri); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceListResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspaceListResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceListResult)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryWorkspaceListResult(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryWorkspaceListResult DeserializeStorageDiscoveryWorkspaceListResult(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList value = default; + Uri nextLink = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("value"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(StorageDiscoveryWorkspaceData.DeserializeStorageDiscoveryWorkspaceData(item, options)); + } + value = array; + continue; + } + if (prop.NameEquals("nextLink"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nextLink = new Uri(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryWorkspaceListResult(value, nextLink, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceListResult)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceListResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspaceListResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryWorkspaceListResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceListResult)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to deserialize the from. + internal static StorageDiscoveryWorkspaceListResult FromResponse(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeStorageDiscoveryWorkspaceListResult(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.cs new file mode 100644 index 000000000000..87368290056b --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceListResult.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The response of a StorageDiscoveryWorkspace list operation. + internal partial class StorageDiscoveryWorkspaceListResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// The StorageDiscoveryWorkspace items on this page. + internal StorageDiscoveryWorkspaceListResult(IEnumerable value) + { + Value = value.ToList(); + } + + /// Initializes a new instance of . + /// The StorageDiscoveryWorkspace items on this page. + /// The link to the next page of items. + /// Keeps track of any properties unknown to the library. + internal StorageDiscoveryWorkspaceListResult(IList value, Uri nextLink, IDictionary additionalBinaryDataProperties) + { + Value = value; + NextLink = nextLink; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The StorageDiscoveryWorkspace items on this page. + public IList Value { get; } + + /// The link to the next page of items. + public Uri NextLink { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.Serialization.cs new file mode 100644 index 000000000000..063af8ce5f26 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.Serialization.cs @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The template for adding updateable properties. + public partial class StorageDiscoveryWorkspacePatch : IJsonModel + { + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePatch)} does not support writing '{format}' format."); + } + if (Optional.IsCollectionDefined(Tags)) + { + writer.WritePropertyName("tags"u8); + writer.WriteStartObject(); + foreach (var item in Tags) + { + writer.WritePropertyName(item.Key); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + if (Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryWorkspacePatch IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspacePatch JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePatch)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryWorkspacePatch(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryWorkspacePatch DeserializeStorageDiscoveryWorkspacePatch(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IDictionary tags = default; + StorageDiscoveryWorkspacePropertiesUpdate properties = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("tags"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } + } + tags = dictionary; + continue; + } + if (prop.NameEquals("properties"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = StorageDiscoveryWorkspacePropertiesUpdate.DeserializeStorageDiscoveryWorkspacePropertiesUpdate(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryWorkspacePatch(tags ?? new ChangeTrackingDictionary(), properties, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePatch)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryWorkspacePatch IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspacePatch PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryWorkspacePatch(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePatch)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + internal static RequestContent ToRequestContent(StorageDiscoveryWorkspacePatch patch) + { + if (patch == null) + { + return null; + } + Utf8JsonRequestContent content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(patch, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.cs new file mode 100644 index 000000000000..72e9011eeda3 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePatch.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The template for adding updateable properties. + public partial class StorageDiscoveryWorkspacePatch + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public StorageDiscoveryWorkspacePatch() + { + Tags = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// Resource tags. + /// The resource-specific properties for this resource. + /// Keeps track of any properties unknown to the library. + internal StorageDiscoveryWorkspacePatch(IDictionary tags, StorageDiscoveryWorkspacePropertiesUpdate properties, IDictionary additionalBinaryDataProperties) + { + Tags = tags; + Properties = properties; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Resource tags. + public IDictionary Tags { get; } + + /// The resource-specific properties for this resource. + public StorageDiscoveryWorkspacePropertiesUpdate Properties { get; set; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.Serialization.cs new file mode 100644 index 000000000000..3bc714d3280e --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.Serialization.cs @@ -0,0 +1,231 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Workspace Properties. + public partial class StorageDiscoveryWorkspaceProperties : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal StorageDiscoveryWorkspaceProperties() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceProperties)} does not support writing '{format}' format."); + } + if (Optional.IsDefined(Sku)) + { + writer.WritePropertyName("sku"u8); + writer.WriteStringValue(Sku.Value.ToString()); + } + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + writer.WritePropertyName("workspaceRoots"u8); + writer.WriteStartArray(); + foreach (ResourceIdentifier item in WorkspaceRoots) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("scopes"u8); + writer.WriteStartArray(); + foreach (StorageDiscoveryScope item in Scopes) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (options.Format != "W" && Optional.IsDefined(ProvisioningState)) + { + writer.WritePropertyName("provisioningState"u8); + writer.WriteStringValue(ProvisioningState.Value.ToString()); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspaceProperties JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceProperties)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryWorkspaceProperties(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryWorkspaceProperties DeserializeStorageDiscoveryWorkspaceProperties(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + StorageDiscoverySku? sku = default; + string description = default; + IList workspaceRoots = default; + IList scopes = default; + StorageDiscoveryProvisioningState? provisioningState = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("sku"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + sku = new StorageDiscoverySku(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("description"u8)) + { + description = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("workspaceRoots"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(new ResourceIdentifier(item.GetString())); + } + } + workspaceRoots = array; + continue; + } + if (prop.NameEquals("scopes"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(StorageDiscoveryScope.DeserializeStorageDiscoveryScope(item, options)); + } + scopes = array; + continue; + } + if (prop.NameEquals("provisioningState"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + provisioningState = new StorageDiscoveryProvisioningState(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryWorkspaceProperties( + sku, + description, + workspaceRoots, + scopes, + provisioningState, + additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceProperties)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspaceProperties PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryWorkspaceProperties(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceProperties)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.cs new file mode 100644 index 000000000000..5a10959af286 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspaceProperties.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// Storage Discovery Workspace Properties. + public partial class StorageDiscoveryWorkspaceProperties + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// The view level storage discovery data estate. + /// The scopes of the storage discovery workspace. + /// or is null. + public StorageDiscoveryWorkspaceProperties(IEnumerable workspaceRoots, IEnumerable scopes) + { + Argument.AssertNotNull(workspaceRoots, nameof(workspaceRoots)); + Argument.AssertNotNull(scopes, nameof(scopes)); + + WorkspaceRoots = workspaceRoots.ToList(); + Scopes = scopes.ToList(); + } + + /// Initializes a new instance of . + /// The storage discovery sku. + /// The description of the storage discovery workspace. + /// The view level storage discovery data estate. + /// The scopes of the storage discovery workspace. + /// The status of the last operation. + /// Keeps track of any properties unknown to the library. + internal StorageDiscoveryWorkspaceProperties(StorageDiscoverySku? sku, string description, IList workspaceRoots, IList scopes, StorageDiscoveryProvisioningState? provisioningState, IDictionary additionalBinaryDataProperties) + { + Sku = sku; + Description = description; + WorkspaceRoots = workspaceRoots; + Scopes = scopes; + ProvisioningState = provisioningState; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The storage discovery sku. + public StorageDiscoverySku? Sku { get; set; } + + /// The description of the storage discovery workspace. + public string Description { get; set; } + + /// The view level storage discovery data estate. + public IList WorkspaceRoots { get; } + + /// The scopes of the storage discovery workspace. + public IList Scopes { get; } + + /// The status of the last operation. + public StorageDiscoveryProvisioningState? ProvisioningState { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.Serialization.cs new file mode 100644 index 000000000000..1178fccbcbba --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The template for adding updateable properties. + public partial class StorageDiscoveryWorkspacePropertiesUpdate : IJsonModel + { + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePropertiesUpdate)} does not support writing '{format}' format."); + } + if (Optional.IsDefined(Sku)) + { + writer.WritePropertyName("sku"u8); + writer.WriteStringValue(Sku.Value.ToString()); + } + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (Optional.IsCollectionDefined(WorkspaceRoots)) + { + writer.WritePropertyName("workspaceRoots"u8); + writer.WriteStartArray(); + foreach (ResourceIdentifier item in WorkspaceRoots) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Scopes)) + { + writer.WritePropertyName("scopes"u8); + writer.WriteStartArray(); + foreach (StorageDiscoveryScope item in Scopes) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryWorkspacePropertiesUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspacePropertiesUpdate JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePropertiesUpdate)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryWorkspacePropertiesUpdate(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryWorkspacePropertiesUpdate DeserializeStorageDiscoveryWorkspacePropertiesUpdate(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + StorageDiscoverySku? sku = default; + string description = default; + IList workspaceRoots = default; + IList scopes = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("sku"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + sku = new StorageDiscoverySku(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("description"u8)) + { + description = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("workspaceRoots"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(new ResourceIdentifier(item.GetString())); + } + } + workspaceRoots = array; + continue; + } + if (prop.NameEquals("scopes"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(StorageDiscoveryScope.DeserializeStorageDiscoveryScope(item, options)); + } + scopes = array; + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryWorkspacePropertiesUpdate(sku, description, workspaceRoots ?? new ChangeTrackingList(), scopes ?? new ChangeTrackingList(), additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePropertiesUpdate)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryWorkspacePropertiesUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StorageDiscoveryWorkspacePropertiesUpdate PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryWorkspacePropertiesUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspacePropertiesUpdate)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.cs new file mode 100644 index 000000000000..25a621a2ca54 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/Models/StorageDiscoveryWorkspacePropertiesUpdate.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using Microsoft.StorageDiscovery; + +namespace Microsoft.StorageDiscovery.Models +{ + /// The template for adding updateable properties. + public partial class StorageDiscoveryWorkspacePropertiesUpdate + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public StorageDiscoveryWorkspacePropertiesUpdate() + { + WorkspaceRoots = new ChangeTrackingList(); + Scopes = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The storage discovery sku. + /// The description of the storage discovery workspace. + /// The view level storage discovery data estate. + /// The scopes of the storage discovery workspace. + /// Keeps track of any properties unknown to the library. + internal StorageDiscoveryWorkspacePropertiesUpdate(StorageDiscoverySku? sku, string description, IList workspaceRoots, IList scopes, IDictionary additionalBinaryDataProperties) + { + Sku = sku; + Description = description; + WorkspaceRoots = workspaceRoots; + Scopes = scopes; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The storage discovery sku. + public StorageDiscoverySku? Sku { get; set; } + + /// The description of the storage discovery workspace. + public string Description { get; set; } + + /// The view level storage discovery data estate. + public IList WorkspaceRoots { get; } + + /// The scopes of the storage discovery workspace. + public IList Scopes { get; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/ProviderConstants.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/ProviderConstants.cs new file mode 100644 index 000000000000..fcf69c0f56b3 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/ProviderConstants.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core.Pipeline; + +namespace Microsoft.StorageDiscovery +{ + internal static partial class ProviderConstants + { + /// Gets the DefaultProviderNamespace. + public static string DefaultProviderNamespace { get; } = ClientDiagnostics.GetResourceProviderNamespace(typeof(ProviderConstants).Assembly); + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/RestOperations/StorageDiscoveryWorkspacesRestOperations.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/RestOperations/StorageDiscoveryWorkspacesRestOperations.cs new file mode 100644 index 000000000000..c03235f3d519 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/RestOperations/StorageDiscoveryWorkspacesRestOperations.cs @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryWorkspaces + { + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of StorageDiscoveryWorkspaces for mocking. + protected StorageDiscoveryWorkspaces() + { + } + + /// Initializes a new instance of StorageDiscoveryWorkspaces. + /// The ClientDiagnostics is used to provide tracing support for the client library. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// Service endpoint. + /// + internal StorageDiscoveryWorkspaces(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _endpoint = endpoint; + Pipeline = pipeline; + _apiVersion = apiVersion; + } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline { get; } + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + internal HttpMessage CreateGetRequest(Guid subscriptionId, string resourceGroupName, string storageDiscoveryWorkspaceName, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces/", false); + uri.AppendPath(storageDiscoveryWorkspaceName, true); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Get; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCreateOrUpdateRequest(Guid subscriptionId, string resourceGroupName, string storageDiscoveryWorkspaceName, RequestContent content, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces/", false); + uri.AppendPath(storageDiscoveryWorkspaceName, true); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Put; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateUpdateRequest(Guid subscriptionId, string resourceGroupName, string storageDiscoveryWorkspaceName, RequestContent content, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces/", false); + uri.AppendPath(storageDiscoveryWorkspaceName, true); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Patch; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateDeleteRequest(Guid subscriptionId, string resourceGroupName, string storageDiscoveryWorkspaceName, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces/", false); + uri.AppendPath(storageDiscoveryWorkspaceName, true); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Delete; + return message; + } + + internal HttpMessage CreateGetByResourceGroupRequest(Guid subscriptionId, string resourceGroupName, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces", false); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Get; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateNextGetByResourceGroupRequest(Uri nextPage, Guid subscriptionId, string resourceGroupName, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(nextPage); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Get; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetBySubscriptionRequest(Guid subscriptionId, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId.ToString(), true); + uri.AppendPath("/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces", false); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Get; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateNextGetBySubscriptionRequest(Uri nextPage, Guid subscriptionId, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(nextPage); + HttpMessage message = Pipeline.CreateMessage(); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Get; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceCollection.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceCollection.cs new file mode 100644 index 000000000000..52f88b1e6afc --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceCollection.cs @@ -0,0 +1,414 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Microsoft.StorageDiscovery +{ + /// + /// A class representing a collection of and their operations. + /// Each in the collection will belong to the same instance of a parent resource (TODO: add parent resource information). + /// To get a instance call the GetStorageDiscoveryWorkspaces method from an instance of the parent resource. + /// + public partial class StorageDiscoveryWorkspaceCollection : ArmCollection, IEnumerable, IAsyncEnumerable + { + private readonly ClientDiagnostics _storageDiscoveryWorkspacesClientDiagnostics; + private readonly StorageDiscoveryWorkspaces _storageDiscoveryWorkspacesRestClient; + + /// Initializes a new instance of StorageDiscoveryWorkspaceCollection for mocking. + protected StorageDiscoveryWorkspaceCollection() + { + } + + /// 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. + internal StorageDiscoveryWorkspaceCollection(ArmClient client, ResourceIdentifier id) : base(client, id) + { + TryGetApiVersion(StorageDiscoveryWorkspaceResource.ResourceType, out string storageDiscoveryWorkspaceApiVersion); + _storageDiscoveryWorkspacesClientDiagnostics = new ClientDiagnostics("Microsoft.StorageDiscovery", StorageDiscoveryWorkspaceResource.ResourceType.Namespace, Diagnostics); + _storageDiscoveryWorkspacesRestClient = new StorageDiscoveryWorkspaces(_storageDiscoveryWorkspacesClientDiagnostics, Pipeline, Endpoint, storageDiscoveryWorkspaceApiVersion ?? "2025-09-01"); + ValidateResourceId(id); + } + + /// + [Conditional("DEBUG")] + internal static void ValidateResourceId(ResourceIdentifier id) + { + if (id.ResourceType != ResourceGroupResource.ResourceType) + { + throw new ArgumentException(string.Format("Invalid resource type {0} expected {1}", id.ResourceType, ResourceGroupResource.ResourceType), id); + } + } + + /// Create a StorageDiscoveryWorkspace. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The name of the StorageDiscoveryWorkspace. + /// Resource create parameters. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateOrUpdateAsync(WaitUntil waitUntil, string storageDiscoveryWorkspaceName, StorageDiscoveryWorkspaceData data, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + Argument.AssertNotNull(data, nameof(data)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.CreateOrUpdate"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateCreateOrUpdateRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, StorageDiscoveryWorkspaceData.ToRequestContent(data), context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + RequestUriBuilder uri = message.Request.Uri; + RehydrationToken rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Put, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); + StorageDiscoveryArmOperation operation = new StorageDiscoveryArmOperation(Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()), rehydrationToken); + if (waitUntil == WaitUntil.Completed) + { + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); + } + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Create a StorageDiscoveryWorkspace. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The name of the StorageDiscoveryWorkspace. + /// Resource create parameters. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual ArmOperation CreateOrUpdate(WaitUntil waitUntil, string storageDiscoveryWorkspaceName, StorageDiscoveryWorkspaceData data, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + Argument.AssertNotNull(data, nameof(data)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.CreateOrUpdate"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateCreateOrUpdateRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, StorageDiscoveryWorkspaceData.ToRequestContent(data), context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + RequestUriBuilder uri = message.Request.Uri; + RehydrationToken rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Put, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); + StorageDiscoveryArmOperation operation = new StorageDiscoveryArmOperation(Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()), rehydrationToken); + if (waitUntil == WaitUntil.Completed) + { + operation.WaitForCompletion(cancellationToken); + } + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a StorageDiscoveryWorkspace. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetAsync(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.Get"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a StorageDiscoveryWorkspace. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response Get(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.Get"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// List StorageDiscoveryWorkspace resources by resource group. + /// The cancellation token to use. + /// A collection of that may take multiple service requests to iterate over. + public virtual AsyncPageable GetAllAsync(CancellationToken cancellationToken = default) + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + return new AsyncPageableWrapper(new StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT(_storageDiscoveryWorkspacesRestClient, Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, context), data => new StorageDiscoveryWorkspaceResource(Client, data)); + } + + /// List StorageDiscoveryWorkspace resources by resource group. + /// The cancellation token to use. + /// A collection of that may take multiple service requests to iterate over. + public virtual Pageable GetAll(CancellationToken cancellationToken = default) + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + return new PageableWrapper(new StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT(_storageDiscoveryWorkspacesRestClient, Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, context), data => new StorageDiscoveryWorkspaceResource(Client, data)); + } + + /// Checks to see if the resource exists in azure. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> ExistsAsync(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.Exists"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + await Pipeline.SendAsync(message, context.CancellationToken).ConfigureAwait(false); + Response result = message.Response; + Response response = default; + switch (result.Status) + { + case 200: + response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + break; + case 404: + response = Response.FromValue((StorageDiscoveryWorkspaceData)null, result); + break; + default: + throw new RequestFailedException(result); + } + return Response.FromValue(response.Value != null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Checks to see if the resource exists in azure. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response Exists(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.Exists"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + Pipeline.Send(message, context.CancellationToken); + Response result = message.Response; + Response response = default; + switch (result.Status) + { + case 200: + response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + break; + case 404: + response = Response.FromValue((StorageDiscoveryWorkspaceData)null, result); + break; + default: + throw new RequestFailedException(result); + } + return Response.FromValue(response.Value != null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Tries to get details for this resource from the service. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetIfExistsAsync(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.GetIfExists"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + await Pipeline.SendAsync(message, context.CancellationToken).ConfigureAwait(false); + Response result = message.Response; + Response response = default; + switch (result.Status) + { + case 200: + response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + break; + case 404: + response = Response.FromValue((StorageDiscoveryWorkspaceData)null, result); + break; + default: + throw new RequestFailedException(result); + } + if (response.Value == null) + { + return new NoValueResponse(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Tries to get details for this resource from the service. + /// The name of the StorageDiscoveryWorkspace. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual NullableResponse GetIfExists(string storageDiscoveryWorkspaceName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(storageDiscoveryWorkspaceName, nameof(storageDiscoveryWorkspaceName)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.GetIfExists"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, storageDiscoveryWorkspaceName, context); + Pipeline.Send(message, context.CancellationToken); + Response result = message.Response; + Response response = default; + switch (result.Status) + { + case 200: + response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + break; + case 404: + response = Response.FromValue((StorageDiscoveryWorkspaceData)null, result); + break; + default: + throw new RequestFailedException(result); + } + if (response.Value == null) + { + return new NoValueResponse(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetAll().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetAll().GetEnumerator(); + } + + /// The cancellation token to use. + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + { + return GetAllAsync(cancellationToken: cancellationToken).GetAsyncEnumerator(cancellationToken); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.Serialization.cs new file mode 100644 index 000000000000..cd4fe0aa3adf --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.Serialization.cs @@ -0,0 +1,232 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using Azure; +using Azure.Core; +using Azure.ResourceManager.Models; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + /// A Storage Discovery Workspace resource. This resource configures the collection of storage account metrics. + public partial class StorageDiscoveryWorkspaceData : TrackedResourceData, IJsonModel + { + /// Initializes a new instance of for deserialization. + internal StorageDiscoveryWorkspaceData() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceData)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceData IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (StorageDiscoveryWorkspaceData)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual ResourceData JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceData)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStorageDiscoveryWorkspaceData(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static StorageDiscoveryWorkspaceData DeserializeStorageDiscoveryWorkspaceData(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + ResourceType resourceType = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + IDictionary tags = default; + AzureLocation location = default; + StorageDiscoveryWorkspaceProperties properties = default; + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + resourceType = new ResourceType(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = ModelReaderWriter.Read(new BinaryData(Encoding.UTF8.GetBytes(prop.Value.GetRawText())), ModelSerializationExtensions.WireOptions, MicrosoftStorageDiscoveryContext.Default); + continue; + } + if (prop.NameEquals("tags"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } + } + tags = dictionary; + continue; + } + if (prop.NameEquals("location"u8)) + { + location = new AzureLocation(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("properties"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = StorageDiscoveryWorkspaceProperties.DeserializeStorageDiscoveryWorkspaceProperties(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StorageDiscoveryWorkspaceData( + id, + name, + resourceType, + systemData, + additionalBinaryDataProperties, + tags ?? new ChangeTrackingDictionary(), + location, + properties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftStorageDiscoveryContext.Default); + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceData)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceData IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (StorageDiscoveryWorkspaceData)PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual ResourceData PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStorageDiscoveryWorkspaceData(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StorageDiscoveryWorkspaceData)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + internal static RequestContent ToRequestContent(StorageDiscoveryWorkspaceData storageDiscoveryWorkspaceData) + { + if (storageDiscoveryWorkspaceData == null) + { + return null; + } + Utf8JsonRequestContent content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(storageDiscoveryWorkspaceData, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + internal static StorageDiscoveryWorkspaceData FromResponse(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeStorageDiscoveryWorkspaceData(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.cs new file mode 100644 index 000000000000..f4d366ecb32d --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceData.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using Azure.ResourceManager.Models; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + /// A Storage Discovery Workspace resource. This resource configures the collection of storage account metrics. + public partial class StorageDiscoveryWorkspaceData : TrackedResourceData + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// The geo-location where the resource lives. + public StorageDiscoveryWorkspaceData(AzureLocation location) : base(location) + { + } + + /// Initializes a new instance of . + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// Keeps track of any properties unknown to the library. + /// Resource tags. + /// The geo-location where the resource lives. + /// The resource-specific properties for this resource. + internal StorageDiscoveryWorkspaceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary additionalBinaryDataProperties, IDictionary tags, AzureLocation location, StorageDiscoveryWorkspaceProperties properties) : base(id, name, resourceType, systemData, tags, location) + { + _additionalBinaryDataProperties = additionalBinaryDataProperties; + Properties = properties; + } + + /// The resource-specific properties for this resource. + public StorageDiscoveryWorkspaceProperties Properties { get; set; } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.Serialization.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.Serialization.cs new file mode 100644 index 000000000000..f53815a78090 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.Serialization.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace Microsoft.StorageDiscovery +{ + /// + public partial class StorageDiscoveryWorkspaceResource : IJsonModel + { + private static IJsonModel s_dataDeserializationInstance; + + private static IJsonModel DataDeserializationInstance => s_dataDeserializationInstance ??= new StorageDiscoveryWorkspaceData(); + + /// The writer to serialize the model to. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => ((IJsonModel)Data).Write(writer, options); + + /// The reader for deserializing the model. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceData IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => DataDeserializationInstance.Create(ref reader, options); + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => ModelReaderWriter.Write(Data, options, MicrosoftStorageDiscoveryContext.Default); + + /// The binary data to be processed. + /// The client options for reading and writing models. + StorageDiscoveryWorkspaceData IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => ModelReaderWriter.Read(data, options, MicrosoftStorageDiscoveryContext.Default); + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => DataDeserializationInstance.GetFormatFromOptions(options); + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.cs new file mode 100644 index 000000000000..107dce6d67d4 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspaceResource.cs @@ -0,0 +1,552 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + /// + /// A class representing a StorageDiscoveryWorkspace along with the instance operations that can be performed on it. + /// If you have a you can construct a from an instance of using the GetResource method. + /// Otherwise you can get one from its parent resource using the GetStorageDiscoveryWorkspaces method. + /// + public partial class StorageDiscoveryWorkspaceResource : ArmResource + { + private readonly ClientDiagnostics _storageDiscoveryWorkspacesClientDiagnostics; + private readonly StorageDiscoveryWorkspaces _storageDiscoveryWorkspacesRestClient; + private readonly StorageDiscoveryWorkspaceData _data; + /// Gets the resource type for the operations. + public static readonly ResourceType ResourceType = "Microsoft.StorageDiscovery/storageDiscoveryWorkspaces"; + + /// Initializes a new instance of StorageDiscoveryWorkspaceResource for mocking. + protected StorageDiscoveryWorkspaceResource() + { + } + + /// Initializes a new instance of class. + /// The client parameters to use in these operations. + /// The resource that is the target of operations. + internal StorageDiscoveryWorkspaceResource(ArmClient client, StorageDiscoveryWorkspaceData data) : this(client, data.Id) + { + HasData = true; + _data = data; + } + + /// 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. + internal StorageDiscoveryWorkspaceResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + TryGetApiVersion(ResourceType, out string storageDiscoveryWorkspaceApiVersion); + _storageDiscoveryWorkspacesClientDiagnostics = new ClientDiagnostics("Microsoft.StorageDiscovery", ResourceType.Namespace, Diagnostics); + _storageDiscoveryWorkspacesRestClient = new StorageDiscoveryWorkspaces(_storageDiscoveryWorkspacesClientDiagnostics, Pipeline, Endpoint, storageDiscoveryWorkspaceApiVersion ?? "2025-09-01"); + ValidateResourceId(id); + } + + /// Gets whether or not the current instance has data. + public virtual bool HasData { get; } + + /// Gets the data representing this Feature. + public virtual StorageDiscoveryWorkspaceData Data + { + get + { + if (!HasData) + { + throw new InvalidOperationException("The current instance does not have data, you must call Get first."); + } + return _data; + } + } + + /// Generate the resource identifier for this resource. + /// The subscriptionId. + /// The resourceGroupName. + /// The storageDiscoveryWorkspaceName. + public static ResourceIdentifier CreateResourceIdentifier(string subscriptionId, string resourceGroupName, string storageDiscoveryWorkspaceName) + { + string resourceId = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageDiscovery/storageDiscoveryWorkspaces/{storageDiscoveryWorkspaceName}"; + return new ResourceIdentifier(resourceId); + } + + /// + [Conditional("DEBUG")] + internal static void ValidateResourceId(ResourceIdentifier id) + { + if (id.ResourceType != ResourceType) + { + throw new ArgumentException(string.Format("Invalid resource type {0} expected {1}", id.ResourceType, ResourceType), id); + } + } + + /// Get a StorageDiscoveryWorkspace. + /// The cancellation token to use. + public virtual async Task> GetAsync(CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Get"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get a StorageDiscoveryWorkspace. + /// The cancellation token to use. + public virtual Response Get(CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Get"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Update a StorageDiscoveryWorkspace. + /// The resource properties to be updated. + /// The cancellation token to use. + /// is null. + public virtual async Task> UpdateAsync(StorageDiscoveryWorkspacePatch patch, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(patch, nameof(patch)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Update"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateUpdateRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, StorageDiscoveryWorkspacePatch.ToRequestContent(patch), context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Update a StorageDiscoveryWorkspace. + /// The resource properties to be updated. + /// The cancellation token to use. + /// is null. + public virtual Response Update(StorageDiscoveryWorkspacePatch patch, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(patch, nameof(patch)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Update"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateUpdateRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, StorageDiscoveryWorkspacePatch.ToRequestContent(patch), context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + if (response.Value == null) + { + throw new RequestFailedException(response.GetRawResponse()); + } + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Delete a StorageDiscoveryWorkspace. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The cancellation token to use. + public virtual async Task DeleteAsync(WaitUntil waitUntil, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Delete"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateDeleteRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response response = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + RequestUriBuilder uri = message.Request.Uri; + RehydrationToken rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Delete, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); + StorageDiscoveryArmOperation operation = new StorageDiscoveryArmOperation(response, rehydrationToken); + if (waitUntil == WaitUntil.Completed) + { + await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + } + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Delete a StorageDiscoveryWorkspace. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The cancellation token to use. + public virtual ArmOperation Delete(WaitUntil waitUntil, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.Delete"); + scope.Start(); + try + { + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateDeleteRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response response = Pipeline.ProcessMessage(message, context); + RequestUriBuilder uri = message.Request.Uri; + RehydrationToken rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Delete, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); + StorageDiscoveryArmOperation operation = new StorageDiscoveryArmOperation(response, rehydrationToken); + if (waitUntil == WaitUntil.Completed) + { + operation.WaitForCompletionResponse(cancellationToken); + } + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Add a tag to the current resource. + /// The key for the tag. + /// The value for the tag. + /// The cancellation token to use. + /// or is null. + public virtual async Task> AddTagAsync(string key, string value, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(key, nameof(key)); + Argument.AssertNotNull(value, nameof(value)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.AddTag"); + scope.Start(); + try + { + if (await CanUseTagResourceAsync(cancellationToken).ConfigureAwait(false)) + { + Response originalTags = await GetTagResource().GetAsync(cancellationToken).ConfigureAwait(false); + originalTags.Value.Data.TagValues[key] = value; + await GetTagResource().CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken).ConfigureAwait(false); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = (await GetAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + foreach (KeyValuePair tag in current.Tags) + { + patch.Tags.Add(tag); + } + patch.Tags[key] = value; + Response result = await UpdateAsync(patch, cancellationToken).ConfigureAwait(false); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Add a tag to the current resource. + /// The key for the tag. + /// The value for the tag. + /// The cancellation token to use. + /// or is null. + public virtual Response AddTag(string key, string value, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(key, nameof(key)); + Argument.AssertNotNull(value, nameof(value)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.AddTag"); + scope.Start(); + try + { + if (CanUseTagResource(cancellationToken)) + { + Response originalTags = GetTagResource().Get(cancellationToken); + originalTags.Value.Data.TagValues[key] = value; + GetTagResource().CreateOrUpdate(WaitUntil.Completed, originalTags.Value.Data, cancellationToken); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = Get(cancellationToken: cancellationToken).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + foreach (KeyValuePair tag in current.Tags) + { + patch.Tags.Add(tag); + } + patch.Tags[key] = value; + Response result = Update(patch, cancellationToken); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Replace the tags on the resource with the given set. + /// The tags to set on the resource. + /// The cancellation token to use. + /// is null. + public virtual async Task> SetTagsAsync(IDictionary tags, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(tags, nameof(tags)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.SetTags"); + scope.Start(); + try + { + if (await CanUseTagResourceAsync(cancellationToken).ConfigureAwait(false)) + { + await GetTagResource().DeleteAsync(WaitUntil.Completed, cancellationToken).ConfigureAwait(false); + Response originalTags = await GetTagResource().GetAsync(cancellationToken).ConfigureAwait(false); + originalTags.Value.Data.TagValues.ReplaceWith(tags); + await GetTagResource().CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken).ConfigureAwait(false); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = (await GetAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + patch.Tags.ReplaceWith(tags); + Response result = await UpdateAsync(patch, cancellationToken).ConfigureAwait(false); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Replace the tags on the resource with the given set. + /// The tags to set on the resource. + /// The cancellation token to use. + /// is null. + public virtual Response SetTags(IDictionary tags, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(tags, nameof(tags)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.SetTags"); + scope.Start(); + try + { + if (CanUseTagResource(cancellationToken)) + { + GetTagResource().Delete(WaitUntil.Completed, cancellationToken); + Response originalTags = GetTagResource().Get(cancellationToken); + originalTags.Value.Data.TagValues.ReplaceWith(tags); + GetTagResource().CreateOrUpdate(WaitUntil.Completed, originalTags.Value.Data, cancellationToken); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = Get(cancellationToken: cancellationToken).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + patch.Tags.ReplaceWith(tags); + Response result = Update(patch, cancellationToken); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Removes a tag by key from the resource. + /// The key for the tag. + /// The cancellation token to use. + /// is null. + public virtual async Task> RemoveTagAsync(string key, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(key, nameof(key)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.RemoveTag"); + scope.Start(); + try + { + if (await CanUseTagResourceAsync(cancellationToken).ConfigureAwait(false)) + { + Response originalTags = await GetTagResource().GetAsync(cancellationToken).ConfigureAwait(false); + originalTags.Value.Data.TagValues.Remove(key); + await GetTagResource().CreateOrUpdateAsync(WaitUntil.Completed, originalTags.Value.Data, cancellationToken).ConfigureAwait(false); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = (await GetAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + foreach (KeyValuePair tag in current.Tags) + { + patch.Tags.Add(tag); + } + patch.Tags.Remove(key); + Response result = await UpdateAsync(patch, cancellationToken).ConfigureAwait(false); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Removes a tag by key from the resource. + /// The key for the tag. + /// The cancellation token to use. + /// is null. + public virtual Response RemoveTag(string key, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(key, nameof(key)); + + using DiagnosticScope scope = _storageDiscoveryWorkspacesClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceResource.RemoveTag"); + scope.Start(); + try + { + if (CanUseTagResource(cancellationToken)) + { + Response originalTags = GetTagResource().Get(cancellationToken); + originalTags.Value.Data.TagValues.Remove(key); + GetTagResource().CreateOrUpdate(WaitUntil.Completed, originalTags.Value.Data, cancellationToken); + RequestContext context = new RequestContext + { + CancellationToken = cancellationToken + }; + HttpMessage message = _storageDiscoveryWorkspacesRestClient.CreateGetRequest(Guid.Parse(Id.SubscriptionId), Id.ResourceGroupName, Id.Name, context); + Response result = Pipeline.ProcessMessage(message, context); + Response response = Response.FromValue(StorageDiscoveryWorkspaceData.FromResponse(result), result); + return Response.FromValue(new StorageDiscoveryWorkspaceResource(Client, response.Value), response.GetRawResponse()); + } + else + { + StorageDiscoveryWorkspaceData current = Get(cancellationToken: cancellationToken).Value.Data; + StorageDiscoveryWorkspacePatch patch = new StorageDiscoveryWorkspacePatch(); + foreach (KeyValuePair tag in current.Tags) + { + patch.Tags.Add(tag); + } + patch.Tags.Remove(key); + Response result = Update(patch, cancellationToken); + return Response.FromValue(result.Value, result.GetRawResponse()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT.cs new file mode 100644 index 000000000000..6431668bfbe3 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT : AsyncPageable + { + private readonly StorageDiscoveryWorkspaces _client; + private readonly Guid _subscriptionId; + private readonly string _resourceGroupName; + private readonly RequestContext _context; + + /// Initializes a new instance of StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT, which is used to iterate over the pages of a collection. + /// The StorageDiscoveryWorkspaces client used to send requests. + /// The ID of the target subscription. The value must be an UUID. + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + public StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT(StorageDiscoveryWorkspaces client, Guid subscriptionId, string resourceGroupName, RequestContext context) : base(context?.CancellationToken ?? default) + { + Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); + + _client = client; + _subscriptionId = subscriptionId; + _resourceGroupName = resourceGroupName; + _context = context; + } + + /// Gets the pages of StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT as an enumerable collection. + /// A continuation token indicating where to resume paging. + /// The number of items per page. + /// The pages of StorageDiscoveryWorkspacesGetByResourceGroupAsyncCollectionResultOfT as an enumerable collection. + public override async IAsyncEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + Uri nextPage = continuationToken != null ? new Uri(continuationToken) : null; + while (true) + { + Response response = await GetNextResponseAsync(pageSizeHint, nextPage).ConfigureAwait(false); + if (response is null) + { + yield break; + } + StorageDiscoveryWorkspaceListResult result = StorageDiscoveryWorkspaceListResult.FromResponse(response); + yield return Page.FromValues((IReadOnlyList)result.Value, nextPage?.AbsoluteUri, response); + nextPage = result.NextLink; + if (nextPage == null) + { + yield break; + } + } + } + + /// Get next page. + /// The number of items per page. + /// The next link to use for the next page of results. + private async ValueTask GetNextResponseAsync(int? pageSizeHint, Uri nextLink) + { + HttpMessage message = nextLink != null ? _client.CreateNextGetByResourceGroupRequest(nextLink, _subscriptionId, _resourceGroupName, _context) : _client.CreateGetByResourceGroupRequest(_subscriptionId, _resourceGroupName, _context); + using DiagnosticScope scope = _client.ClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.GetAll"); + scope.Start(); + try + { + return await _client.Pipeline.ProcessMessageAsync(message, _context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT.cs new file mode 100644 index 000000000000..f888b14d5087 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT : Pageable + { + private readonly StorageDiscoveryWorkspaces _client; + private readonly Guid _subscriptionId; + private readonly string _resourceGroupName; + private readonly RequestContext _context; + + /// Initializes a new instance of StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT, which is used to iterate over the pages of a collection. + /// The StorageDiscoveryWorkspaces client used to send requests. + /// The ID of the target subscription. The value must be an UUID. + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// is an empty string, and was expected to be non-empty. + public StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT(StorageDiscoveryWorkspaces client, Guid subscriptionId, string resourceGroupName, RequestContext context) : base(context?.CancellationToken ?? default) + { + Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); + + _client = client; + _subscriptionId = subscriptionId; + _resourceGroupName = resourceGroupName; + _context = context; + } + + /// Gets the pages of StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT as an enumerable collection. + /// A continuation token indicating where to resume paging. + /// The number of items per page. + /// The pages of StorageDiscoveryWorkspacesGetByResourceGroupCollectionResultOfT as an enumerable collection. + public override IEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + Uri nextPage = continuationToken != null ? new Uri(continuationToken) : null; + while (true) + { + Response response = GetNextResponse(pageSizeHint, nextPage); + if (response is null) + { + yield break; + } + StorageDiscoveryWorkspaceListResult result = StorageDiscoveryWorkspaceListResult.FromResponse(response); + yield return Page.FromValues((IReadOnlyList)result.Value, nextPage?.AbsoluteUri, response); + nextPage = result.NextLink; + if (nextPage == null) + { + yield break; + } + } + } + + /// Get next page. + /// The number of items per page. + /// The next link to use for the next page of results. + private Response GetNextResponse(int? pageSizeHint, Uri nextLink) + { + HttpMessage message = nextLink != null ? _client.CreateNextGetByResourceGroupRequest(nextLink, _subscriptionId, _resourceGroupName, _context) : _client.CreateGetByResourceGroupRequest(_subscriptionId, _resourceGroupName, _context); + using DiagnosticScope scope = _client.ClientDiagnostics.CreateScope("StorageDiscoveryWorkspaceCollection.GetAll"); + scope.Start(); + try + { + return _client.Pipeline.ProcessMessage(message, _context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT.cs new file mode 100644 index 000000000000..7a25650019e2 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT : AsyncPageable + { + private readonly StorageDiscoveryWorkspaces _client; + private readonly Guid _subscriptionId; + private readonly RequestContext _context; + + /// Initializes a new instance of StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT, which is used to iterate over the pages of a collection. + /// The StorageDiscoveryWorkspaces client used to send requests. + /// The ID of the target subscription. The value must be an UUID. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + public StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT(StorageDiscoveryWorkspaces client, Guid subscriptionId, RequestContext context) : base(context?.CancellationToken ?? default) + { + _client = client; + _subscriptionId = subscriptionId; + _context = context; + } + + /// Gets the pages of StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT as an enumerable collection. + /// A continuation token indicating where to resume paging. + /// The number of items per page. + /// The pages of StorageDiscoveryWorkspacesGetBySubscriptionAsyncCollectionResultOfT as an enumerable collection. + public override async IAsyncEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + Uri nextPage = continuationToken != null ? new Uri(continuationToken) : null; + while (true) + { + Response response = await GetNextResponseAsync(pageSizeHint, nextPage).ConfigureAwait(false); + if (response is null) + { + yield break; + } + StorageDiscoveryWorkspaceListResult result = StorageDiscoveryWorkspaceListResult.FromResponse(response); + yield return Page.FromValues((IReadOnlyList)result.Value, nextPage?.AbsoluteUri, response); + nextPage = result.NextLink; + if (nextPage == null) + { + yield break; + } + } + } + + /// Get next page. + /// The number of items per page. + /// The next link to use for the next page of results. + private async ValueTask GetNextResponseAsync(int? pageSizeHint, Uri nextLink) + { + HttpMessage message = nextLink != null ? _client.CreateNextGetBySubscriptionRequest(nextLink, _subscriptionId, _context) : _client.CreateGetBySubscriptionRequest(_subscriptionId, _context); + using DiagnosticScope scope = _client.ClientDiagnostics.CreateScope("MockableMicrosoftStorageDiscoverySubscriptionResource.GetStorageDiscoveryWorkspaces"); + scope.Start(); + try + { + return await _client.Pipeline.ProcessMessageAsync(message, _context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT.cs b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT.cs new file mode 100644 index 000000000000..0538f1b7d3d0 --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Generated/StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Microsoft.StorageDiscovery.Models; + +namespace Microsoft.StorageDiscovery +{ + internal partial class StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT : Pageable + { + private readonly StorageDiscoveryWorkspaces _client; + private readonly Guid _subscriptionId; + private readonly RequestContext _context; + + /// Initializes a new instance of StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT, which is used to iterate over the pages of a collection. + /// The StorageDiscoveryWorkspaces client used to send requests. + /// The ID of the target subscription. The value must be an UUID. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + public StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT(StorageDiscoveryWorkspaces client, Guid subscriptionId, RequestContext context) : base(context?.CancellationToken ?? default) + { + _client = client; + _subscriptionId = subscriptionId; + _context = context; + } + + /// Gets the pages of StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT as an enumerable collection. + /// A continuation token indicating where to resume paging. + /// The number of items per page. + /// The pages of StorageDiscoveryWorkspacesGetBySubscriptionCollectionResultOfT as an enumerable collection. + public override IEnumerable> AsPages(string continuationToken, int? pageSizeHint) + { + Uri nextPage = continuationToken != null ? new Uri(continuationToken) : null; + while (true) + { + Response response = GetNextResponse(pageSizeHint, nextPage); + if (response is null) + { + yield break; + } + StorageDiscoveryWorkspaceListResult result = StorageDiscoveryWorkspaceListResult.FromResponse(response); + yield return Page.FromValues((IReadOnlyList)result.Value, nextPage?.AbsoluteUri, response); + nextPage = result.NextLink; + if (nextPage == null) + { + yield break; + } + } + } + + /// Get next page. + /// The number of items per page. + /// The next link to use for the next page of results. + private Response GetNextResponse(int? pageSizeHint, Uri nextLink) + { + HttpMessage message = nextLink != null ? _client.CreateNextGetBySubscriptionRequest(nextLink, _subscriptionId, _context) : _client.CreateGetBySubscriptionRequest(_subscriptionId, _context); + using DiagnosticScope scope = _client.ClientDiagnostics.CreateScope("MockableMicrosoftStorageDiscoverySubscriptionResource.GetStorageDiscoveryWorkspaces"); + scope.Start(); + try + { + return _client.Pipeline.ProcessMessage(message, _context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/@azure-typespec/http-client-csharp-mgmt/src/Microsoft.StorageDiscovery.csproj b/@azure-typespec/http-client-csharp-mgmt/src/Microsoft.StorageDiscovery.csproj new file mode 100644 index 000000000000..3440d6971c3f --- /dev/null +++ b/@azure-typespec/http-client-csharp-mgmt/src/Microsoft.StorageDiscovery.csproj @@ -0,0 +1,31 @@ + + + This is the Microsoft.StorageDiscovery client library for developing .NET applications with rich experience. + SDK Code Generation Microsoft.StorageDiscovery + 1.0.0-beta.1 + Microsoft.StorageDiscovery + true + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/storagediscovery/Azure.ResourceManager.StorageDiscovery/tsp-location.yaml b/sdk/storagediscovery/Azure.ResourceManager.StorageDiscovery/tsp-location.yaml index 6c6ffc181134..706d3fb8819e 100644 --- a/sdk/storagediscovery/Azure.ResourceManager.StorageDiscovery/tsp-location.yaml +++ b/sdk/storagediscovery/Azure.ResourceManager.StorageDiscovery/tsp-location.yaml @@ -1,4 +1,6 @@ directory: specification/storagediscovery/Microsoft.StorageDiscovery.Management -commit: 930e8030f5058d947fea4e2640725baab8a4561a +commit: c55f9f1458e736f79703a72ee5c9a4caf242a85b repo: Azure/azure-rest-api-specs -emitterPackageJsonPath: "eng/azure-typespec-http-client-csharp-mgmt-emitter-package.json" +additionalDirectories: + +emitterPackageJsonPath: eng/azure-typespec-http-client-csharp-mgmt-emitter-package.json \ No newline at end of file