Microsoft.Azure.Commands.TrafficManager.NewAzureTrafficManagerEndpoint.ExecuteCmdlet C# (CSharp) Method

ExecuteCmdlet() public method

public ExecuteCmdlet ( ) : void
return void
        public override void ExecuteCmdlet()
        {
            // We are not supporting etags yet, NewAzureTrafficManagerEndpoint should not overwrite any existing endpoint.
            // Since our create operation is implemented using PUT, it will overwrite by default.
            // Therefore, we need to check whether the Profile exists before we actually try to create it.
            try
            {
                this.TrafficManagerClient.GetTrafficManagerEndpoint(this.ResourceGroupName, this.ProfileName, this.Type, this.Name);

                throw new PSArgumentException(string.Format(ProjectResources.Error_CreateExistingEndpoint, this.Name, this.ProfileName, this.ResourceGroupName));
            }
            catch (CloudException exception)
            {
                if (exception.Response.StatusCode.Equals(HttpStatusCode.NotFound))
                {
                    TrafficManagerEndpoint trafficManagerEndpoint = this.TrafficManagerClient.CreateTrafficManagerEndpoint(
                        this.ResourceGroupName,
                        this.ProfileName,
                        this.Type,
                        this.Name,
                        this.TargetResourceId,
                        this.Target,
                        this.EndpointStatus,
                        this.Weight,
                        this.Priority,
                        this.EndpointLocation,
                        this.MinChildEndpoints);

                    this.WriteVerbose(ProjectResources.Success);
                    this.WriteObject(trafficManagerEndpoint);
                }
                else
                {
                    throw;
                }
            }
        }
    }
NewAzureTrafficManagerEndpoint