public void TestIsDiskCacheDisabledIfRequested7()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("data:image/png;base64"));
     builder.DisableDiskCache();
     Assert.IsFalse(builder.IsDiskCacheEnabled);
 }
 public void TestIsDiskCacheDisabledIfRequested4()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("ms-appx-web:///request"));
     builder.DisableDiskCache();
     Assert.IsFalse(builder.IsDiskCacheEnabled);
 }
        private async void FetchDecodedImage()
        {
            try
            {
                Uri uri = MainPage.GenerateImageUri();
                ImageRequestBuilder builder = ImageRequestBuilder.NewBuilderWithSource(uri);
                if (GrayscaleRadioButton.IsChecked.Value)
                {
                    builder.SetPostprocessor(GrayscalePostprocessor);
                }
                else if (InvertRadioButton.IsChecked.Value)
                {
                    builder.SetPostprocessor(InvertPostprocessor);
                }

                ImageRequest    request = builder.Build();
                WriteableBitmap bitmap  = await _imagePipeline.FetchDecodedBitmapImageAsync(request);

                var image = new Image();
                image.Width  = image.Height = MainPage.VIEW_DIMENSION;
                image.Source = bitmap;
                ImageGrid.Items.Add(image);
            }
            catch (Exception)
            {
                // Invalid uri, try again
                FetchDecodedImage();
            }
        }
示例#4
0
        public void TestDownloadHandler()
        {
            _imageRequest = ImageRequestBuilder
                            .NewBuilderWithSource(IMAGE_URL)
                            .SetProgressiveRenderingEnabled(true)
                            .Build();

            _producerContext = new SettableProducerContext(
                _imageRequest,
                $"{ _imageRequest.SourceUri.ToString() }2",
                _producerListener,
                new object(),
                RequestLevel.FULL_FETCH,
                false,
                true,
                Priority.MEDIUM);

            _networkFetchProducer.ProduceResults(_consumer, _producerContext);

            // Wait for callback
            _completion.WaitOne();

            Assert.IsTrue(_onNewResultImplCalls > 1);
            Assert.IsTrue(_intermediateResultProducerEventCalls > 1);
        }
示例#5
0
        public void TestExceptionInFetchImage()
        {
            _imageRequest = ImageRequestBuilder
                            .NewBuilderWithSource(FAILURE_URL)
                            .SetProgressiveRenderingEnabled(true)
                            .Build();

            _producerContext = new SettableProducerContext(
                _imageRequest,
                _imageRequest.SourceUri.ToString(),
                _producerListener,
                new object(),
                RequestLevel.FULL_FETCH,
                false,
                true,
                Priority.MEDIUM);

            _networkFetchProducer.ProduceResults(_consumer, _producerContext);

            // Wait for callback
            _completion.WaitOne();

            Assert.IsTrue(_onProducerFinishWithFailureFuncCalls == 1);
            Assert.AreEqual(_internalRequestId, _imageRequest.SourceUri.ToString());
            Assert.AreEqual(_internalProducerName, NetworkFetchProducer.PRODUCER_NAME);
            Assert.IsNotNull(_internalError);
            Assert.IsNull(_internalExtraMap);
        }
