/// <summary>
        /// Gets the post-processed bitmap cache key.
        /// </summary>
        /// <returns>
        /// <see cref="ICacheKey" /> for doing post-processed bitmap cache
        /// lookups in the pipeline.
        /// </returns>
        public ICacheKey GetPostprocessedBitmapCacheKey(ImageRequest request, object callerContext)
        {
            IPostprocessor postprocessor = request.Postprocessor;
            ICacheKey      postprocessorCacheKey;
            string         postprocessorName;

            if (postprocessor != null)
            {
                postprocessorCacheKey = postprocessor.PostprocessorCacheKey;
                postprocessorName     = postprocessor.GetType().ToString();
            }
            else
            {
                postprocessorCacheKey = null;
                postprocessorName     = null;
            }
            return(new BitmapMemoryCacheKey(
                       GetCacheKeySourceUri(request.SourceUri).ToString(),
                       request.ResizeOptions,
                       request.IsAutoRotateEnabled,
                       request.ImageDecodeOptions,
                       postprocessorCacheKey,
                       postprocessorName,
                       callerContext));
        }
示例#2
0
        /// <summary>
        /// Start producing results for given context.
        /// Provided consumer is notified whenever progress is made
        /// (new value is ready or error occurs).
        /// </summary>
        public void ProduceResults(
            IConsumer <CloseableReference <CloseableImage> > consumer,
            IProducerContext context)
        {
            IProducerListener     listener                  = context.Listener;
            IPostprocessor        postprocessor             = context.ImageRequest.Postprocessor;
            PostprocessorConsumer basePostprocessorConsumer =
                new PostprocessorConsumer(this, consumer, listener, context.Id, postprocessor, context);

            IConsumer <CloseableReference <CloseableImage> > postprocessorConsumer;

            if (postprocessor.GetType() == typeof(IRepeatedPostprocessor))
            {
                postprocessorConsumer = new RepeatedPostprocessorConsumer(
                    basePostprocessorConsumer,
                    (IRepeatedPostprocessor)postprocessor,
                    context);
            }
            else
            {
                postprocessorConsumer = new SingleUsePostprocessorConsumer(basePostprocessorConsumer);
            }

            _inputProducer.ProduceResults(postprocessorConsumer, context);
        }
示例#3
0
        /// <summary>
        /// Start producing results for given context.
        /// Provided consumer is notified whenever progress is made
        /// (new value is ready or error occurs).
        /// </summary>
        public void ProduceResults(
            IConsumer <CloseableReference <CloseableImage> > consumer,
            IProducerContext producerContext)
        {
            IProducerListener listener      = producerContext.Listener;
            string            requestId     = producerContext.Id;
            ImageRequest      imageRequest  = producerContext.ImageRequest;
            object            callerContext = producerContext.CallerContext;

            // If there's no postprocessor or the postprocessor doesn't
            // require caching, forward results.
            IPostprocessor postprocessor = imageRequest.Postprocessor;

            if (postprocessor == null || postprocessor.PostprocessorCacheKey == null)
            {
                _inputProducer.ProduceResults(consumer, producerContext);
                return;
            }

            listener.OnProducerStart(requestId, ProducerName);
            ICacheKey cacheKey = _cacheKeyFactory.GetPostprocessedBitmapCacheKey(
                imageRequest, callerContext);

            CloseableReference <CloseableImage> cachedReference = _memoryCache.Get(cacheKey);
            var extraMap = default(Dictionary <string, string>);

            if (cachedReference != null)
            {
                extraMap = new Dictionary <string, string>()
                {
                    { VALUE_FOUND, "true" }
                };

                listener.OnProducerFinishWithSuccess(
                    requestId,
                    ProducerName,
                    listener.RequiresExtraMap(requestId) ?
                    new ReadOnlyDictionary <string, string>(extraMap) :
                    null);

                consumer.OnProgressUpdate(1.0f);
                consumer.OnNewResult(cachedReference, true);
                cachedReference.Dispose();
            }
            else
            {
                bool isRepeatedProcessor = postprocessor.GetType() == typeof(IRepeatedPostprocessor);
                IConsumer <CloseableReference <CloseableImage> > cachedConsumer =
                    new CachedPostprocessorConsumer(
                        consumer,
                        cacheKey,
                        isRepeatedProcessor,
                        _memoryCache);

                extraMap = new Dictionary <string, string>()
                {
                    { VALUE_FOUND, "false" }
                };

                listener.OnProducerFinishWithSuccess(
                    requestId,
                    ProducerName,
                    listener.RequiresExtraMap(requestId) ?
                    new ReadOnlyDictionary <string, string>(extraMap) :
                    null);

                _inputProducer.ProduceResults(cachedConsumer, producerContext);
            }
        }