Microsoft.Azure.Commands.Network.AddAzureVirtualNetworkSubnetConfigCommand.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : void
return void
        public override void Execute()
        {
            base.Execute();

            // Verify if the subnet exists in the VirtualNetwork
            var subnet = this.VirtualNetwork.Subnets.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (subnet != null)
            {
                throw new ArgumentException("Subnet with the specified name already exists");
            }

            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.NetworkSecurityGroup != null)
                {
                    this.NetworkSecurityGroupId = this.NetworkSecurityGroup.Id;
                }

                if (this.RouteTable != null)
                {
                    this.RouteTableId = this.RouteTable.Id;
                }
            }

            subnet = new PSSubnet();

            subnet.Name = this.Name;
            subnet.AddressPrefix = this.AddressPrefix;

            if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId))
            {
                subnet.NetworkSecurityGroup = new PSNetworkSecurityGroup();
                subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
            }

            if (!string.IsNullOrEmpty(this.RouteTableId))
            {
                subnet.RouteTable = new PSRouteTable();
                subnet.RouteTable.Id = this.RouteTableId;
            }

            this.VirtualNetwork.Subnets.Add(subnet);

            WriteObject(this.VirtualNetwork);
        }
    }
AddAzureVirtualNetworkSubnetConfigCommand