public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            var compositeTransformer = new CompositeMediaTransformer();
            var factories = _transformerFactories.ToList();
            AddTransformerToComposite(request, originalFormat, compositeTransformer, factories, formatInfoProvider);

            mediaTransformer = compositeTransformer;
            return compositeTransformer.Count > 0;
        }
        private static string GetOriginalPath(HttpRequestBase request, IMediaTransformer mediaTransformer)
        {
            var path = HttpUtility.UrlDecode(request.Url.AbsolutePath);

            if (mediaTransformer != null)
            {
                path = mediaTransformer.ModifyAbsolutePath(path);
            }

            return(path);
        }
        public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            var transforms = GetBitmapTransforms(request.QueryString).ToArray();
            if (!transforms.Any())
            {
                mediaTransformer = null;
                return false;
            }

            IFormatInfo outputFormat;
            BitmapEncoder encoder;

            if (!TryGetContentType(originalFormat, request, formatInfoProvider, out outputFormat, out encoder))
            {
                mediaTransformer = null;
                return false;
            }

            mediaTransformer = new ImageMediaTransformer(transforms, encoder, outputFormat);
            return true;
        }
        public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            if (!CanHandleFormat(originalFormat))
            {
                mediaTransformer = null;
                return false;
            }

            if(!IsValidFilePath(request.Url.AbsolutePath))
            {
                mediaTransformer = null;
                return false;
            }

            IFormatInfo outputFormat;
            if( !TryGetOutputFormat(request, originalFormat, formatInfoProvider, out outputFormat) )
            {
                mediaTransformer = null;
                return false;
            }

            mediaTransformer = new MediaTransformer(outputFormat, this);
            return true;
        }
        public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            if (!CanHandleFormat(originalFormat))
            {
                mediaTransformer = null;
                return(false);
            }

            if (!IsValidFilePath(request.Url.AbsolutePath))
            {
                mediaTransformer = null;
                return(false);
            }

            IFormatInfo outputFormat;

            if (!TryGetOutputFormat(request, originalFormat, formatInfoProvider, out outputFormat))
            {
                mediaTransformer = null;
                return(false);
            }

            mediaTransformer = new MediaTransformer(outputFormat, this);
            return(true);
        }
Example #6
0
        public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            var transforms = GetBitmapTransforms(request.QueryString).ToArray();

            if (!transforms.Any())
            {
                mediaTransformer = null;
                return(false);
            }

            IFormatInfo   outputFormat;
            BitmapEncoder encoder;

            if (!TryGetContentType(originalFormat, request, formatInfoProvider, out outputFormat, out encoder))
            {
                mediaTransformer = null;
                return(false);
            }

            mediaTransformer = new ImageMediaTransformer(transforms, encoder, outputFormat);
            return(true);
        }
 public void AddMediaTransformer(IMediaTransformer transformer)
 {
     _transformers.Add(transformer);
 }
        private bool TryGetResult(HttpRequestBase request, IFormatInfo outputFormat, bool transformMedia, IMediaTransformer mediaTransformer, out IResult result)
        {
            var path         = GetRequestPath(request);
            var originalPath = GetOriginalPath(request, mediaTransformer);

            if (MediaCache.TryServeRequestFromCache(transformMedia ? path : originalPath, outputFormat, out result))
            {
                return(true);
            }

            IStorageFile storageFile;

            if (!StorageBackend.TryGetStorageFile(originalPath, out storageFile))
            {
                return(false);
            }

            if (!transformMedia && !CacheOriginals)
            {
                result = storageFile;
                return(true);
            }

            if (transformMedia)
            {
                result = TransformMedia(storageFile.GetStream(), outputFormat, path, mediaTransformer);
                return(true);
            }

            result = ServeOriginal(originalPath, storageFile, outputFormat);
            return(true);
        }
        private IResult TransformMedia(Stream original, IFormatInfo outputFormat, string path, IMediaTransformer mediaTransformer)
        {
            Stream stream;
            var    transformResult = mediaTransformer.TransformStream(original, out stream);

            original.Dispose();

            if (transformResult == MediaTransformResult.Success)
            {
                IAddToCacheResult cacheResult;
                if (MediaCache.TryAddToCache(path, stream, outputFormat, out cacheResult))
                {
                    return(new CopyToOutputStreamResult(cacheResult.LastModified, cacheResult.ETag, stream.Length, stream));
                }
            }

            return(new CopyToOutputStreamResult(null, null, stream.Length, stream));
        }
        private bool TryGetResult( HttpRequestBase request, IFormatInfo outputFormat, bool transformMedia, IMediaTransformer mediaTransformer, out IResult result )
        {
            var path = GetRequestPath( request );
            var originalPath = GetOriginalPath( request, mediaTransformer );

            if ( MediaCache.TryServeRequestFromCache( transformMedia ? path : originalPath, outputFormat, out result ) )
            {
                return true;
            }

            IStorageFile storageFile;
            if ( !StorageBackend.TryGetStorageFile( originalPath, out storageFile ) )
            {
                return false;
            }

            if ( !transformMedia && !CacheOriginals )
            {
                result = storageFile;
                return true;
            }

            if ( transformMedia )
            {
                result = TransformMedia( storageFile.GetStream(), outputFormat, path, mediaTransformer );
                return true;
            }

            result = ServeOriginal( originalPath, storageFile, outputFormat );
            return true;
        }
        private IResult TransformMedia( Stream original, IFormatInfo outputFormat, string path, IMediaTransformer mediaTransformer )
        {
            Stream stream;
            var transformResult = mediaTransformer.TransformStream( original, out stream );
            original.Dispose();

            if ( transformResult == MediaTransformResult.Success )
            {
                IAddToCacheResult cacheResult;
                if ( MediaCache.TryAddToCache( path, stream, outputFormat, out cacheResult ) )
                {
                    return new CopyToOutputStreamResult( cacheResult.LastModified, cacheResult.ETag, stream.Length, stream );
                }
            }

            return new CopyToOutputStreamResult( null, null, stream.Length, stream );
        }
        private static string GetOriginalPath( HttpRequestBase request, IMediaTransformer mediaTransformer )
        {
            var path = HttpUtility.UrlDecode( request.Url.AbsolutePath );

            if ( mediaTransformer != null )
            {
                path = mediaTransformer.ModifyAbsolutePath( path );
            }

            return path;
        }
 public void AddMediaTransformer(IMediaTransformer transformer)
 {
     _transformers.Add(transformer);
 }
        public bool TryCreateTransformer(HttpRequestBase request, IFormatInfo originalFormat, IFormatInfoProvider formatInfoProvider, out IMediaTransformer mediaTransformer)
        {
            var compositeTransformer = new CompositeMediaTransformer();
            var factories            = _transformerFactories.ToList();

            AddTransformerToComposite(request, originalFormat, compositeTransformer, factories, formatInfoProvider);

            mediaTransformer = compositeTransformer;
            return(compositeTransformer.Count > 0);
        }