protected override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (string.IsNullOrEmpty(this.ServiceName) || this.CurrentDeploymentNewSM == null)
            {
                return;
            }

            var endpoint = this.GetEndpoint();
            if(endpoint == null)
            {
                this.ThrowTerminatingError(
                    new ErrorRecord(
                        new InvalidOperationException(
                            string.Format(
                                CultureInfo.InvariantCulture, 
                                Resources.EndpointsCannotBeFoundWithGivenLBSetName, 
                                this.LBSetName)),
                        string.Empty,
                        ErrorCategory.InvalidData,
                        null));
            }

            this.UpdateEndpointProperties(endpoint);
            
            var endpointList = new LoadBalancedEndpointList();
            endpointList.Add(endpoint);

            var endPointParams = new VirtualMachineUpdateLoadBalancedSetParameters
            {
                //TODO: AutoMapper doesn't seem to work for this conversion.
                //LoadBalancedEndpoints = Mapper.Map<IList<VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint>>(endpointList)
                LoadBalancedEndpoints = new int[1].Select(e => new VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint
                {
                    EnableDirectServerReturn = endpoint.EnableDirectServerReturn,
                    LoadBalancedEndpointSetName = endpoint.LoadBalancedEndpointSetName,
                    LoadBalancerProbe = endpoint.LoadBalancerProbe == null ? null : new NSM.LoadBalancerProbe
                    {
                        IntervalInSeconds = endpoint.LoadBalancerProbe.IntervalInSeconds,
                        Path = endpoint.LoadBalancerProbe.Path,
                        Port = endpoint.LoadBalancerProbe.Port,
                        Protocol = (LoadBalancerProbeTransportProtocol)Enum.Parse(typeof(LoadBalancerProbeTransportProtocol), endpoint.LoadBalancerProbe.Protocol, true),
                        TimeoutInSeconds = endpoint.LoadBalancerProbe.TimeoutInSeconds
                    },
                    LocalPort = endpoint.LocalPort,
                    Name = endpoint.Name,
                    Port = endpoint.Port,
                    Protocol = endpoint.Protocol,
                    Rules = endpoint.EndpointAccessControlList == null ? null : endpoint.EndpointAccessControlList.Rules == null ? null : endpoint.EndpointAccessControlList.Rules.Select(r => new NSM.AccessControlListRule
                    {
                        Action = r.Action,
                        Description = r.Description,
                        Order = r.Order,
                        RemoteSubnet = r.RemoteSubnet
                    }).ToList(),
                    VirtualIPAddress = endpoint.Vip,
                    LoadBalancerName = this.InternalLoadBalancerName
                }).ToList()
            };

            this.ExecuteClientActionNewSM(
                null,
                this.CommandRuntime.ToString(),
                () => this.ComputeClient.VirtualMachines.UpdateLoadBalancedEndpointSet(this.ServiceName, this.CurrentDeploymentNewSM.Name, endPointParams));
        }
        protected PSArgument[] CreateVirtualMachineUpdateLoadBalancedEndpointSetParameters()
        {
            string serviceName = string.Empty;
            string deploymentName = string.Empty;
            VirtualMachineUpdateLoadBalancedSetParameters parameters = new VirtualMachineUpdateLoadBalancedSetParameters();

            return ConvertFromObjectsToArguments(new string[] { "ServiceName", "DeploymentName", "Parameters" }, new object[] { serviceName, deploymentName, parameters });
        }
 /// <summary>
 /// The UpdateLoadBalancedEndpointSet operation changes the specified
 /// load-balanced InputEndpoints on all the roles of an Infrastructure
 /// as a Service deployment. Non load-balanced endpoints must be
 /// changed using UpdateRole.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations.
 /// </param>
 /// <param name='serviceName'>
 /// The name of your service.
 /// </param>
 /// <param name='deploymentName'>
 /// The name of your deployment.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Load Balanced Endpoint Set
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse BeginUpdatingLoadBalancedEndpointSet(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineUpdateLoadBalancedSetParameters parameters)
 {
     try
     {
         return operations.BeginUpdatingLoadBalancedEndpointSetAsync(serviceName, deploymentName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
 /// <summary>
 /// The UpdateLoadBalancedEndpointSet operation changes the specified
 /// load-balanced InputEndpoints on all the roles of an Infrastructure
 /// as a Service deployment. Non load-balanced endpoints must be
 /// changed using UpdateRole.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations.
 /// </param>
 /// <param name='serviceName'>
 /// The name of your service.
 /// </param>
 /// <param name='deploymentName'>
 /// The name of your deployment.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update Load Balanced Endpoint Set
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<OperationResponse> BeginUpdatingLoadBalancedEndpointSetAsync(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineUpdateLoadBalancedSetParameters parameters)
 {
     return operations.BeginUpdatingLoadBalancedEndpointSetAsync(serviceName, deploymentName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Begin Updating Load Balanced Endpoint Set operation changes the
 /// specified load-balanced InputEndpoints on all the roles of an
 /// Infrastructure as a Service deployment. Non-load-balanced
 /// endpoints must be changed using UpdateRole.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn469417.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of your service.
 /// </param>
 /// <param name='deploymentName'>
 /// Required. The name of your deployment.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Updating Load Balanced
 /// Endpoint Set operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse BeginUpdatingLoadBalancedEndpointSet(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineUpdateLoadBalancedSetParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVirtualMachineOperations)s).BeginUpdatingLoadBalancedEndpointSetAsync(serviceName, deploymentName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }