/// <summary>
        /// Creates a new instance of the <see cref="SasQueryParameters"/> type
        /// based on the supplied query parameters <paramref name="values"/>.
        /// All SAS-related query parameters will be removed from
        /// <paramref name="values"/>.
        /// </summary>
        /// <param name="values">URI query parameters</param>
        /// <param name="includeBlobParameters">
        /// Optional flag indicating whether to process blob-specific query
        /// parameters.  The default value is false.
        /// </param>
        internal SasQueryParameters(
            UriQueryParamsCollection values,
            bool includeBlobParameters = false)
        {
            // make copy, otherwise we'll get an exception when we remove
            IEnumerable <KeyValuePair <string, string> > kvps = values.ToArray();

            foreach (KeyValuePair <string, string> kv in kvps)
            {
                // these are already decoded
                var isSasKey = true;
                switch (kv.Key.ToUpperInvariant())
                {
                case Constants.Sas.Parameters.VersionUpper:
                    _version = kv.Value;
                    break;

                case Constants.Sas.Parameters.ServicesUpper:
                    _services = SasExtensions.ParseAccountServices(kv.Value);
                    break;

                case Constants.Sas.Parameters.ResourceTypesUpper:
                    _resourceTypes = SasExtensions.ParseResourceTypes(kv.Value);
                    break;

                case Constants.Sas.Parameters.ProtocolUpper:
                    _protocol = SasExtensions.ParseProtocol(kv.Value);
                    break;

                case Constants.Sas.Parameters.StartTimeUpper:
                    _startTime = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    break;

                case Constants.Sas.Parameters.ExpiryTimeUpper:
                    _expiryTime = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    break;

                case Constants.Sas.Parameters.IPRangeUpper:
                    _ipRange = SasIPRange.Parse(kv.Value);
                    break;

                case Constants.Sas.Parameters.IdentifierUpper:
                    _identifier = kv.Value;
                    break;

                case Constants.Sas.Parameters.ResourceUpper:
                    _resource = kv.Value;
                    break;

                case Constants.Sas.Parameters.PermissionsUpper:
                    _permissions = kv.Value;
                    break;

                case Constants.Sas.Parameters.SignatureUpper:
                    _signature = kv.Value;
                    break;

                case Constants.Sas.Parameters.CacheControlUpper:
                    _cacheControl = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentDispositionUpper:
                    _contentDisposition = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentEncodingUpper:
                    _contentEncoding = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentLanguageUpper:
                    _contentLanguage = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentTypeUpper:
                    _contentType = kv.Value;
                    break;

                // Optionally include Blob parameters
                case Constants.Sas.Parameters.KeyObjectIdUpper:
                    if (includeBlobParameters)
                    {
                        _keyObjectId = kv.Value;
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                case Constants.Sas.Parameters.KeyTenantIdUpper:
                    if (includeBlobParameters)
                    {
                        _keyTenantId = kv.Value;
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                case Constants.Sas.Parameters.KeyStartUpper:
                    if (includeBlobParameters)
                    {
                        _keyStart = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                case Constants.Sas.Parameters.KeyExpiryUpper:
                    if (includeBlobParameters)
                    {
                        _keyExpiry = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                case Constants.Sas.Parameters.KeyServiceUpper:
                    if (includeBlobParameters)
                    {
                        _keyService = kv.Value;
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                case Constants.Sas.Parameters.KeyVersionUpper:
                    if (includeBlobParameters)
                    {
                        _keyVersion = kv.Value;
                    }
                    else
                    {
                        isSasKey = false;
                    }
                    break;

                // We didn't recognize the query parameter
                default:
                    isSasKey = false;
                    break;
                }

                // Remove the query parameter if it's part of the SAS
                if (isSasKey)
                {
                    values.Remove(kv.Key);
                }
            }
        }
        /// <summary>
        /// Creates a new instance of the <see cref="SasQueryParameters"/> type
        /// based on the supplied query parameters <paramref name="values"/>.
        /// All SAS-related query parameters will be removed from
        /// <paramref name="values"/>.
        /// </summary>
        /// <param name="values">URI query parameters</param>
        protected SasQueryParameters(IDictionary <string, string> values)
        {
            // make copy, otherwise we'll get an exception when we remove
            IEnumerable <KeyValuePair <string, string> > kvps = values.ToArray();

            foreach (KeyValuePair <string, string> kv in kvps)
            {
                // these are already decoded
                var isSasKey = true;
                switch (kv.Key.ToUpperInvariant())
                {
                case Constants.Sas.Parameters.VersionUpper:
                    _version = kv.Value;
                    break;

                case Constants.Sas.Parameters.ServicesUpper:
                    _services = SasExtensions.ParseAccountServices(kv.Value);
                    break;

                case Constants.Sas.Parameters.ResourceTypesUpper:
                    _resourceTypes = SasExtensions.ParseResourceTypes(kv.Value);
                    break;

                case Constants.Sas.Parameters.ProtocolUpper:
                    _protocol = SasExtensions.ParseProtocol(kv.Value);
                    break;

                case Constants.Sas.Parameters.StartTimeUpper:
                    _startTime = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    break;

                case Constants.Sas.Parameters.ExpiryTimeUpper:
                    _expiryTime = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, CultureInfo.InvariantCulture);
                    break;

                case Constants.Sas.Parameters.IPRangeUpper:
                    _ipRange = SasIPRange.Parse(kv.Value);
                    break;

                case Constants.Sas.Parameters.IdentifierUpper:
                    _identifier = kv.Value;
                    break;

                case Constants.Sas.Parameters.ResourceUpper:
                    _resource = kv.Value;
                    break;

                case Constants.Sas.Parameters.PermissionsUpper:
                    _permissions = kv.Value;
                    break;

                case Constants.Sas.Parameters.SignatureUpper:
                    _signature = kv.Value;
                    break;

                case Constants.Sas.Parameters.CacheControlUpper:
                    _cacheControl = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentDispositionUpper:
                    _contentDisposition = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentEncodingUpper:
                    _contentEncoding = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentLanguageUpper:
                    _contentLanguage = kv.Value;
                    break;

                case Constants.Sas.Parameters.ContentTypeUpper:
                    _contentType = kv.Value;
                    break;

                case Constants.Sas.Parameters.PreauthorizedAgentObjectIdUpper:
                    _preauthorizedAgentObjectId = kv.Value;
                    break;

                case Constants.Sas.Parameters.AgentObjectIdUpper:
                    _agentObjectId = kv.Value;
                    break;

                case Constants.Sas.Parameters.CorrelationIdUpper:
                    _correlationId = kv.Value;
                    break;

                case Constants.Sas.Parameters.DirectoryDepthUpper:
                    _directoryDepth = Convert.ToInt32(kv.Value, Constants.Base16);
                    break;

                // We didn't recognize the query parameter
                default:
                    isSasKey = false;
                    break;
                }

                // Remove the query parameter if it's part of the SAS
                if (isSasKey)
                {
                    values.Remove(kv.Key);
                }
            }
        }