示例#6
0
        public void Initialize()
        {
            _request       = ImageRequestBuilder.NewBuilderWithSource(new Uri("http://request")).Build();
            _callerContext = new object();
            _error         = new Exception();
            _immutableMap  = new Dictionary <string, string>();

            ProducerListenerImpl producerListener1 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls1; },
                (_, __, ___) => { ++_onProducerEventFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls1; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls1; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls1; },
                (_) => { ++_requiresExtraMapFuncCalls1; return(false); });

            ProducerListenerImpl producerListener2 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls2; },
                (_, __, ___) => { ++_onProducerEventFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls2; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls2; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls2; },
                (_) => { ++_requiresExtraMapFuncCalls2; return(false); });

            ProducerListenerImpl producerListener3 = new ProducerListenerImpl(
                (_, __) => { ++_onProducerStartFuncCalls3; },
                (_, __, ___) => { ++_onProducerEventFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithSuccessFuncCalls3; },
                (_, __, ___, ____) => { ++_onProducerFinishWithFailureFuncCalls3; },
                (_, __, ___) => { ++_onProducerFinishWithCancellationFuncCalls3; },
                (_) => { ++_requiresExtraMapFuncCalls3; return(false); });

            _requestListener1 = new RequestListenerImpl(
                producerListener1,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls1; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall1; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls1; },
                (_) => { ++_onRequestCancellationFuncCalls1; });

            _requestListener2 = new RequestListenerImpl(
                producerListener2,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls2; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall2; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls2; },
                (_) => { ++_onRequestCancellationFuncCalls2; });

            _requestListener3 = new RequestListenerImpl(
                producerListener3,
                (_, __, ___, ____) => { ++_onRequestStartFuncCalls3; },
                (_, __, ___) => { ++_onRequestSuccessFuncCall3; },
                (_, __, ___, ____) => { ++_onRequestFailureFuncCalls3; },
                (_) => { ++_onRequestCancellationFuncCalls3; });

            _listenerManager = new ForwardingRequestListener(new HashSet <IRequestListener>
            {
                _requestListener1,
                _requestListener2,
                _requestListener3
            });
        }
        /// <summary>
        /// Returns whether the image is stored in the disk cache.
        /// Performs disk cache check synchronously. It is not
        /// recommended to use this unless you know what exactly
        /// you are doing. Disk cache check is a costly operation,
        /// the call will block the caller thread until the cache
        /// check is completed.
        /// </summary>
        /// <param name="uri">
        /// The uri for the image to be looked up.
        /// </param>
        /// <param name="cacheChoice">
        /// The cacheChoice for the cache to be looked up.
        /// </param>
        /// <returns>
        /// true if the image was found in the disk cache,
        /// false otherwise.
        /// </returns>
        public bool IsInDiskCacheSync(Uri uri, CacheChoice cacheChoice)
        {
            ImageRequest imageRequest = ImageRequestBuilder
                                        .NewBuilderWithSource(uri)
                                        .SetCacheChoice(cacheChoice)
                                        .Build();

            return(IsInDiskCacheSync(imageRequest));
        }
        public void getSize(string uriString, IPromise promise)
        {
            if (string.IsNullOrEmpty(uriString))
            {
                promise.Reject(ErrorInvalidUri, "Cannot get the size of an image for an empty URI.");
                return;
            }

            var uri            = new Uri(uriString);
            var imagePipeline  = ImagePipelineFactory.Instance.GetImagePipeline();
            var request        = ImageRequestBuilder.NewBuilderWithSource(uri).Build();
            var dataSource     = imagePipeline.FetchDecodedImage(request, null);
            var dataSubscriber = new BaseDataSubscriberImpl <CloseableReference <CloseableImage> >(
                response =>
            {
                if (!response.IsFinished())
                {
                    return(Task.CompletedTask);
                }

                CloseableReference <CloseableImage> reference = response.GetResult();
                if (reference != null)
                {
                    try
                    {
                        CloseableImage image = reference.Get();
                        promise.Resolve(new JObject
                        {
                            { "width", image.Width },
                            { "height", image.Height },
                        });
                    }
                    catch (Exception ex)
                    {
                        promise.Reject(ErrorGetSizeFailure, ex.Message);
                    }
                    finally
                    {
                        CloseableReference <CloseableImage> .CloseSafely(reference);
                    }
                }
                else
                {
                    promise.Reject(ErrorGetSizeFailure, Invariant($"Invalid URI '{uri}' provided."));
                }

                return(Task.CompletedTask);
            },
                response =>
            {
                promise.Reject(ErrorGetSizeFailure, response.GetFailureCause());
            });

            dataSource.Subscribe(dataSubscriber, FBCore.Concurrency.CallerThreadExecutor.Instance);
        }
示例#9
0
        public async Task TestFetchLocalJpegExif()
        {
            var imageRequest = ImageRequestBuilder
                               .NewBuilderWithSource(LOCAL_JPEG_EXIF_URL)
                               .SetAutoRotateEnabled(true)
                               .Build();

            var bitmap = await _imagePipeline.FetchDecodedBitmapImageAsync(imageRequest)
                         .ConfigureAwait(false);

            await DispatcherHelpers.RunOnDispatcherAsync(() =>
            {
                Assert.IsTrue(bitmap.PixelWidth != 0);
                Assert.IsTrue(bitmap.PixelHeight != 0);
            });
        }
示例#10
0
        public void UpdateImage(Image image, Uri uri)
        {
            ImageRequest request = ImageRequestBuilder
                                   .NewBuilderWithSource(uri)
                                   .SetProgressiveRenderingEnabled(true)
                                   .Build();

            var dataSource     = _imagePipeline.FetchDecodedImage(request, null);
            var dataSubscriber = new BaseDataSubscriberImpl <CloseableReference <CloseableImage> >(
                async bitmapDataSource =>
            {
                if (bitmapDataSource != null)
                {
                    var reference = bitmapDataSource.GetResult();

                    try
                    {
                        SoftwareBitmap bitmap = ((CloseableBitmap)reference.Get()).UnderlyingBitmap;

                        await DispatcherHelpers.RunOnDispatcherAsync(() =>
                        {
                            var writeableBitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                            bitmap.CopyToBuffer(writeableBitmap.PixelBuffer);
                            image.Source = writeableBitmap;
                        })
                        .ConfigureAwait(false);
                    }
                    finally
                    {
                        CloseableReference <CloseableImage> .CloseSafely(reference);
                    }
                }
            },
                _ => { });

            dataSource.Subscribe(dataSubscriber, CallerThreadExecutor.Instance);
        }
 public void TestIsDiskCacheEnabledByDefault3()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("ms-appx:///request"));
     Assert.IsFalse(builder.IsDiskCacheEnabled);
 }
 public void TestIsDiskCacheEnabledByDefault2()
 {
     ImageRequestBuilder builder =
         ImageRequestBuilder.NewBuilderWithSource(new Uri("https://request"));
     Assert.IsTrue(builder.IsDiskCacheEnabled);
 }
示例#13
0
 public void Initialize()
 {
     _requestBuilder = ImageRequestBuilder.NewBuilderWithSource(IMAGE_URL);
 }