Пример #1
0
        /// <summary>
        /// Set up all the handlers for this CacheEntry
        /// </summary>
        /// <param name="objectType"></param>
        /// <param name="context"></param>
        /// <param name="proxyCallback">callback that should be invoked when update is finished</param>
        public CacheEntry(LoadContext context, Type objectType, Action<CacheEntry> proxyCallback)
        {
            _proxyComplitionCallback = proxyCallback;
            LoadContext = context;
            ObjectType = objectType;

            _stats = new EntryStats(this);

            // set up our value loaders.
            //
            _cacheLoader = new CacheValueLoader(this);
            _cacheLoader.Loading += ValueLoader_Loading;
            _cacheLoader.ValueAvailable += Cached_ValueAvailable;
            _cacheLoader.LoadFailed += CacheLoader_Failed;

            _liveLoader = new LiveValueLoader(this);
            _liveLoader.Loading += ValueLoader_Loading;
            _liveLoader.ValueAvailable += Live_ValueAvailable;
            _liveLoader.LoadFailed += LiveValueLoader_Failed;

            NextCompletedAction = new UpdateCompletionHandler(this);
        }
Пример #2
0
            /// <summary>
            /// Fetch the data for this loader.
            /// </summary>
            /// <param name="force"></param>
            public void FetchData(bool force)
            {
                lock (this)
                {
                    NextCompletedAction = CacheEntry.NextCompletedAction;

                    // make sure we're not already in a loading state.
                    //
                    switch (LoadState)
                    {
                        case DataLoadState.Loading:
                        case DataLoadState.Processing:
                            return;
                        case DataLoadState.Loaded:
                            FireLoading();
                            ProcessData();
                            return;
                    }

                    LoadState = DataLoadState.Loading;

                    try
                    {
                        // kick off the derived class's load
                        if (!FetchDataCore(force))
                        {
                            LoadState = DataLoadState.None;
                        }
                        else
                        {
                            FireLoading();
                        }
                    }
                    catch (Exception ex)
                    {
                        LoadState = DataLoadState.Failed;
                        OnLoadFailed(ex);
                        return;
                    }
                }
            }