protected override IObservable<ImageInfo> WhenLoadedInternal(Uri uri, Size size) { return Observable.Create<ImageInfo>(observer => { if (imageData != null) { var imageInfo = new ImageInfo(uri, size, imageData) { ForceFallback = true }; observer.OnNext(imageInfo); } observer.OnCompleted(); return () => { }; }); }
private async void ProceedReqeustAsync(ImageLoadContext request) { try { var imageResponse = await WebRequest.Create(request.Uri).GetResponseAsync(); var imageData = await imageResponse.GetResponseStream().ToArrayAsync(); var resizedImageInfo = await imageData.ResizeAsync(request.Size, true); var result = new ImageInfo { Data = resizedImageInfo.Data, Size = resizedImageInfo.Size, Uri = request.Uri }; request.Observer.OnNext(result); request.Observer.OnCompleted(); } catch (WebException ex) { request.Observer.OnError(new ImageLoaderException(string.Format("An error occurred when loading the image on '{0}'", request.Uri), ex)); } catch (Exception ex) { request.Observer.OnError(new ImageLoaderException(string.Format("An error occurred when parsing loaded image on '{0}'", request.Uri), ex)); } finally { lock (this.pendingRequests) { if (this.pendingRequests.Any()) { var newRequest = this.pendingRequests.First(); this.pendingRequests.RemoveFirst(); this.ProceedReqeustAsync(newRequest); } else { this.requestsCounter--; } } } }
protected bool Equals(ImageInfo other) { return Size.Equals(other.Size) && Equals(Uri, other.Uri); }
/// <summary> /// Notifies that the image is loaded from fallback <see cref="BaseImageLoader"/>. /// </summary> /// <param name="image"> /// The loaded image. /// </param> /// <remarks> /// Use this method to save/cache the loaded image. /// </remarks> protected virtual void OnFallbackImageLoaded(ImageInfo image) { }