protected override void ProcessRecord()
        {
            var disabled = false;
            TrafficManagerEndpoint endpointToDisable = null;

            if (this.ParameterSetName == "Fields")
            {
                endpointToDisable = new TrafficManagerEndpoint
                {
                    Name = this.Name,
                    Type = this.Type,
                    ProfileName = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                endpointToDisable = this.TrafficManagerEndpoint;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_DisableEndpoint, endpointToDisable.Name, endpointToDisable.ProfileName),
                ProjectResources.Progress_DisablingEndpoint,
                this.Name,
                () => { disabled = this.TrafficManagerClient.EnableDisableTrafficManagerEndpoint(endpointToDisable, shouldEnableEndpointStatus: false); });

            if (disabled)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_DisableEndpoint, endpointToDisable.Name, endpointToDisable.Name, endpointToDisable.ResourceGroupName));
            }

            this.WriteObject(disabled);
        }
        public override void ExecuteCmdlet()
        {
            var deleted = false;
            TrafficManagerEndpoint trafficManagerEndpointToDelete = null;

            if (this.ParameterSetName == "Fields")
            {
                trafficManagerEndpointToDelete = new TrafficManagerEndpoint
                {
                    Name = this.Name,
                    ProfileName = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName,
                    Type = this.Type
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                trafficManagerEndpointToDelete = this.TrafficManagerEndpoint;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveEndpoint, trafficManagerEndpointToDelete.Name, trafficManagerEndpointToDelete.ProfileName, trafficManagerEndpointToDelete.ResourceGroupName),
                ProjectResources.Progress_RemovingEndpoint,
                this.Name,
                () => { deleted = this.TrafficManagerClient.DeleteTrafficManagerEndpoint(trafficManagerEndpointToDelete); });

            if (deleted)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_RemoveEndpoint, trafficManagerEndpointToDelete.Name, trafficManagerEndpointToDelete.ProfileName, trafficManagerEndpointToDelete.ResourceGroupName));
            }

            this.WriteObject(deleted);
        }
        protected override void ProcessRecord()
        {
            TrafficManagerEndpoint endpointToEnable = null;

            if (this.ParameterSetName == "Fields")
            {
                endpointToEnable = new TrafficManagerEndpoint
                {
                    Name = this.Name,
                    Target = this.Type,
                    ProfileName = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                endpointToEnable = this.TrafficManagerEndpoint;
            }

            bool enabled = this.TrafficManagerClient.EnableDisableTrafficManagerEndpoint(endpointToEnable, shouldEnableEndpointStatus: true);

            if (enabled)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_EnableEndpoint, endpointToEnable.Name, endpointToEnable.ProfileName, endpointToEnable.ResourceGroupName));
            }

            this.WriteObject(enabled);
        }
 public Endpoint ToSDKEndpointForPatch()
 {
     return(new Endpoint
     {
         Id = this.Id,
         Name = this.Name,
         Type = TrafficManagerEndpoint.ToFullEndpointType(this.Type),
     });
 }
 public Endpoint ToSDKEndpointForPatch()
 {
     return(new Endpoint
     {
         Id = this.Id,
         Name = this.Name,
         Type = TrafficManagerEndpoint.ToSDKEndpointType(this.Type),
         Properties = new EndpointProperties
         {
         }
     });
 }
        public Endpoint ToSDKEndpoint()
        {
            Endpoint endpoint = new Endpoint(this.Id, this.Name, TrafficManagerEndpoint.ToFullEndpointType(this.Type));

            endpoint.EndpointLocation  = this.Location;
            endpoint.EndpointStatus    = this.EndpointStatus;
            endpoint.GeoMapping        = this.GeoMapping;
            endpoint.MinChildEndpoints = this.MinChildEndpoints;
            endpoint.Priority          = this.Priority;
            endpoint.Target            = this.Target;
            endpoint.TargetResourceId  = this.TargetResourceId;
            endpoint.Weight            = this.Weight;
            endpoint.Subnets           = this.SubnetMapping?.Select(ipAddressRange => ipAddressRange.ToSDKSubnetMapping()).ToList();
            endpoint.CustomHeaders     = this.CustomHeaders?.Select(customHeader => customHeader.ToSDKEndpointPropertiesCustomHeadersItem()).ToList();
            return(endpoint);
        }
 public Endpoint ToSDKEndpoint()
 {
     return(new Endpoint
     {
         Id = this.Id,
         Name = this.Name,
         Type = TrafficManagerEndpoint.ToFullEndpointType(this.Type),
         EndpointLocation = this.Location,
         EndpointStatus = this.EndpointStatus,
         GeoMapping = this.GeoMapping,
         MinChildEndpoints = this.MinChildEndpoints,
         Priority = this.Priority,
         Target = this.Target,
         TargetResourceId = this.TargetResourceId,
         Weight = this.Weight,
     });
 }
 public Endpoint ToSDKEndpoint()
 {
     return(new Endpoint
     {
         Name = this.Name,
         Type = TrafficManagerEndpoint.ToSDKEndpointType(this.Type),
         Id = this.TargetResourceId,
         Properties = new EndpointProperties
         {
             Target = this.Target,
             EndpointStatus = this.EndpointStatus,
             Weight = this.Weight,
             Priority = this.Priority,
             EndpointLocation = this.Location
         }
     });
 }
        public bool EnableDisableTrafficManagerEndpoint(TrafficManagerEndpoint endpoint, bool shouldEnableEndpointStatus)
        {
            endpoint.EndpointStatus = shouldEnableEndpointStatus ? Constants.StatusEnabled : Constants.StatusDisabled;

            Endpoint sdkEndpoint = endpoint.ToSDKEndpoint();
            sdkEndpoint.Properties.EndpointLocation = null;
            sdkEndpoint.Properties.EndpointMonitorStatus = null;
            sdkEndpoint.Properties.Priority = null;
            sdkEndpoint.Properties.Weight = null;
            sdkEndpoint.Properties.Target = null;
            sdkEndpoint.Properties.TargetResourceId = null;

            var parameters = new EndpointUpdateParameters
            {
                Endpoint = sdkEndpoint
            };

            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Update(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return response.StatusCode.Equals(HttpStatusCode.Created);
        }
        public bool DeleteTrafficManagerEndpoint(TrafficManagerEndpoint trafficManagerEndpoint)
        {
            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Delete(
                trafficManagerEndpoint.ResourceGroupName, 
                trafficManagerEndpoint.ProfileName, 
                trafficManagerEndpoint.Type, 
                trafficManagerEndpoint.Name);

            return response.StatusCode.Equals(HttpStatusCode.OK);
        }
        public TrafficManagerEndpoint SetTrafficManagerEndpoint(TrafficManagerEndpoint endpoint)
        {
            var parameters = new EndpointCreateOrUpdateParameters
            {
                Endpoint = endpoint.ToSDKEndpoint()
            };

            EndpointCreateOrUpdateResponse response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return TrafficManagerClient.GetPowershellTrafficManagerEndpoint(
                endpoint.Id,
                endpoint.ResourceGroupName, 
                endpoint.ProfileName,
                endpoint.Type, 
                endpoint.Name, 
                response.Endpoint.Properties);
        }
 public Endpoint ToSDKEndpointForPatch()
 {
     return(new Endpoint(this.Id, this.Name, TrafficManagerEndpoint.ToFullEndpointType(this.Type)));
 }