public int?SetupLoadNotification(string key, CacheNotificationAction action, Action <LoadingStatus, int, string> callback) { foreach (var cacheDataController in Cache.Where(cacheDataController => cacheDataController.InternalData.Key == key)) { return(SetupLoadNotification(action, callback, cacheDataController)); } return(null); }
public void SetupInvalidateNotification(string key, CacheNotificationAction action, Action callback) { foreach (var cacheDataController in Cache.Where(cacheDataController => cacheDataController.InternalData.Key == key)) { switch (action) { case CacheNotificationAction.Add: cacheDataController.InvalidateNotificationEvent += callback; break; case CacheNotificationAction.Remove: break; default: throw new ArgumentOutOfRangeException("action"); } } }
/// <summary> /// Subscribe/Unsubscribe to the LoadNotification by dataKey /// </summary> /// <param name="action">Specifies the action to be taken</param> /// <param name="callback"></param> /// <param name="cacheDataController"></param> /// <returns>Returns a unique Loading Key that will be use to identify when a IDataCache is being loaded</returns> private int?SetupLoadNotification(CacheNotificationAction action, Action <LoadingStatus, int, string> callback, CacheDataController cacheDataController) { switch (action) { case CacheNotificationAction.Add: cacheDataController.LoadingKey = Generator.GetNextLoadingKey; cacheDataController.LoadStatusNotificationEvent += callback; return(cacheDataController.LoadingKey); case CacheNotificationAction.Remove: // ReSharper disable DelegateSubtraction cacheDataController.LoadStatusNotificationEvent -= callback; // ReSharper restore DelegateSubtraction return(null); default: throw new ArgumentOutOfRangeException("action"); } }