void CacheLoader_Failed(object s, ExceptionEventArgs e) { // if the cache load failed, make sure we're doing a live load. // if we aren't, kick one off. // NextCompletedAction.UnregisterLoader(LoaderType.CacheLoader); if (!_liveLoader.IsBusy && !HaveWeEverGottenALiveValue) { NextCompletedAction.RegisterActiveLoader(LoaderType.LiveLoader); _liveLoader.FetchData(true); } }
/// <summary> /// Start loading operation /// </summary> /// <param name="force">indicates if loading should be forced</param> /// <param name="loader">loader that should be invoked</param> private void StartLoading(bool force, ValueLoader loader) { NextCompletedAction.RegisterActiveLoader(loader.LoaderType); try { loader.FetchData(force); } catch (Exception) { NextCompletedAction.UnregisterLoader(loader.LoaderType); throw; } }
/// <summary> /// Notify any listeners of completion of the load, or of any exceptions /// that occurred during loading. /// </summary> /// <param name="loader"></param> /// <param name="ex"></param> private void NotifyCompletion(ValueLoader loader, Exception ex) { IUpdatable iupd = ValueInternal as IUpdatable; if (iupd != null) { iupd.IsUpdating = false; } ModelItemBase mib = ValueInternal as ModelItemBase; if (mib != null) { try { mib.OnLoadCompleted(ex, false); } catch (Exception) { } } LoaderType loaderType = loader != null ? loader.LoaderType : LoaderType.CacheLoader; // UpdateCompletionHandler makes sure to call handler on UI thread // try { if (ex == null) { NextCompletedAction.OnSuccess(loaderType); if (_proxyComplitionCallback != null) { _proxyComplitionCallback(this); } } else { NextCompletedAction.OnError(loaderType, ex); } } finally { // free our value root // _rootedValue = null; } }
/// <summary> /// The CacheLoader has finished loading and is handing us a new value. /// </summary> void Cached_ValueAvailable(object sender, ValueAvailableEventArgs e) { // live loader has data, so we don't care about it anymore. // if (HaveWeEverGottenALiveValue) { NextCompletedAction.UnregisterLoader(LoaderType.CacheLoader); return; } // copy the cached value into our state. // UpdateFrom((ValueLoader)sender, e.Value); SetBoolValue(UsingCachedValueMask, true); UpdateExpiration(e.UpdateTime, e.Value as ICachedItem); }