internal void LoadingComplete(ResourceLoadedEventArgs <T> args) { IsCompleted = true; Error = args.Error; Resource = args.Resource; if (_onLoad != null) { _onLoad(args); } }
/// <summary> /// Load resource async /// </summary> /// <param name="owner">Who request resource</param> /// <param name="url">Resource URL</param> /// <param name="actionOnLoad">Handler to handle load complete</param> /// <param name="actionOnStep">Handler to handle loading progress</param> /// <typeparam name="T"></typeparam> public void LoadResource <T>(object owner, string url, Action <ResourceLoadedEventArgs <T> > actionOnLoad, Action <ResourceLoadingProgressEventArgs> actionOnStep = null) where T : class { var loadingOperation = InternalLoadResource <T>(owner, url); if (loadingOperation == null) { if (actionOnLoad != null) { actionOnLoad(ResourceLoadedEventArgs <T> .CompletedError(url, new ImpossibleToLoadResourceException(string.Format("ResourceType:{0} Owner:{1} Url:{2}", typeof(T), owner, url)))); } if (_onResourceLoadError != null) { _onResourceLoadError(new ImpossibleToLoadResourceException(string.Format("ResourceType:{0} Owner:{1} Url:{2}", typeof(T), owner, url))); } return; } if (actionOnLoad != null) { if (loadingOperation.Error != null) { actionOnLoad(ResourceLoadedEventArgs <T> .CompletedError(url, loadingOperation.Error)); return; } if (loadingOperation.IsCompleted) { actionOnLoad(ResourceLoadedEventArgs <T> .CompletedSuccess(url, loadingOperation.Resource)); return; } loadingOperation.OnResourceLoaded += actionOnLoad; } if (actionOnStep != null) { loadingOperation.OnLoadStep += actionOnStep; } }
public void LoadingCanceled() { IsCanceled = true; LoadingComplete(ResourceLoadedEventArgs <T> .Canceled(Uri)); }