/// <summary> /// Loads and gets UImage using defined parameters. /// IMPORTANT: It throws image loading exceptions - you should handle them /// </summary> /// <returns>The PImage async.</returns> /// <param name="parameters">Parameters.</param> public static Task <NSImage> AsNSImageAsync(this TaskParameter parameters) { var target = new NSImageTarget(); var userErrorCallback = parameters.OnError; var finishCallback = parameters.OnFinish; var tcs = new TaskCompletionSource <NSImage>(); parameters .Error(ex => { tcs.TrySetException(ex); userErrorCallback?.Invoke(ex); }) .Finish(scheduledWork => { finishCallback?.Invoke(scheduledWork); tcs.TrySetResult(target.PImage); }); if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } var task = ImageService.CreateTask(parameters, target); ImageService.Instance.LoadImage(task); return(tcs.Task); }
public static Task <WriteableBitmap> AsWriteableBitmapAsync(this TaskParameter parameters) { BitmapTarget target = new BitmapTarget(); Action <Exception> userErrorCallback = parameters.OnError; Action <IScheduledWork> finishCallback = parameters.OnFinish; TaskCompletionSource <WriteableBitmap> tcs = new TaskCompletionSource <WriteableBitmap>(); parameters.Error(delegate(Exception ex) { tcs.TrySetException(ex); userErrorCallback?.Invoke(ex); }).Finish(delegate(IScheduledWork scheduledWork) { finishCallback?.Invoke(scheduledWork); tcs.TrySetResult(target.BitmapSource as WriteableBitmap); }); if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } IImageLoaderTask task = ImageService.CreateTask(parameters, target); ImageService.Instance.LoadImage(task); return(tcs.Task); }
public static IScheduledWork Into <TImageView>(this TaskParameter parameters, ITarget <BitmapSource, TImageView> target) where TImageView : class { if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } IImageLoaderTask imageLoaderTask = ImageService.CreateTask(parameters, target); ImageService.Instance.LoadImage(imageLoaderTask); return(imageLoaderTask); }
private static IScheduledWork Into <TImageView>(this TaskParameter parameters, ITarget <WriteableBitmap, TImageView> target) where TImageView : class { if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } var task = CreateTask(parameters, target); ImageService.Instance.LoadImage(task); return(task); }
/// <summary> /// Loads the image into given ImageViewAsync using defined parameters. /// </summary> /// <param name="parameters">Parameters for loading the image.</param> /// <param name="imageView">Image view that should receive the image.</param> public static IScheduledWork Into(this TaskParameter parameters, ImageViewAsync imageView) { var target = new ImageViewTarget(imageView); if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } var task = ImageService.CreateTask(parameters, target); ImageService.Instance.LoadImage(task); return(task); }
/// <summary> /// Loads and gets BitmapDrawable using defined parameters. /// IMPORTANT: you should call SetNoLongerDisplayed method if drawable is no longer displayed /// IMPORTANT: It throws image loading exceptions - you should handle them /// </summary> /// <returns>The bitmap drawable async.</returns> /// <param name="parameters">Parameters.</param> public static Task <BitmapDrawable> AsBitmapDrawableAsync(this TaskParameter parameters) { var target = new BitmapTarget(); var userErrorCallback = parameters.OnError; var finishCallback = parameters.OnFinish; var tcs = new TaskCompletionSource <BitmapDrawable>(); List <Exception> exceptions = null; parameters .Error(ex => { if (exceptions == null) { exceptions = new List <Exception>(); } exceptions.Add(ex); userErrorCallback?.Invoke(ex); }) .Finish(scheduledWork => { finishCallback?.Invoke(scheduledWork); if (exceptions != null) { tcs.TrySetException(exceptions); } else { tcs.TrySetResult(target.BitmapDrawable as BitmapDrawable); } }); if (parameters.Source != ImageSource.Stream && string.IsNullOrWhiteSpace(parameters.Path)) { target.SetAsEmpty(null); parameters.TryDispose(); return(null); } var task = CreateTask(parameters, target); ImageService.Instance.LoadImage(task); return(tcs.Task); }