Пример #1
0
        protected static string getThumbDisplayUrl(BaseShowThumbnailPageParameters config, string fileUrl, int displayBoxWidth, int displayBoxHeight)
        {
            // -- get the AppPath
            string appPath = PageUtils.ApplicationPath;

            // -- remove appPath
            if (fileUrl.StartsWith(appPath))
            {
                fileUrl = fileUrl.Substring(appPath.Length);
            }

            if (config.useDiskCache && config.diskCacheStorageDirectoryPath != "")
            {
                string FullSizeImageFilenameOnDisk = config.fullSizeImageStorageDir + fileUrl;
                string cacheUrl = getCachedThumbnailUrl(config, FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);
                if (cacheUrl != String.Empty)
                {
                    return(cacheUrl);
                }
            } // if use disk cache


            string displayUrl = config.showThumbDisplayPageUrl + "?file=" + fileUrl;

            if (displayBoxWidth > 0)
            {
                displayUrl += "&w=" + displayBoxWidth.ToString();
            }
            if (displayBoxHeight > 0)
            {
                displayUrl += "&h=" + displayBoxHeight.ToString();
            }
            return(displayUrl);
        }
Пример #2
0
        /// <summary>
        /// returns String.Empty if not found in the cache.
        /// </summary>
        /// <param name="FullSizeImageFilenameOnDisk"></param>
        /// <param name="longestSidePixels"></param>
        /// <param name="shortestSidePixels"></param>
        /// <returns></returns>
        protected static string getCachedThumbnailUrl(BaseShowThumbnailPageParameters config, string FullSizeImageFilenameOnDisk, int displayBoxWidth, int displayBoxHeight)
        {
            ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);

            string cacheKey     = getImageCacheKey(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);
            string imgExtension = Path.GetExtension(FullSizeImageFilenameOnDisk);

            if (diskCache.ExistsInCache(cacheKey, imgExtension))
            {
                string url = diskCache.CacheKeyToUrl(cacheKey, imgExtension);
                return(url);
            }


            return(String.Empty);
        }
Пример #3
0
        /// <summary>
        /// if width and height can not be determined, returns a new size with isEmpty = true.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="filename"></param>
        /// <param name="longestSidePixels"></param>
        /// <param name="shortestSidePixels"></param>
        /// <returns></returns>
        protected static System.Drawing.Size getDisplayWidthAndHeight(BaseShowThumbnailPageParameters config, string filename, int displayBoxWidth, int displayBoxHeight)
        {
            string FullSizeImageFilenameOnDisk = config.fullSizeImageStorageDir + filename;
            string cacheKey = getImageCacheKey(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);

            ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);

            if (config.useDiskCache && diskCache.ExistsInCache(cacheKey, Path.GetExtension(FullSizeImageFilenameOnDisk)))
            {
                string fn = diskCache.CacheKeyToFilename(cacheKey, Path.GetExtension(FullSizeImageFilenameOnDisk));
                return(Thumbnail2.getDisplayWidthAndHeight(fn, displayBoxWidth, displayBoxHeight));
            }
            else if (File.Exists(FullSizeImageFilenameOnDisk))
            {
                return(Thumbnail2.getDisplayWidthAndHeight(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight));
            }
            else
            {
                return(new System.Drawing.Size());
            }
        }
Пример #4
0
        protected void Process_Page_Load(BaseShowThumbnailPageParameters config)
        {
            string requestFile      = PageUtils.getFromForm("file", "");
            int    displayBoxWidth  = PageUtils.getFromForm("w", 0);
            int    displayBoxHeight = PageUtils.getFromForm("h", 0);

            // -- get the full sized image filename on disk
            string FullSizeImageFilenameOnDisk = "";
            // requestFile could have the Application path in it, and the config.fullSizeImageStorageDir could also making the file impossible to find
            // so let's remove it from requestFile
            string appPath = Request.ApplicationPath;

            if (!appPath.EndsWith("/"))
            {
                appPath += "/";
            }
            if (requestFile.StartsWith(appPath))
            {
                requestFile = requestFile.Substring(appPath.Length);
            }

            FullSizeImageFilenameOnDisk = config.fullSizeImageStorageDir + requestFile;

            if (FullSizeImageFilenameOnDisk == "" || !File.Exists(FullSizeImageFilenameOnDisk))
            {
                return;
            }

            string imgExtension = Path.GetExtension(FullSizeImageFilenameOnDisk);

            // -- check the cache for the image key
            string cacheKey = getImageCacheKey(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);

            byte[] imageContent = null;
            if (config.useMemoryCache)
            {
                imageContent = CheckMemoryCache(cacheKey);
            }

            if (imageContent == null && config.useDiskCache && config.diskCacheStorageDirectoryPath != "" && Directory.Exists(config.diskCacheStorageDirectoryPath))
            {
                ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);
                imageContent = diskCache.getFromCache(cacheKey, imgExtension);
            }

            if (imageContent == null)
            {
                imageContent = Thumbnail2.CreateThumbnail(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);
            }

            if (imageContent != null)
            {
                // -- save to cache
                if (config.useMemoryCache)
                {
                    InsertIntoMemoryCache(cacheKey, imageContent);
                }
                if (config.useDiskCache)
                {
                    ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);
                    diskCache.addToCache(cacheKey, imgExtension, imageContent);
                }

                // -- serve the image binary data
                serveImageContent(imgExtension, imageContent);
            }
        } // Process_Page_Load