internal Task FetchASync( FetchState fetchState, INetworkFetcherCallback callback, CancellationToken token) { return(_executorService.Execute( async() => { try { using (var response = await DownloadFrom(fetchState.Uri, MAX_REDIRECTS, token).ConfigureAwait(false)) { if (response != null) { using (var inputStream = await response.Content.ReadAsInputStreamAsync().AsTask().ConfigureAwait(false)) using (var stream = inputStream.AsStreamForRead()) { callback.OnResponse(stream, -1); } } } } catch (Exception e) { callback.OnFailure(e); } }) .Result); }
/// <summary> /// Initiates the network fetch and informs the producer when a /// response is received via the provided callback. /// </summary> /// <param name="fetchState"> /// The fetch-specific state. /// </param> /// <param name="callback"> /// The callback used to inform the network fetch producer. /// </param> public override void Fetch( FetchState fetchState, INetworkFetcherCallback callback) { _tasks.Add(fetchState.Id, token => FetchASync(fetchState, callback, token)); fetchState.Context.AddCallbacks( new BaseProducerContextCallbacks( () => { bool isCanceled = _tasks.Cancel(fetchState.Id); if (isCanceled) { callback.OnCancellation(); } }, () => { }, () => { }, () => { })); }
public override void Fetch(Java.Lang.Object p0, INetworkFetcherCallback p1) { RawFetch((global::Com.Facebook.Imagepipeline.Producers.FetchState)p0, p1); }
/// <summary> /// Initiates the network fetch and informs the producer when /// a response is received via the provided callback. /// </summary> /// <param name="fetchState">The fetch-specific state.</param> /// <param name="callback"> /// The callback used to inform the network fetch producer. /// </param> public abstract void Fetch(FETCH_STATE fetchState, INetworkFetcherCallback callback);