コード例 #1
0
        /// <summary>Gets the path of a resized version of the image, if it exists, otherwise the given image url.</summary>
        /// <param name="fs">The file system used to check file existence.</param>
        /// <param name="url">The base url of an image.</param>
        /// <param name="resizedSuffix">The size suffix to append before the extension.</param>
        /// <returns>A resized image url if it exists.</returns>
        public static string GetExistingImagePath(this IFileSystem fs, string imageUrl, string preferredSize, out bool preferredSizeExists)
        {
            if (string.IsNullOrEmpty(imageUrl) || string.IsNullOrEmpty(preferredSize))
            {
                preferredSizeExists = false;
                return(imageUrl);
            }

            string preferredUrl = ImagesUtility.GetResizedPath(imageUrl, preferredSize);

            try
            {
                if (fs.FileExists(preferredUrl))
                {
                    preferredSizeExists = true;
                    return(preferredUrl);
                }
            }
            catch (InvalidOperationException)
            {
            }

            preferredSizeExists = false;
            return(Url.ToAbsolute(imageUrl));
        }
コード例 #2
0
        /// <summary>Gets the path of a resized version of the image, if it exists, otherwise the given image url.</summary>
        /// <param name="url">The base url of an image.</param>
        /// <param name="resizedSuffix">The size suffix to append before the extension.</param>
        /// <returns>A resized image url if it exists.</returns>
        public static string GetExistingImagePath(string imageUrl, string preferredSize)
        {
            if (string.IsNullOrEmpty(imageUrl) || string.IsNullOrEmpty(preferredSize))
            {
                return(imageUrl);
            }

            string preferredUrl = ImagesUtility.GetResizedPath(imageUrl, preferredSize);

            if (HostingEnvironment.VirtualPathProvider.FileExists(preferredUrl))
            {
                return(preferredUrl);
            }

            return(Url.ToAbsolute(imageUrl));
        }
コード例 #3
0
ファイル: ImagesUtility.cs プロジェクト: wrohrbach/n2cms
        /// <summary>Gets the path of a resized version of the image, if it exists, otherwise the given image url.</summary>
        /// <param name="url">The base url of an image.</param>
        /// <param name="resizedSuffix">The size suffix to append before the extension.</param>
        /// <returns>A resized image url if it exists.</returns>
        public static string GetExistingImagePath(string imageUrl, string preferredSize)
        {
            if (string.IsNullOrEmpty(imageUrl) || string.IsNullOrEmpty(preferredSize))
            {
                return(imageUrl);
            }

            string preferredUrl = ImagesUtility.GetResizedPath(imageUrl, preferredSize);

            try
            {
                if ((Context.Current.Resolve <IFileSystem>()).FileExists(preferredUrl))
                {
                    return(preferredUrl);
                }
            }
            catch (InvalidOperationException)
            {
            }

            return(Url.ToAbsolute(imageUrl));
        }