コード例 #1
0
        /// <summary>
        /// Parses the query.
        /// </summary>
        /// <param name="queryParameters">The query parameters.</param>
        /// <param name="credentials">The credentials.</param>
        internal static void ParseQuery(NameValueCollection queryParameters, out StorageCredentialsSharedAccessSignature credentials)
        {
            string signature         = null;
            string signedStart       = null;
            string signedExpiry      = null;
            string signedResource    = null;
            string sigendPermissions = null;
            string signedIdentifier  = null;
            string signedVersion     = null;

            bool sasParameterFound = false;

            credentials = null;

            foreach (var key in queryParameters.AllKeys)
            {
                switch (key.ToLower())
                {
                case Constants.QueryConstants.SignedStart:
                    signedStart       = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.SignedExpiry:
                    signedExpiry      = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.SignedPermissions:
                    sigendPermissions = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.SignedResource:
                    signedResource    = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.SignedIdentifier:
                    signedIdentifier  = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.Signature:
                    signature         = queryParameters[key];
                    sasParameterFound = true;
                    break;

                case Constants.QueryConstants.SignedVersion:
                    signedVersion     = queryParameters[key];
                    sasParameterFound = true;
                    break;

                default:
                    break;
                    //// string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.InvalidQueryParametersInsideBlobAddress, key.ToLower());
                    //// throw new ArgumentException(errorMessage);
                }
            }

            if (sasParameterFound)
            {
                if (signature == null || signedResource == null)
                {
                    string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.MissingMandatoryParamtersForSAS);
                    throw new ArgumentException(errorMessage);
                }

                UriQueryBuilder builder = new UriQueryBuilder();
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedStart, signedStart);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedExpiry, signedExpiry);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedPermissions, sigendPermissions);
                builder.Add(Constants.QueryConstants.SignedResource, signedResource);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedIdentifier, signedIdentifier);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedVersion, signedVersion);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.Signature, signature);

                string token = builder.ToString();
                credentials = new StorageCredentialsSharedAccessSignature(token);
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses the query.
        /// </summary>
        /// <param name="queryParameters">The query parameters.</param>
        /// <param name="credentials">The credentials.</param>
        internal static void ParseQuery(NameValueCollection queryParameters, out StorageCredentialsSharedAccessSignature credentials)
        {
            string signature = null;
            string signedStart = null;
            string signedExpiry = null;
            string signedResource = null;
            string sigendPermissions = null;
            string signedIdentifier = null;
            string signedVersion = null;

            bool sasParameterFound = false;

            credentials = null;

            foreach (var key in queryParameters.AllKeys)
            {
                switch (key.ToLower())
                {
                    case Constants.QueryConstants.SignedStart:
                        signedStart = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedExpiry:
                        signedExpiry = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedPermissions:
                        sigendPermissions = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedResource:
                        signedResource = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedIdentifier:
                        signedIdentifier = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.Signature:
                        signature = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedVersion:
                        signedVersion = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    default:
                        break;
                    //// string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.InvalidQueryParametersInsideBlobAddress, key.ToLower());
                    //// throw new ArgumentException(errorMessage);
                }
            }

            if (sasParameterFound)
            {
                if (signature == null || signedResource == null)
                {
                    string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.MissingMandatoryParamtersForSAS);
                    throw new ArgumentException(errorMessage);
                }

                UriQueryBuilder builder = new UriQueryBuilder();
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedStart, signedStart);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedExpiry, signedExpiry);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedPermissions, sigendPermissions);
                builder.Add(Constants.QueryConstants.SignedResource, signedResource);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedIdentifier, signedIdentifier);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedVersion, signedVersion);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.Signature, signature);

                string token = builder.ToString();
                credentials = new StorageCredentialsSharedAccessSignature(token);
            }
        }