public virtual Task FetchPageExceptionAsync(DownloadExceptionListenerContext context) { #if NETSTANDARD2_0 return(Task.CompletedTask); #else return(Task.FromResult(false)); #endif }
private async Task DownloadPageAsync(ComicDownloadRequest request, ComicChapter chapter, ComicPage page, CancellationToken token) { var listener = request.Listener; DownloadListenerContext listenerContext = null; if (listener != null) { listenerContext = new DownloadListenerContext(request, chapter, page, token); await listener.ReadyFetchAsync(listenerContext); } if (listener != null && token.IsCancellationRequested) { await listener.CanceledAsync(listenerContext); return; } var ctx = new ComicDownloadContext(request.Entity, chapter, page, null, token); if (!request.Saver.NeedToSave(ctx)) { if (listener != null) { await listener.NotNeedToSaveAsync(listenerContext); } return; } try { if (listener != null) { await listener.BeginFetchPageAsync(listenerContext); } using (var stream = await request.Provider.GetImageStreamAsync(page.TargetUrl)) using (var destStream = streamManager.GetStream()) { DownloadSaveListenerContext saveCtx = null; if (listener != null) { saveCtx = new DownloadSaveListenerContext(request, chapter, page, token, destStream); await listener.ReadySaveAsync(saveCtx); } await stream.CopyToAsync(destStream); destStream.Seek(0, SeekOrigin.Begin); ctx = new ComicDownloadContext(request.Entity, chapter, page, destStream, token); await request.Saver.SaveAsync(ctx); if (listener != null) { await listener.EndFetchPageAsync(saveCtx); } } } catch (Exception ex) { if (listener != null) { var errCtx = new DownloadExceptionListenerContext(request, chapter, page, token, ex); await listener.FetchPageExceptionAsync(errCtx); } } if (listener != null) { await listener.ComplatedSaveAsync(listenerContext); } }
public Task FetchPageExceptionAsync(DownloadExceptionListenerContext context) { return(Task.WhenAll(this.Where(x => x != null).Select(x => x.FetchPageExceptionAsync(context)))); }