Exemplo n.º 1
0
 public bool IsOperationAllowed(OperationType operation)
 {
     return(allowedOperations.HasFlag(operation));
 }
        private ReadOnlyCollection <Uri> GetPreferredAvailableEndpoints(ReadOnlyDictionary <string, Uri> endpointsByLocation, ReadOnlyCollection <string> orderedLocations, OperationType expectedAvailableOperation, Uri fallbackEndpoint)
        {
            List <Uri> endpoints = new List <Uri>();
            DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo;

            // if enableEndpointDiscovery is false, we always use the defaultEndpoint that user passed in during documentClient init
            if (this.enableEndpointDiscovery)
            {
                if (this.CanUseMultipleWriteLocations() || expectedAvailableOperation.HasFlag(OperationType.Read))
                {
                    List <Uri> unavailableEndpoints = new List <Uri>();

                    // When client can not use multiple write locations, preferred locations list should only be used
                    // determining read endpoints order.
                    // If client can use multiple write locations, preferred locations list should be used for determining
                    // both read and write endpoints order.

                    foreach (string location in currentLocationInfo.PreferredLocations)
                    {
                        Uri endpoint;
                        if (endpointsByLocation.TryGetValue(location, out endpoint))
                        {
                            if (this.IsEndpointUnavailable(endpoint, expectedAvailableOperation))
                            {
                                unavailableEndpoints.Add(endpoint);
                            }
                            else
                            {
                                endpoints.Add(endpoint);
                            }
                        }
                    }

                    if (endpoints.Count == 0)
                    {
                        endpoints.Add(fallbackEndpoint);
                    }

                    endpoints.AddRange(unavailableEndpoints);
                }
                else
                {
                    foreach (string location in orderedLocations)
                    {
                        Uri endpoint;
                        if (!string.IsNullOrEmpty(location) && // location is empty during manual failover
                            endpointsByLocation.TryGetValue(location, out endpoint))
                        {
                            endpoints.Add(endpoint);
                        }
                    }
                }
            }

            if (endpoints.Count == 0)
            {
                endpoints.Add(fallbackEndpoint);
            }

            return(endpoints.AsReadOnly());
        }