Bloom.ImageProcessing.ImageServer.ProcessRequest C# (CSharp) Method

ProcessRequest() protected method

protected ProcessRequest ( IRequestInfo info ) : bool
info IRequestInfo
return bool
        protected override bool ProcessRequest(IRequestInfo info)
        {
            if (base.ProcessRequest(info))
                return true;

            if (!_useCache)
                return false;

            var imageFile = GetLocalPathWithoutQuery(info);

            // only process images
            var isSvg = imageFile.EndsWith(".svg", StringComparison.OrdinalIgnoreCase);
            if (!IsImageTypeThatCanBeDegraded(imageFile) && !isSvg)
                return false;

            imageFile = imageFile.Replace("thumbnail", "");

            var processImage = !isSvg;

            // This happens with the new way we are serving css files
            if (!RobustFile.Exists(imageFile))
            {
                var fileName = Path.GetFileName(imageFile);
                var sourceDir = FileLocator.GetDirectoryDistributedWithApplication(BloomFileLocator.BrowserRoot);
                imageFile = Directory.EnumerateFiles(sourceDir, fileName, SearchOption.AllDirectories).FirstOrDefault();

                // image file not found
                if (string.IsNullOrEmpty(imageFile)) return false;

                // BL-2368: Do not process files from the BloomBrowserUI directory. These files are already in the state we
                //          want them. Running them through _cache.GetPathToResizedImage() is not necessary, and in PNG files
                //          it converts all white areas to transparent. This is resulting in icons which only contain white
                //          (because they are rendered on a dark background) becoming completely invisible.
                processImage = false;
            }

            if (processImage)
            {
                // thumbnail requests have the thumbnail parameter set in the query string
                var thumb = info.GetQueryParameters()["thumbnail"] != null;
                imageFile = _cache.GetPathToResizedImage(imageFile, thumb);

                if (string.IsNullOrEmpty(imageFile)) return false;
            }

            info.ReplyWithImage(imageFile);
            return true;
        }