Exemplo n.º 1
0
        internal static Uri CreateRequestUri(
            Uri baseUri,
            bool usePathStyleUris,
            string accountName,
            string containerName,
            string blobName,
            TimeSpan Timeout,
            NameValueCollection queryParameters,
            out ResourceUriComponents uriComponents
            )
        {
            uriComponents =
                new ResourceUriComponents(accountName, containerName, blobName);
            Uri uri = HttpRequestAccessor.ConstructResourceUri(baseUri, uriComponents, usePathStyleUris);

            if (queryParameters != null)
            {
                UriBuilder builder = new UriBuilder(uri);

                if (queryParameters.Get(QueryParams.QueryParamTimeout) == null)
                {
                    queryParameters.Add(QueryParams.QueryParamTimeout,
                                        Timeout.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                }

                StringBuilder sb         = new StringBuilder();
                bool          firstParam = true;
                foreach (string queryKey in queryParameters.AllKeys)
                {
                    if (!firstParam)
                    {
                        sb.Append("&");
                    }
                    sb.Append(HttpUtility.UrlEncode(queryKey));
                    sb.Append('=');
                    sb.Append(HttpUtility.UrlEncode(queryParameters[queryKey]));
                    firstParam = false;
                }

                if (sb.Length > 0)
                {
                    builder.Query = sb.ToString();
                }
                return(builder.Uri);
            }
            else
            {
                return(uri);
            }
        }