示例#1
0
 /// <summary>
 /// A subroutine for loading the lookup table if it's not loaded.
 /// </summary>
 /// <param name="type">The type of the lookup table to load.</param>
 /// <param name="onReadyCallback">The method to call when the loading is complete if it happened asynchronously.</param>
 protected virtual void LoadLookupTable(string type, LookupTableReady onReadyCallback)
 {
     // Protection from queuing up listeners for a table type that is not supported,
     // which will never be notified thereby creating a memory leak.
     if (!cacheLoaders.Any(cl => cl.IsSupported(CacheType, type)))
     {
         notifyQueues.Remove(type);
         return;
     }
     if (notifyQueues.ContainsKey(type))
     { // The table is already being loaded, so just add the listener to the queue to be notified.
         LookupTableReady notify = notifyQueues[type];
         if (notify == null)
         {
             notify = onReadyCallback;
         }
         else if (onReadyCallback != null)
         {
             notify += onReadyCallback;
         }
         notifyQueues[type] = notify;
     }
     else
     { // Set up the notify queue and start loading.
         notifyQueues[type] = onReadyCallback;
         foreach (ILookupCacheLoader cl in cacheLoaders)
         {
             cl.Load(this, type);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Gets a lookup table of the specified type from the cache.
 /// </summary>
 /// <param name="type">Lookup table type.</param>
 /// <param name="onReadyCallback">The method to call when the loading is complete if it happened asynchronously.</param>
 /// <returns>A lookup table of the specified type or <c>null</c> if no lookup table can be found.</returns>
 public virtual LookupTable GetLookupTable(string type, LookupTableReady onReadyCallback)
 {
     if (type == null)
     {
         return(null);
     }
     rwLock.EnterUpgradeableReadLock();
     try
     {
         if (!cache.ContainsKey(type))
         {
             LoadLookupTable(type, onReadyCallback);
         }
         return(cache.ContainsKey(type) ? cache[type] : null);
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
 }
示例#3
0
 /// <summary>
 /// A subroutine for loading the lookup table if it's not loaded.
 /// </summary>
 /// <param name="type">The type of the lookup table to load.</param>
 /// <param name="onReadyCallback">The method to call when the loading is complete if it happened asynchronously.</param>
 protected virtual void LoadLookupTable(string type, LookupTableReady onReadyCallback)
 {
     // Protection from queuing up listeners for a table type that is not supported,
     // which will never be notified thereby creating a memory leak.
     if (!cacheLoaders.Any(cl => cl.IsSupported(CacheType, type)))
     {
         notifyQueues.Remove(type);
         return;
     }
     if (notifyQueues.ContainsKey(type))
     { // The table is already being loaded, so just add the listener to the queue to be notified.
         LookupTableReady notify = notifyQueues[type];
         if (notify == null) notify = onReadyCallback;
         else if (onReadyCallback != null) notify += onReadyCallback;
         notifyQueues[type] = notify;
     }
     else
     { // Set up the notify queue and start loading.
         notifyQueues[type] = onReadyCallback;
         foreach (ILookupCacheLoader cl in cacheLoaders) cl.Load(this, type);
     }
 }
示例#4
0
 /// <summary>
 /// Gets a lookup table of the specified type from the cache.
 /// </summary>
 /// <param name="type">Lookup table type.</param>
 /// <param name="onReadyCallback">The method to call when the loading is complete if it happened asynchronously.</param>
 /// <returns>A lookup table of the specified type or <c>null</c> if no lookup table can be found.</returns>
 public virtual LookupTable GetLookupTable(string type, LookupTableReady onReadyCallback)
 {
     if (type == null) return null;
     #if SILVERLIGHT
     if (!cache.ContainsKey(type)) LoadLookupTable(type, onReadyCallback);
     return cache.ContainsKey(type) ? cache[type] : null;
     #else
     rwLock.EnterUpgradeableReadLock();
     try
     {
         if (!cache.ContainsKey(type)) LoadLookupTable(type, onReadyCallback);
         return cache.ContainsKey(type) ? cache[type] : null;
     }
     finally
     {
         rwLock.ExitUpgradeableReadLock();
     }
     #endif
 }