Esempio n. 1
0
        public static string UpdateImageUrl(
            string url,
            ImageSizeParameters parameters = null)
        {
            var parsedUrl = new Uri(url, UriKind.RelativeOrAbsolute);

            var uriBuilder = parsedUrl.IsAbsoluteUri ?
                             new UriBuilder(parsedUrl) :
                             new UriBuilder("http://www.tempuri.org" + parsedUrl);

            var imageParameters = parameters?.ToString();

            if (!string.IsNullOrWhiteSpace(imageParameters))
            {
                uriBuilder.Query = imageParameters;
            }

            var match = MediaUrlPrefixRegex.Match(uriBuilder.Path);

            if (match.Length > 1)
            {
                // regex will provide us with /-/ or /~/ type
                uriBuilder.Path = MediaUrlPrefixRegex.Replace(uriBuilder.Path, $"/{match.Groups[1].Value}/jssmedia/");
            }

            return(parsedUrl.IsAbsoluteUri ?
                   uriBuilder.Uri.GetComponents(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped) :
                   uriBuilder.Uri.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped));
        }