Example #1
0
        /// <summary>
        /// Adds a Cache Data object to the Controller and returns a CacheDataController
        /// </summary>
        /// <param name="controller">Cache Controller that will manage this the Cache Data</param>
        /// <param name="type">Class type that implements ICacheData</param>
        public static CacheDataController CreateCacheData(ICacheController controller, Type type)
        {
            var data           = (ICacheData)Activator.CreateInstance(type);
            var dataController = new CacheDataController();

            dataController.Initialize(data);
            controller.Add(dataController);
            return(dataController);
        }
        private void InternalLoadDataStore()
        {
            var model = DataStore.Load();

            foreach (var data in model)
            {
                var cacheDataController = new CacheDataController();
                cacheDataController.Initialize(data);
                Cache.Add(cacheDataController);
            }
        }
        /// <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");
            }
        }
 public void Remove(CacheDataController controller)
 {
     Cache.Remove(controller);
 }
 public void Add(CacheDataController controller)
 {
     Cache.Add(controller);
 }