예제 #1
0
        /// <summary>
        /// Evaluate connection string and return the requested endpoint.
        /// </summary>
        /// <remarks>
        /// Parsing the connection string MUST follow these rules:
        ///     1. check for explicit endpoint (location is ignored)
        ///     2. check for endpoint suffix (location is optional)
        ///     3. use default endpoint (location is ignored)
        /// This behavior is required by the Connection String Specification.
        /// </remarks>
        internal static string GetIngestionEndpoint(this Azure.Core.ConnectionString connectionString)
        {
            // Passing the user input values through the Uri constructor will verify that we've built a valid endpoint.
            Uri uri;

            if (connectionString.TryGetNonRequiredValue(Constants.IngestionExplicitEndpointKey, out string explicitEndpoint))
            {
                if (!Uri.TryCreate(explicitEndpoint, UriKind.Absolute, out uri))
                {
                    throw new ArgumentException($"The value for {Constants.IngestionExplicitEndpointKey} is invalid. '{explicitEndpoint}'");
                }
            }
            else if (connectionString.TryGetNonRequiredValue(Constants.EndpointSuffixKey, out string endpointSuffix))
            {
                var location = connectionString.GetNonRequired(Constants.LocationKey);
                if (!TryBuildUri(prefix: Constants.IngestionPrefix, suffix: endpointSuffix, location: location, uri: out uri))
                {
                    throw new ArgumentException($"The value for {Constants.EndpointSuffixKey} is invalid. '{endpointSuffix}'");
                }
            }
            else
            {
                return(Constants.DefaultIngestionEndpoint);
            }

            return(uri.AbsoluteUri);
        }
예제 #2
0
 /// <summary>
 /// This method wraps <see cref="Azure.Core.ConnectionString.GetNonRequired(string)"/> in a null check.
 /// </summary>
 internal static bool TryGetNonRequiredValue(this Azure.Core.ConnectionString connectionString, string key, out string value)
 {
     value = connectionString.GetNonRequired(key);
     return(value != null);
 }