private IDataSource <CloseableReference <T> > SubmitFetchRequest <T>(
            IProducer <CloseableReference <T> > producerSequence,
            ImageRequest imageRequest,
            RequestLevel lowestPermittedRequestLevelOnSubmit,
            object callerContext)
        {
            IRequestListener requestListener = GetRequestListenerForRequest(imageRequest);

            try
            {
                RequestLevel lowestPermittedRequestLevel = RequestLevel.GetMax(
                    imageRequest.LowestPermittedRequestLevel,
                    lowestPermittedRequestLevelOnSubmit);

                SettableProducerContext settableProducerContext = new SettableProducerContext(
                    imageRequest,
                    GenerateUniqueFutureId(),
                    requestListener,
                    callerContext,
                    lowestPermittedRequestLevel.Value,
                    /* isPrefetch */ false,
                    imageRequest.IsProgressiveRenderingEnabled ||
                    !UriUtil.IsNetworkUri(imageRequest.SourceUri),
                    imageRequest.Priority);

                return(CloseableProducerToDataSourceAdapter <T> .Create(
                           producerSequence,
                           settableProducerContext,
                           requestListener));
            }
            catch (Exception exception)
            {
                return(DataSources.ImmediateFailedDataSource <CloseableReference <T> >(exception));
            }
        }
Beispiel #2
0
        public void Initialize()
        {
            // Initializes the mock RequestListener
            ProducerListenerImpl producerListener = new ProducerListenerImpl(
                (_, __) => { },
                (_, __, ___) => { },
                (_, __, ___) => { },
                (_, __, ___, ____) => { },
                (_, __, ___) => { },
                (_) => { return(false); });

            _requestListener = new RequestListenerImpl(
                producerListener,
                (imageRequest, callerContext, requestId, isPrefetch) =>
            {
                _onRequestStartInvocation = true;
                _internalImageRequest     = imageRequest;
                _internalCallerContext    = callerContext;
                _internalRequestId        = requestId;
                _internalIsPrefetch       = isPrefetch;
            },
                (imageRequest, requestId, isPrefetch) =>
            {
                _onRequestSuccessInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalIsPrefetch         = isPrefetch;
            },
                (imageRequest, requestId, exception, isPrefetch) =>
            {
                _onRequestFailureInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalException          = exception;
                _internalIsPrefetch         = isPrefetch;
            },
                (requestId) =>
            {
                _onRequestCancellationInvocation = true;
                _internalRequestId = requestId;
            });
            _resourceReleaser = new ResourceReleaserImpl <object>(_ => { });
            _resultRef1       = CloseableReference <object> .of(new object(), _resourceReleaser);

            _resultRef2 = CloseableReference <object> .of(new object(), _resourceReleaser);

            _resultRef3 = CloseableReference <object> .of(new object(), _resourceReleaser);

            _dataSubscriber1 = new MockDataSubscriber <CloseableReference <object> >();
            _dataSubscriber2 = new MockDataSubscriber <CloseableReference <object> >();

            _internalIsPrefetch      = true;
            _settableProducerContext = new SettableProducerContext(
                IMAGE_REQUEST,
                REQUEST_ID,
                producerListener,
                CALLER_CONTEXT,
                RequestLevel.FULL_FETCH,
                IS_PREFETCH,
                true,
                Priority.HIGH);
            _producer = new ProducerImpl <CloseableReference <object> >(
                (consumer, _) =>
            {
                _internalConsumer = consumer;
            });
            _dataSource = CloseableProducerToDataSourceAdapter <object> .Create(
                _producer,
                _settableProducerContext,
                _requestListener);

            Assert.IsTrue(_onRequestStartInvocation);
            Assert.AreSame(_internalImageRequest, IMAGE_REQUEST);
            Assert.AreSame(_internalCallerContext, CALLER_CONTEXT);
            Assert.AreSame(_internalRequestId, REQUEST_ID);
            Assert.IsFalse(_internalIsPrefetch);
            Assert.IsNotNull(_internalConsumer);
            _onRequestStartInvocation = false;

            _dataSource.Subscribe(_dataSubscriber1, CallerThreadExecutor.Instance);
        }