private void AddLocationsForCreateUpdateParameters(Models.DatabaseAccountCreateUpdateParametersInner createUpdateParametersInner, IList <Microsoft.Azure.Management.CosmosDB.Fluent.Models.FailoverPolicyInner> failoverPolicies)
        {
            List <Models.Location> locations = new List <Models.Location>();

            if (failoverPolicies.Count > 0)
            {
                for (int i = 0; i < failoverPolicies.Count; i++)
                {
                    Models.FailoverPolicyInner policyInner = failoverPolicies[i];
                    Models.Location            location    = new Models.Location();
                    location.FailoverPriority = i;
                    location.LocationName     = policyInner.LocationName;
                    locations.Add(location);
                }
            }
            else
            {
                Models.Location location = new Models.Location();
                location.FailoverPriority = 0;
                location.LocationName     = createUpdateParametersInner.Location;
                locations.Add(location);
            }

            createUpdateParametersInner.Locations = locations;
        }
 public CosmosDBAccountImpl WithWriteReplication(Region region, bool?isZoneRedundant)
 {
     Models.Location FailoverPolicy = new Models.Location();
     FailoverPolicy.LocationName     = region.Name;
     FailoverPolicy.IsZoneRedundant  = isZoneRedundant;
     FailoverPolicy.FailoverPriority = this.failoverPolicies.Count;
     this.isFailoverPolicyLoaded     = true;
     this.failoverPolicies.Add(FailoverPolicy);
     return(this);
 }
        public async Task FailoverPriorityChangeAsync(string groupName, string accountName, IList <Microsoft.Azure.Management.CosmosDB.Fluent.Models.Location> failoverLocations, CancellationToken cancellationToken = default(CancellationToken))
        {
            List <Models.FailoverPolicy> policyInners = new List <Models.FailoverPolicy>();

            for (int i = 0; i < failoverLocations.Count(); i++)
            {
                Models.Location       location    = failoverLocations[i];
                Models.FailoverPolicy policyInner = new Models.FailoverPolicy();
                policyInner.LocationName     = location.LocationName;
                policyInner.FailoverPriority = i;
                policyInners.Add(policyInner);
            }

            await this.Manager.Inner.DatabaseAccounts.FailoverPriorityChangeAsync(groupName, accountName, policyInners);
        }
        private void initializeFailover()
        {
            this.failoverPolicies.Clear();
            Models.Location[] locationInners = new Models.Location[this.Inner.Locations.Count];
            for (var i = 0; i < locationInners.Length; i++)
            {
                locationInners[i] = this.Inner.Locations[i];
            }

            Array.Sort(locationInners, (o1, o2) =>
            {
                return(o1.FailoverPriority.GetValueOrDefault().CompareTo(o2.FailoverPriority.GetValueOrDefault()));
            });

            for (int i = 0; i < locationInners.Length; i++)
            {
                this.failoverPolicies.Add(locationInners[i]);
            }

            this.isFailoverPolicyLoaded = true;
        }
        private void AddLocationsForParameters(HasLocation locationParameters, IList <Microsoft.Azure.Management.CosmosDB.Fluent.Models.Location> failoverPolicies)
        {
            List <Models.Location> locations = new List <Models.Location>();

            if (failoverPolicies.Count > 0)
            {
                for (int i = 0; i < failoverPolicies.Count; ++i)
                {
                    failoverPolicies[i].FailoverPriority = i;
                }
                locations.AddRange(failoverPolicies);
            }
            else
            {
                Models.Location location = new Models.Location();
                location.FailoverPriority = 0;
                location.LocationName     = locationParameters.Location;
                locations.Add(location);
            }

            locationParameters.Locations = locations;
        }