/// <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);
        }
 public Middleware(
     IArenaLogic arenaLogic,
     IBotLogic botLogic,
     IPreprocessor preprocessor,
     IProcessor processor,
     IPostprocessor postprocessor)
 {
     _arenaLogic    = arenaLogic;
     _botLogic      = botLogic;
     _preprocessor  = preprocessor;
     _processor     = processor;
     _postprocessor = postprocessor;
 }
Пример #4
0
 public Middleware(
     IArenaLogic arenaLogic,
     IBotLogic botLogic,
     IMessageLogic messageLogic,
     IPreprocessor preprocessor,
     IProcessor processor,
     IPostprocessor postprocessor,
     ILogger <Middleware> logger)
 {
     _arenaLogic    = arenaLogic;
     _botLogic      = botLogic;
     _messageLogic  = messageLogic;
     _preprocessor  = preprocessor;
     _processor     = processor;
     _postprocessor = postprocessor;
     _logger        = logger;
 }
Пример #5
0
            private IDictionary <string, string> GetExtraMap(
                IProducerListener listener,
                string requestId,
                IPostprocessor postprocessor)
            {
                if (!listener.RequiresExtraMap(requestId))
                {
                    return(null);
                }

                var extraMap = new Dictionary <string, string>()
                {
                    { POSTPROCESSOR, postprocessor.Name }
                };

                return(new ReadOnlyDictionary <string, string>(extraMap));
            }
Пример #6
0
 internal PostprocessorConsumer(
     PostprocessorProducer parent,
     IConsumer <CloseableReference <CloseableImage> > consumer,
     IProducerListener listener,
     string requestId,
     IPostprocessor postprocessor,
     IProducerContext producerContext) :
     base(consumer)
 {
     _parent        = parent;
     _listener      = listener;
     _requestId     = requestId;
     _postprocessor = postprocessor;
     producerContext.AddCallbacks(
         new BaseProducerContextCallbacks(
             () =>
     {
         MaybeNotifyOnCancellation();
     },
             () => { },
             () => { },
             () => { }));
 }
Пример #7
0
 public static IExplorer Chain(this IExplorer explorer, IPostprocessor processor)
 {
     // todo. implement this in a lazy way
     throw new NotImplementedException();
 }
Пример #8
0
 public static IExplorer Chain(this IExplorer explorer, IPostprocessor processor)
 {
     // todo. implement this in a lazy way
     throw new NotImplementedException();
 }
Пример #9
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);
            }
        }
 /// <summary>
 /// Sets the postprocessor.
 /// <param name="postprocessor">
 /// IPostprocessor to postprocess the output bitmap with.
 /// </param>
 /// <returns>The modified builder instance.</returns>
 /// </summary>
 public ImageRequestBuilder SetPostprocessor(IPostprocessor postprocessor)
 {
     Postprocessor = postprocessor;
     return(this);
 }