示例#1
0
 /// <summary>
 /// Initializes a new instance of the DefinitionCreateParameters class
 /// with required arguments.
 /// </summary>
 public DefinitionCreateParameters(DefinitionDnsOptions dnsOptions, IList <DefinitionMonitor> monitors, DefinitionPolicyCreateParameters policy)
     : this()
 {
     if (dnsOptions == null)
     {
         throw new ArgumentNullException("dnsOptions");
     }
     if (monitors == null)
     {
         throw new ArgumentNullException("monitors");
     }
     if (policy == null)
     {
         throw new ArgumentNullException("policy");
     }
     this.DnsOptions    = dnsOptions;
     this.MonitorsValue = monitors;
     this.Policy        = policy;
 }
 /// <summary>
 /// Initializes a new instance of the DefinitionCreateParameters class
 /// with required arguments.
 /// </summary>
 public DefinitionCreateParameters(DefinitionDnsOptions dnsOptions, IList<DefinitionMonitor> monitors, DefinitionPolicyCreateParameters policy)
     : this()
 {
     if (dnsOptions == null)
     {
         throw new ArgumentNullException("dnsOptions");
     }
     if (monitors == null)
     {
         throw new ArgumentNullException("monitors");
     }
     if (policy == null)
     {
         throw new ArgumentNullException("policy");
     }
     this.DnsOptions = dnsOptions;
     this.Monitors = monitors;
     this.Policy = policy;
 }
        public void CreateADefinitionAndEnableTheProfile(
            string profileName,
            LoadBalancingMethod loadBalancingMethod,
            IList<DefinitionEndpointCreateParameters> endpoints)
        {
            DefinitionCreateParameters definitionParameter = new DefinitionCreateParameters();
            DefinitionMonitor monitor = new DefinitionMonitor();
            DefinitionDnsOptions dnsOption = new DefinitionDnsOptions();
            DefinitionPolicyCreateParameters policyParameter = new DefinitionPolicyCreateParameters();
            DefinitionMonitorHTTPOptions monitorHttpOption = new DefinitionMonitorHTTPOptions();

            definitionParameter.DnsOptions = dnsOption;
            definitionParameter.Policy = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            dnsOption.TimeToLiveInSeconds = 30;

            monitorHttpOption.RelativePath = "/randomFile.aspx";
            monitorHttpOption.Verb = "GET";
            monitorHttpOption.ExpectedStatusCode = (int)HttpStatusCode.OK;

            monitor.Protocol = DefinitionMonitorProtocol.Http;
            //Set fixed values required by services   
            monitor.IntervalInSeconds = 30;
            monitor.TimeoutInSeconds = 10;
            monitor.ToleratedNumberOfFailures = 3;
            monitor.Port = 80;

            policyParameter.LoadBalancingMethod = loadBalancingMethod;
            policyParameter.Endpoints = endpoints;

            TrafficManagerClient.Definitions.Create(profileName, definitionParameter);
        }
        public DefinitionCreateParameters InstantiateTrafficManagerDefinition(
            string loadBalancingMethod,
            int monitorPort,
            string monitorProtocol,
            string monitorRelativePath,
            int ttl,
            IList<TrafficManagerEndpoint> endpoints)
        {
            // Create the definition
            var definitionParameter = new DefinitionCreateParameters();
            var dnsOptions = new DefinitionDnsOptions();
            var monitor = new DefinitionMonitor();
            var policyParameter = new DefinitionPolicyCreateParameters();
            var monitorHttpOption = new DefinitionMonitorHTTPOptions();

            dnsOptions.TimeToLiveInSeconds = ttl;

            monitorHttpOption.RelativePath = monitorRelativePath;
            monitorHttpOption.Verb = Constants.monitorHttpOptionVerb;
            monitorHttpOption.ExpectedStatusCode = Constants.monitorHttpOptionExpectedStatusCode;

            monitor.Protocol =
                (DefinitionMonitorProtocol)Enum.Parse(typeof(DefinitionMonitorProtocol), monitorProtocol);
            monitor.IntervalInSeconds = Constants.monitorIntervalInSeconds;
            monitor.TimeoutInSeconds = Constants.monitorTimeoutInSeconds;
            monitor.ToleratedNumberOfFailures = Constants.monitorToleratedNumberOfFailures;
            monitor.Port = monitorPort;
            policyParameter.LoadBalancingMethod =
                (LoadBalancingMethod)Enum.Parse(typeof(LoadBalancingMethod), loadBalancingMethod);

            policyParameter.Endpoints = new List<DefinitionEndpointCreateParameters>();
            foreach (TrafficManagerEndpoint endpoint in endpoints)
            {
                var endpointParam = new DefinitionEndpointCreateParameters
                    {
                        DomainName = endpoint.DomainName,
                        Location = endpoint.Location,
                        Status = endpoint.Status,
                        Type = endpoint.Type,
                        Weight = endpoint.Weight
                    };

                policyParameter.Endpoints.Add(endpointParam);
            }

            definitionParameter.DnsOptions = dnsOptions;
            definitionParameter.Policy = policyParameter;
            definitionParameter.Monitors.Add(monitor);
            monitor.HttpOptions = monitorHttpOption;

            return definitionParameter;
        }