BuildUrl() публичный Метод

public BuildUrl ( ) : string
Результат string
Пример #1
0
        private string FinalizePosterUrl(string source)
        {
            string posterUrl = null;

            if (m_posterUrl != null)
            {
                posterUrl = m_posterUrl.BuildUrl();
            }
            else if (m_posterTransformation != null)
            {
                posterUrl = Clone().Format("jpg").Transform(m_posterTransformation.Clone()).BuildUrl(source);
            }
            else if (m_posterSource != null)
            {
                if (!String.IsNullOrEmpty(m_posterSource))
                {
                    posterUrl = Clone().Format("jpg").BuildUrl(m_posterSource);
                }
            }
            else
            {
                posterUrl = Clone().Format("jpg").BuildUrl(source);
            }

            return(posterUrl);
        }
Пример #2
0
        public static IHtmlContent BuildImageTag(this Url url, string source, IDictionary <string, string> options = null)
        {
            if (options == null)
            {
                options = new Dictionary <string, string>();
            }
            var str1 = url.BuildUrl(source);

            if (!string.IsNullOrEmpty(url.Transformation.HtmlWidth))
            {
                options.Add("width", url.Transformation.HtmlWidth);
            }
            if (!string.IsNullOrEmpty(url.Transformation.HtmlHeight))
            {
                options.Add("height", url.Transformation.HtmlHeight);
            }

            string placeholder = null;

            if (url.Transformation.HiDpi || url.Transformation.IsResponsive)
            {
                var isResponsive = url.Transformation.IsResponsive ? "cld-responsive" : "cld-hidpi";
                var className    = options["class"];
                options["class"] = className == null ? isResponsive : className + " " + isResponsive;
                options.Add("data-src", str1);
                if (options.TryGetValue("responsive_placeholder", out placeholder))
                {
                    if (placeholder == "blank")
                    {
                        placeholder = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
                    }
                }
            }
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("<img");
            if (!string.IsNullOrEmpty(placeholder))
            {
                stringBuilder.Append(" src=\"").Append(placeholder).Append("\"");
            }
            foreach (var keyValuePair in options)
            {
                stringBuilder.Append(" ").Append(keyValuePair.Key).Append("=\"").Append(WebUtility.HtmlEncode(keyValuePair.Value)).Append("\"");
            }
            stringBuilder.Append("/>");
            return(new HtmlString(stringBuilder.ToString()));
        }
Пример #3
0
        public DelResResult DeleteResources(DelResParams parameters)
        {
            Url url = m_api.ApiUrlV.
                      Add("resources").
                      Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType));

            if (String.IsNullOrEmpty(parameters.Tag))
            {
                url = url.Add(parameters.Type);
            }
            else
            {
                url = url.Add("tags").Add(parameters.Tag);
            }

            UrlBuilder urlBuilder = new UrlBuilder(url.BuildUrl());

            foreach (var param in parameters.ToParamsDictionary())
            {
                if (param.Value is IEnumerable <string> )
                {
                    foreach (var item in (IEnumerable)param.Value)
                    {
                        urlBuilder.QueryString.Add(String.Format("{0}[]", param.Key), item.ToString());
                    }
                }
                else
                {
                    urlBuilder.QueryString[param.Key] = param.Value.ToString();
                }
            }

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.DELETE, urlBuilder.ToString(), null, null))
            {
                DelResResult result = DelResResult.Parse(response);
                return(result);
            }
        }
Пример #4
0
        public DelResResult DeleteResources(DelResParams parameters)
        {
            Url url = m_api.ApiUrlV.
                      Add("resources").
                      Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType));

            if (String.IsNullOrEmpty(parameters.Tag))
            {
                url = url.Add(parameters.Type);
            }
            else
            {
                url = url.Add("tags").Add(parameters.Tag);
            }

            UrlBuilder urlBuilder = new UrlBuilder(url.BuildUrl(), parameters.ToParamsDictionary());

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.DELETE, urlBuilder.ToString(), null, null))
            {
                DelResResult result = DelResResult.Parse(response);
                return(result);
            }
        }
Пример #5
0
        public SearchResult Execute()
        {
            Url url = m_api.ApiUrlV.Add("resources").Add("search");

            return(m_api.CallAndParse <SearchResult>(HttpMethod.POST, url.BuildUrl(), PrepareSearchParams(), null, PrepareHeaders()));
        }
Пример #6
0
        public static IHtmlContent BuildVideoTag(this Url url, string source, IDictionary <string, string> options = null)
        {
            if (options == null)
            {
                options = new Dictionary <string, string>();
            }
            source = VIDEO_EXTENSION_RE.Replace(source, "", 1);
            if (string.IsNullOrEmpty(url.m_resourceType))
            {
                url.m_resourceType = "video";
            }
            var strArray = url.m_sourceTypes ?? DEFAULT_VIDEO_SOURCE_TYPES;
            var str1     = FinalizePosterUrl(url, source);

            if (!string.IsNullOrEmpty(str1))
            {
                options.Add("poster", str1);
            }
            var sb   = new StringBuilder("<video");
            var flag = strArray.Length > 1;

            if (!flag)
            {
                var str2 = url.BuildUrl(source + "." + strArray[0]);
                options.Add("src", str2);
            }
            else
            {
                url.BuildUrl(source);
            }
            if (options.ContainsKey("html_height"))
            {
                options["height"] = options.SliceValue("html_height");
            }
            else if (url.Transformation.HtmlHeight != null)
            {
                options["height"] = url.Transformation.HtmlHeight;
            }
            if (options.ContainsKey("html_width"))
            {
                options["width"] = options.SliceValue("html_width");
            }
            else if (url.Transformation.HtmlWidth != null)
            {
                options["width"] = url.Transformation.HtmlWidth;
            }
            foreach (var keyValuePair in options.OrderBy(x => x.Key))
            {
                sb.Append(" ").Append(keyValuePair.Key);
                if (keyValuePair.Value != null)
                {
                    sb.Append("='").Append(keyValuePair.Value).Append("'");
                }
            }
            sb.Append(">");
            if (flag)
            {
                foreach (var sourceType in strArray)
                {
                    url.AppendVideoSources(sb, source, sourceType);
                }
            }
            if (!string.IsNullOrEmpty(url.m_fallbackContent))
            {
                sb.Append(url.m_fallbackContent);
            }
            sb.Append("</video>");
            return(new HtmlString(sb.ToString()));
        }