public override void ExecuteCmdlet()
        {
            var disabled = false;
            TrafficManagerProfile profileToDisable = null;

            if (this.ParameterSetName == "Fields")
            {
                profileToDisable = new TrafficManagerProfile
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                profileToDisable = this.TrafficManagerProfile;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_DisableProfile, profileToDisable.Name),
                ProjectResources.Progress_DisablingProfile,
                profileToDisable.Name,
                () => { disabled = this.TrafficManagerClient.EnableDisableTrafficManagerProfile(profileToDisable, shouldEnableProfileStatus: false); });

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

            this.WriteObject(disabled);
        }
        public override void ExecuteCmdlet()
        {
            TrafficManagerProfile profileToEnable = null;

            if (this.ParameterSetName == "Fields")
            {
                profileToEnable = new TrafficManagerProfile
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                profileToEnable = this.TrafficManagerProfile;
            }

            bool enabled = this.TrafficManagerClient.EnableDisableTrafficManagerProfile(profileToEnable, shouldEnableProfileStatus: true);

            if (enabled)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_EnableProfile, profileToEnable.Name, profileToEnable.ResourceGroupName));
            }

            this.WriteObject(enabled);
        }
        protected override void ProcessRecord()
        {
            var deleted = false;
            TrafficManagerProfile profileToDelete = null;

            if (this.ParameterSetName == "Fields")
            {
                profileToDelete = new TrafficManagerProfile
                {
                    Name = this.Name,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                profileToDelete = this.TrafficManagerProfile;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveProfile, profileToDelete.Name),
                ProjectResources.Progress_RemovingProfile,
                this.Name,
                () => { deleted = this.TrafficManagerClient.DeleteTrafficManagerProfile(profileToDelete); });

            if (deleted)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_RemoveProfile, profileToDelete.Name, profileToDelete.ResourceGroupName));
            }

            this.WriteObject(deleted);
        }
        public TrafficManagerProfile SetTrafficManagerProfile(TrafficManagerProfile profile)
        {
            var parameteres = new ProfileCreateOrUpdateParameters
            {
                Profile = profile.ToSDKProfile()
            };

            ProfileCreateOrUpdateResponse response = this.TrafficManagerManagementClient.Profiles.CreateOrUpdate(
                profile.ResourceGroupName,
                profile.Name, 
                parameteres
                );

            return TrafficManagerClient.GetPowershellTrafficManagerProfile(profile.ResourceGroupName, profile.Name, response.Profile.Properties);
        }
        private static TrafficManagerProfile GetPowershellTrafficManagerProfile(string resourceGroupName, string profileName, ProfileProperties mamlProfileProperties)
        {
            var profile = new TrafficManagerProfile
            {
                Name = profileName,
                ResourceGroupName = resourceGroupName,
                ProfileStatus = mamlProfileProperties.ProfileStatus,
                RelativeDnsName = mamlProfileProperties.DnsConfig.RelativeName,
                Ttl = mamlProfileProperties.DnsConfig.Ttl,
                TrafficRoutingMethod = mamlProfileProperties.TrafficRoutingMethod,
                MonitorProtocol = mamlProfileProperties.MonitorConfig.Protocol,
                MonitorPort = mamlProfileProperties.MonitorConfig.Port,
                MonitorPath = mamlProfileProperties.MonitorConfig.Path
            };

            if (mamlProfileProperties.Endpoints != null)
            {
                profile.Endpoints = new List<TrafficManagerEndpoint>();

                foreach (Endpoint endpoint in mamlProfileProperties.Endpoints)
                {
                    profile.Endpoints.Add(new TrafficManagerEndpoint
                    {
                        Name = endpoint.Name,
                        Type = endpoint.Type,
                        Target = endpoint.Properties.Target,
                        EndpointStatus = endpoint.Properties.EndpointStatus,
                        Location = endpoint.Properties.EndpointLocation,
                        Priority = endpoint.Properties.Priority,
                        Weight = endpoint.Properties.Weight
                    });
                }
            }

            return profile;
        }
        public bool EnableDisableTrafficManagerProfile(TrafficManagerProfile profile, bool shouldEnableProfileStatus)
        {
            profile.ProfileStatus = shouldEnableProfileStatus ? Constants.StatusEnabled : Constants.StatusDisabled;

            Profile sdkProfile = profile.ToSDKProfile();
            sdkProfile.Properties.DnsConfig = null;
            sdkProfile.Properties.Endpoints = null;
            sdkProfile.Properties.TrafficRoutingMethod = null;
            sdkProfile.Properties.MonitorConfig = null;

            var parameters = new ProfileUpdateParameters
            {
                Profile = sdkProfile
            };

            AzureOperationResponse response = this.TrafficManagerManagementClient.Profiles.Update(profile.ResourceGroupName, profile.Name, parameters);

            return response.StatusCode.Equals(HttpStatusCode.OK);
        }
        public bool DeleteTrafficManagerProfile(TrafficManagerProfile profile)
        {
            AzureOperationResponse response = this.TrafficManagerManagementClient.Profiles.Delete(profile.ResourceGroupName, profile.Name);

            return response.StatusCode.Equals(HttpStatusCode.OK);
        }