diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs index 62d0eefc945fa..8733d210589bd 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs @@ -14,9 +14,9 @@ namespace Azure.ResourceManager.Core /// The type of the class containing operations for the underlying resource. /// The type of the class containing properties for the underlying resource. public abstract class ResourceContainerBase : ContainerBase - where TOperations : ResourceOperationsBase - where TResource : Resource where TIdentifier : TenantResourceIdentifier + where TOperations : ResourceOperationsBase + where TResource : class { private static readonly object _parentLock = new object(); private object _parentResource; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs new file mode 100644 index 0000000000000..764903ec81717 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing a sub-resource that contains only the ID. + /// + public partial class SubResource : IUtf8JsonSerializable + { + /// + /// Serialize the input SubResource object. + /// + /// Input Json writer. + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + if (writer is null) + { + throw new ArgumentNullException(nameof(writer)); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"); + writer.WriteStringValue(Id); + } + writer.WriteEndObject(); + } + + /// + /// Deserialize the input JSON element to a SubResource object. + /// + /// The JSON element to be deserialized. + /// Deserialized SubResource object. + internal static SubResource DeserializeSubResource(JsonElement element) + { + Optional id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + id = property.Value.GetString(); + continue; + } + } + return new SubResource(id.Value); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs new file mode 100644 index 0000000000000..234ec575f3bb6 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing a sub-resource that contains only the ID. + /// + [ReferenceType] + public partial class SubResource + { + /// Initializes a new instance of SubResource. + /// ARM resource Id. + protected internal SubResource(string id) + { + Id = id; + } + + /// + /// ARM resource identifier. + /// + /// + public virtual ResourceIdentifier Id { get; set; } + } +} + +// Todo: we want to make the default one (SubResource) to represent read-only data, +// that is the pattern we used in Resource and TrackedResource diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.Serialization.cs new file mode 100644 index 0000000000000..73da313642c81 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.Serialization.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing a sub-resource that contains only the ID. + /// + public partial class SubResourceReadOnly : IUtf8JsonSerializable + { + /// + /// Serialize the input SubResourceReadOnly object. + /// + /// Input Json writer. + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + if (writer is null) + { + throw new ArgumentNullException(nameof(writer)); + } + + writer.WriteStartObject(); + writer.WriteEndObject(); + } + + /// + /// Deserialize the input JSON element to a SubResourceReadOnly object. + /// + /// The JSON element to be deserialized. + /// Deserialized SubResourceReadOnly object. + internal static SubResourceReadOnly DeserializeSubResourceReadOnly(JsonElement element) + { + Optional id = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + id = property.Value.GetString(); + continue; + } + } + return new SubResourceReadOnly(id.Value); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.cs new file mode 100644 index 0000000000000..d5df3191eea71 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing a sub-resource that contains only the read-only ID. + /// + [ReferenceType] + public partial class SubResourceReadOnly + { + /// Initializes a new instance of SubResourceReadOnly. + /// ARM resource Id. + protected internal SubResourceReadOnly(string id) + { + Id = id; + } + + /// + /// ARM resource identifier (read-only). + /// + /// + public virtual ResourceIdentifier Id { get; protected set; } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/AvailabilitySetData.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/AvailabilitySetData.cs index 389823a644712..344e3b119c8de 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Placeholder/AvailabilitySetData.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/AvailabilitySetData.cs @@ -53,13 +53,13 @@ public int? PlatformFaultDomainCount } /// A list of references to all virtual machines in the availability set. - public IList VirtualMachines + public IList VirtualMachines { get => Model.VirtualMachines; } /// Specifies information about the proximity placement group that the availability set should be assigned to. <br><br>Minimum api-version: 2018-04-01. - public SubResource ProximityPlacementGroup + public Azure.ResourceManager.Compute.Models.SubResource ProximityPlacementGroup { get => Model.ProximityPlacementGroup; set => Model.ProximityPlacementGroup = value; diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineData.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineData.cs index 66d9ee43abaab..1da7d4ae52b66 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineData.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineData.cs @@ -32,7 +32,7 @@ public VirtualMachineData(Azure.ResourceManager.Compute.Models.VirtualMachine vm public string ProvisioningState => Model.ProvisioningState; /// Specifies information about the dedicated host that the virtual machine resides in. <br><br>Minimum api-version: 2018-10-01. - public SubResource Host + public Azure.ResourceManager.Compute.Models.SubResource Host { get => Model.Host; set => Model.Host = value; @@ -60,21 +60,21 @@ public VirtualMachinePriorityTypes? Priority } /// Specifies information about the proximity placement group that the virtual machine should be assigned to. <br><br>Minimum api-version: 2018-04-01. - public SubResource ProximityPlacementGroup + public Azure.ResourceManager.Compute.Models.SubResource ProximityPlacementGroup { get => Model.ProximityPlacementGroup; set => Model.ProximityPlacementGroup = value; } /// Specifies information about the virtual machine scale set that the virtual machine should be assigned to. Virtual machines specified in the same virtual machine scale set are allocated to different nodes to maximize availability. Currently, a VM can only be added to virtual machine scale set at creation time. An existing VM cannot be added to a virtual machine scale set. <br><br>This property cannot exist along with a non-null properties.availabilitySet reference. <br><br>Minimum api‐version: 2019‐03‐01. - public SubResource VirtualMachineScaleSet + public Azure.ResourceManager.Compute.Models.SubResource VirtualMachineScaleSet { get => Model.VirtualMachineScaleSet; set => Model.VirtualMachineScaleSet = value; } /// Specifies information about the availability set that the virtual machine should be assigned to. Virtual machines specified in the same availability set are allocated to different nodes to maximize availability. For more information about availability sets, see [Manage the availability of virtual machines](https://docs.microsoft.com/azure/virtual-machines/virtual-machines-windows-manage-availability?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json). <br><br> For more information on Azure planned maintenance, see [Planned maintenance for virtual machines in Azure](https://docs.microsoft.com/azure/virtual-machines/virtual-machines-windows-planned-maintenance?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json) <br><br> Currently, a VM can only be added to availability set at creation time. The availability set to which the VM is being added should be under the same resource group as the availability set resource. An existing VM cannot be added to an availability set. <br><br>This property cannot exist along with a non-null properties.virtualMachineScaleSet reference. - public SubResource AvailabilitySet + public Azure.ResourceManager.Compute.Models.SubResource AvailabilitySet { get => Model.AvailabilitySet; set => Model.AvailabilitySet = value; diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineContainer.cs index 47b755470a5f9..b59b5e9105683 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineContainer.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineContainer.cs @@ -116,7 +116,7 @@ await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDe /// Object used to create a . public VirtualMachineModelBuilder Construct(string hostName, string adminUser, string adminPassword, ResourceIdentifier networkInterfaceId, ResourceIdentifier availabilitySetId, LocationData location = null) { - var parent = GetParentResource(); + var parent = GetParentResource(); var vm = new Azure.ResourceManager.Compute.Models.VirtualMachine(location ?? parent.Data.Location) { NetworkProfile = new NetworkProfile(), @@ -138,7 +138,7 @@ public VirtualMachineModelBuilder Construct(string hostName, string adminUser, s }, }, HardwareProfile = new HardwareProfile() { VmSize = VirtualMachineSizeTypes.StandardB1Ms }, - AvailabilitySet = new SubResource() { Id = availabilitySetId } + AvailabilitySet = new Azure.ResourceManager.Compute.Models.SubResource() { Id = availabilitySetId } }; vm.NetworkProfile.NetworkInterfaces.Add(new NetworkInterfaceReference() { Id = networkInterfaceId }); @@ -230,7 +230,7 @@ public AsyncPageable ListAsync(string nameFilter, int? top = nul /// public override ArmResponse Get(string virtualMachineName, CancellationToken cancellationToken = default) { - return new PhArmResponse(Operations.Get(Id.ResourceGroupName, virtualMachineName, cancellationToken), + return new PhArmResponse(Operations.Get(Id.ResourceGroupName, virtualMachineName, cancellationToken), v => new VirtualMachine(Parent, new VirtualMachineData(v))); } diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/NetworkInterfaceData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/NetworkInterfaceData.cs index 40a2dc674bcd1..ceb3588802700 100644 --- a/sdk/resourcemanager/Proto.Client/network/Placeholder/NetworkInterfaceData.cs +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/NetworkInterfaceData.cs @@ -42,7 +42,7 @@ public NetworkInterfaceData(Azure.ResourceManager.Network.Models.NetworkInterfac /// /// Gets the reference to a linked virtual machine. /// - public SubResource VirtualMachine => Model.VirtualMachine; + public Azure.ResourceManager.Network.Models.SubResource VirtualMachine => Model.VirtualMachine; /// /// Gets the reference to the linked NetworkSecurityGroup resource. @@ -69,7 +69,7 @@ public IList IpConfigurations /// /// Gets a list of TapConfigurations of the newtork interface. /// - public IReadOnlyList TapConfigurations=> Model.TapConfigurations; + public IReadOnlyList TapConfigurations => Model.TapConfigurations; /// /// Gets or sets the DNS settings in network interface. diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/PublicIPAddressData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/PublicIPAddressData.cs index 6c9494b133d98..9e4fced6571d9 100644 --- a/sdk/resourcemanager/Proto.Client/network/Placeholder/PublicIPAddressData.cs +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/PublicIPAddressData.cs @@ -94,7 +94,7 @@ public string IpAddress } /// The Public IP Prefix this Public IP Address should be allocated from. - public SubResource PublicIPPrefix + public Azure.ResourceManager.Network.Models.SubResource PublicIPPrefix { get => Model.PublicIPPrefix; set => Model.PublicIPPrefix = value; diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs index 2e919f7d53cd7..aa8a1d22ca655 100644 --- a/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs @@ -4,29 +4,29 @@ namespace Proto.Network { - /// + /// /// A class representing the subnet data model. /// public class SubnetData : ProxyResource { - /// - /// Initializes a new instance of the class. + /// + /// Initializes a new instance of the class. /// public SubnetData(Azure.ResourceManager.Network.Models.Subnet sub) : base(sub.Id, sub) { } /// - /// Gets the subnet id. + /// Gets the subnet id. /// public override string Name => Model.Name; - /// - /// The provisioning state of the subnet resource. + /// + /// The provisioning state of the subnet resource. /// public ProvisioningState? ProvisioningState => Model.ProvisioningState; - /// + /// /// A read-only string identifying the intention use for this subnet based on delegations and other user-defined properties. /// public string Purpose => Model.Purpose; @@ -44,7 +44,7 @@ public IList Delegations public IReadOnlyList ResourceNavigationLinks => Model.ResourceNavigationLinks; /// Array of IpAllocation which reference this subnet. - public IList IpAllocations + public IList IpAllocations { get => Model.IpAllocations; } @@ -70,9 +70,9 @@ public IList ServiceEndpoints { get => Model.ServiceEndpoints; } - + /// Nat gateway associated with this subnet. - public SubResource NatGateway + public Azure.ResourceManager.Network.Models.SubResource NatGateway { get => Model.NatGateway; set => Model.NatGateway = value; diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/VirtualNetworkData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/VirtualNetworkData.cs index 184e5c2feb684..20a724fb3dc3e 100644 --- a/sdk/resourcemanager/Proto.Client/network/Placeholder/VirtualNetworkData.cs +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/VirtualNetworkData.cs @@ -80,7 +80,7 @@ public bool? EnableVmProtection } /// The DDoS protection plan associated with the virtual network. - public SubResource DdosProtectionPlan + public Azure.ResourceManager.Network.Models.SubResource DdosProtectionPlan { get => Model.DdosProtectionPlan; @@ -95,7 +95,7 @@ public VirtualNetworkBgpCommunities BgpCommunities } /// Array of IpAllocation which reference this VNET. - public IList IpAllocations + public IList IpAllocations { get => Model.IpAllocations; }