Beispiel #1
0
        private static string BuildPublicUrl(MediaUrlData mediaUrlData)
        {
            IMediaUrlProvider urlProvider;

            if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider))
            {
                urlProvider = _defaultMediaUrlProvider.Value;
            }

            if (mediaUrlData.QueryParameters.Count > 0)
            {
                var resizingOptions = ResizingOptions.Parse(mediaUrlData.QueryParameters);

                if (!resizingOptions.IsEmpty)
                {
                    var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider
                        ? urlProvider as IResizableImageUrlProvider
                        : _defaultMediaUrlProvider.Value;

                    return(imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions));
                }
            }

            return(urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId));
        }
Beispiel #2
0
        private static string BuildPublicUrl(MediaUrlData mediaUrlData)
        {
            IMediaUrlProvider urlProvider;

            if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider))
            {
                urlProvider = _defaultMediaUrlProvider.Value;
            }



            if (mediaUrlData.QueryParameters.Count > 0)
            {
                string mediaUrl;
                var    resizingOptions     = ResizingOptions.Parse(mediaUrlData.QueryParameters);
                var    noneResizingOptions = mediaUrlData.QueryParameters;

                if (!resizingOptions.IsEmpty)
                {
                    var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider
                        ? urlProvider as IResizableImageUrlProvider
                        : _defaultMediaUrlProvider.Value;

                    mediaUrl = imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions);

                    foreach (var key in HttpUtility.ParseQueryString(resizingOptions.ToString()).AllKeys)
                    {
                        noneResizingOptions.Remove(key);
                    }
                }
                else
                {
                    mediaUrl = urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId);
                }

                if (noneResizingOptions.Count > 0)
                {
                    var urlBuilder = new UrlBuilder(mediaUrl);

                    urlBuilder.AddQueryParameters(noneResizingOptions);

                    return(urlBuilder.ToString());
                }

                return(mediaUrl);
            }

            return(urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId));
        }
Beispiel #3
0
        private static string BuildInternalUrl(MediaUrlData mediaUrlData)
        {
            string storeId = mediaUrlData.MediaStore == DefaultMediaStore
                             ? ""
                             : mediaUrlData.MediaStore + ":";

            var urlBuilder = new UrlBuilder("~/media(" + storeId + mediaUrlData.MediaId + ")");

            if (mediaUrlData.QueryParameters != null)
            {
                urlBuilder.AddQueryParameters(mediaUrlData.QueryParameters);
            }

            return(urlBuilder.ToString());
        }
Beispiel #4
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
            case UrlKind.Internal:
                return(BuildInternalUrl(mediaUrlData));

            case UrlKind.Renderer:
                return(BuildRendererUrl(mediaUrlData));

            case UrlKind.Public:
                return(BuildPublicUrl(mediaUrlData));
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
Beispiel #5
0
        private static string BuildRendererUrl(MediaUrlData mediaUrlData)
        {
            var queryParams = new NameValueCollection(mediaUrlData.QueryParameters)
            {
                { "id", mediaUrlData.MediaId.ToString() }
            };

            if (mediaUrlData.MediaStore != null &&
                mediaUrlData.MediaStore != DefaultMediaStore)
            {
                queryParams.Add("store", mediaUrlData.MediaStore);
            }

            var url = new UrlBuilder(UrlUtils.PublicRootPath + "/Renderers/ShowMedia.ashx");

            url.AddQueryParameters(queryParams);

            return(url);
        }
Beispiel #6
0
        private static string BuildPublicUrl(MediaUrlData mediaUrlData)
        {
            IMediaUrlProvider urlProvider;
            if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider))
            {
                urlProvider = _defaultMediaUrlProvider.Value;
            }

             
            

            if (mediaUrlData.QueryParameters.Count > 0)
            {
                string mediaUrl;
                var resizingOptions = ResizingOptions.Parse(mediaUrlData.QueryParameters);
                var noneResizingOptions = mediaUrlData.QueryParameters;

                if (!resizingOptions.IsEmpty)
                {
                    var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider
                        ? urlProvider as IResizableImageUrlProvider
                        : _defaultMediaUrlProvider.Value;

                    mediaUrl = imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions);

                    foreach (var key in HttpUtility.ParseQueryString(resizingOptions.ToString()).AllKeys)
                    {
                        noneResizingOptions.Remove(key);
                    }
                }
                else
                {
                    mediaUrl = urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId);
                }

                if (noneResizingOptions.Count > 0)
                {
                    var urlBuilder = new UrlBuilder(mediaUrl);

                    urlBuilder.AddQueryParameters(noneResizingOptions);

                    return urlBuilder.ToString();
                }

                return mediaUrl;
            }

            return urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId);
        }
Beispiel #7
0
        private static string BuildRendererUrl(MediaUrlData mediaUrlData)
        {
            var queryParams = new NameValueCollection(mediaUrlData.QueryParameters)
            {
                {"id", mediaUrlData.MediaId.ToString()}
            };

            if (mediaUrlData.MediaStore != null 
                && mediaUrlData.MediaStore != DefaultMediaStore)
            {
                queryParams.Add("store", mediaUrlData.MediaStore);
            }

            var url = new UrlBuilder(UrlUtils.PublicRootPath + "/Renderers/ShowMedia.ashx");
            url.AddQueryParameters(queryParams);

            return url;
        }
Beispiel #8
0
        private static string BuildInternalUrl(MediaUrlData mediaUrlData)
        {
            string storeId = mediaUrlData.MediaStore == DefaultMediaStore 
                             ? "" 
                             : mediaUrlData.MediaStore + ":";

            var urlBuilder = new UrlBuilder("~/media(" + storeId + mediaUrlData.MediaId + ")");

            if (mediaUrlData.QueryParameters != null)
            {
                urlBuilder.AddQueryParameters(mediaUrlData.QueryParameters);
            }

            return urlBuilder.ToString();
        }
Beispiel #9
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
                case UrlKind.Internal:
                    return BuildInternalUrl(mediaUrlData);
                case UrlKind.Renderer:
                    return BuildRendererUrl(mediaUrlData);
                case UrlKind.Public:
                    return BuildPublicUrl(mediaUrlData);
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
Beispiel #10
0
        private static string BuildPublicUrl(MediaUrlData mediaUrlData)
        {
            IMediaUrlProvider urlProvider;
            if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider))
            {
                urlProvider = _defaultMediaUrlProvider.Value;
            }

            if (mediaUrlData.QueryParameters.Count > 0)
            {
                var resizingOptions = ResizingOptions.Parse(mediaUrlData.QueryParameters);

                if (!resizingOptions.IsEmpty)
                {
                    var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider
                        ? urlProvider as IResizableImageUrlProvider
                        : _defaultMediaUrlProvider.Value;

                    return imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions);
                }
            }

            return urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId);
        }