public override void Execute()
{
base.Execute();
var existingInboundNatRule = this.LoadBalancer.InboundNatRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
if (existingInboundNatRule != null)
{
throw new ArgumentException("InboundNatRule with the specified name already exists");
}
var inboundNatRule = new PSInboundNatRule();
inboundNatRule.Name = this.Name;
inboundNatRule.Protocol = this.Protocol;
inboundNatRule.FrontendPort = this.FrontendPort;
inboundNatRule.BackendPort = this.BackendPort;
if (this.IdleTimeoutInMinutes > 0)
{
inboundNatRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
}
inboundNatRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;
if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
{
inboundNatRule.FrontendIPConfiguration = new PSResourceId() { Id = this.FrontendIpConfigurationId };
}
inboundNatRule.Id =
ChildResourceHelper.GetResourceId(
this.NetworkClient.NetworkManagementClient.SubscriptionId,
this.LoadBalancer.ResourceGroupName,
this.LoadBalancer.Name,
Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName,
this.Name);
this.LoadBalancer.InboundNatRules.Add(inboundNatRule);
WriteObject(this.LoadBalancer);
}
}