示例#1
0
        internal static EventType GetEventType(DataCacheOperations operation)
        {
            EventType eventType = (EventType)0;

            var addItem = (operation & DataCacheOperations.AddItem) == DataCacheOperations.AddItem;

            var updateItem = (operation & DataCacheOperations.ReplaceItem) == DataCacheOperations.ReplaceItem;

            var removeItem = (operation & DataCacheOperations.RemoveItem) == DataCacheOperations.RemoveItem;

            var createRegion = (operation & DataCacheOperations.CreateRegion) == DataCacheOperations.CreateRegion;

            var removeRegion = (operation & DataCacheOperations.RemoveRegion) == DataCacheOperations.RemoveRegion;

            var clearRegion = (operation & DataCacheOperations.ClearRegion) == DataCacheOperations.ClearRegion;

            if (addItem || createRegion || clearRegion)
            {
                eventType |= EventType.ItemAdded;
            }

            if (updateItem)
            {
                eventType |= EventType.ItemUpdated;
            }

            if (removeItem || removeRegion)
            {
                eventType |= EventType.ItemRemoved;
            }

            return(eventType);
        }
示例#2
0
        private static bool PrepareClient(string server_name)
        {
            lastErrorMessage = String.Empty;

            try
            {
                //-------------------------
                // Configure Cache Client
                //-------------------------

                //Define Array for 1 Cache Host
                List <DataCacheServerEndpoint> servers = new List <DataCacheServerEndpoint>(1)
                {
                    new DataCacheServerEndpoint(server_name, 22233)
                };

                //Specify Cache Host Details
                //  Parameter 1 = host name
                //  Parameter 2 = cache port number

                //Create cache configuration
                DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration
                {
                    Servers              = servers,
                    SecurityProperties   = new DataCacheSecurity(DataCacheSecurityMode.None, DataCacheProtectionLevel.None),
                    LocalCacheProperties = new DataCacheLocalCacheProperties()
                };

                //Disable exception messages since this sample works on a cache aside
                //DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);

                //Pass configuration settings to cacheFactory constructor
                myCacheFactory = new DataCacheFactory(configuration);

                //Get reference to named cache called "default"
                myDefaultCache = myCacheFactory.GetCache("default");

                //specify all possible item and region operations
                const DataCacheOperations itemCacheOperations = DataCacheOperations.AddItem |
                                                                DataCacheOperations.ReplaceItem |
                                                                DataCacheOperations.RemoveItem |
                                                                DataCacheOperations.ClearRegion |
                                                                DataCacheOperations.CreateRegion;

                //add cache-level notification callback
                //all cache operations from a notifications-enabled cache
                DataCacheNotificationDescriptor ndCacheLvlAllOps = myDefaultCache.AddRegionLevelCallback("SobekCM", itemCacheOperations, myCacheLvlDelegate);
                myDefaultCache.CreateRegion(regionName);

                return(true);
            }
            catch (Exception ee)
            {
                lastErrorMessage = ee.Message;
                return(false);
            }
        }
 private void ItemChangedCallbackDelegate(
     string cacheName, 
     string region, 
     string key, 
     DataCacheItemVersion version, 
     DataCacheOperations operation, 
     DataCacheNotificationDescriptor descriptior)
 {
     if(cacheKeys.Contains(key) && region == regionName)
         this.OnChanged(null);
 }
示例#4
0
 public void DataCacheItemCallBackHandler(string cacheName, string regionName, string key,
                                          DataCacheItemVersion version, DataCacheOperations cacheOperation, DataCacheNotificationDescriptor nd)
 {
     try
     {
         string result = string.Format("Time: {0} CacheName: {1}  Region {2} Key: {3} DataCacheOperation: {4}", DateTime.Now.ToLongTimeString(),
                                       cacheName, regionName, key, cacheOperation.ToString());
         rtbMontiorCache.Invoke((MethodInvoker) delegate { rtbMontiorCache.AppendText("\r\n" + result); });
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
 }
示例#5
0
        //method invoked by notification "ndCacheLvlAllOps"
        private static void myCacheLvlDelegate(string myCacheName,
                                               string myRegion,
                                               string myKey,
                                               DataCacheItemVersion itemVersion,
                                               DataCacheOperations OperationId,
                                               DataCacheNotificationDescriptor nd)
        {
            //try
            //{
            // update the key list
            if (keys != null)
            {
                if (OperationId == DataCacheOperations.RemoveItem)
                {
                    keys.Remove(myKey);
                }
                if ((OperationId == DataCacheOperations.AddItem) && (!keys.Contains(myKey)))
                {
                    // This is where we can try to guess the TYPE, based on how our system works
                    Type thisType = null;

                    if (((myKey.IndexOf("ITEM_") == 0) || (myKey.IndexOf("USERITEM") == 0)))
                    {
                        thisType = typeof(SobekCM_Item);
                    }
                    if ((thisType == null) && ((myKey.IndexOf("ITEMSEARCH_") == 0) || (myKey.IndexOf("BROWSEBY_") == 0)))
                    {
                        thisType = typeof(List <string>);
                    }
                    if ((thisType == null) && (myKey.IndexOf("SKIN_") == 0))
                    {
                        thisType = typeof(SobekCM_Skin_Object);
                    }
                    if ((thisType == null) && (myKey.IndexOf("AGGR_") == 0))
                    {
                        thisType = typeof(Item_Aggregation);
                    }


                    keys.Add(myKey, thisType);
                }
            }
            //}
            //catch
            //{

            //}
        }
        internal void CacheNotificationCallback(
            string cacheName,
            string regionName,
            string key,
            DataCacheItemVersion version,
            DataCacheOperations cacheOperation,
            DataCacheNotificationDescriptor nd)
        {
            var notification = new ItemNotification
                                   {
                                       CacheName = cacheName,
                                       RegionName = regionName,
                                       Key = key,
                                       Version = version,
                                       CacheOperation = cacheOperation,
                                       NotificationDescriptor = nd
                                   };

            _instance.BeginResumeBookmark(
                new Bookmark(WaitForItemNotification.GetNotificationBookmarkName(nd)),
                notification,
                (asr) => _instance.EndResumeBookmark(asr),
                null);
        }
 public DataCacheNotificationDescriptor AddItemLevelCallback(string key, DataCacheOperations filter, DataCacheNotificationCallback callBack, string region)
 {
     return(_cacheHandler.AddItemLevelCallback(key, filter, callBack, region));
 }
 public DataCacheNotificationDescriptor AddRegionLevelCallback(string region, DataCacheOperations filter, DataCacheNotificationCallback callBack)
 {
     return(_cacheHandler.AddRegionLevelCallback(region, filter, callBack));
 }
 public DataCacheNotificationDescriptor AddCacheLevelCallback(DataCacheOperations filter, DataCacheNotificationCallback callBack)
 {
     return(_cacheHandler.AddCacheLevelCallback(filter, callBack));
 }
 public BaseOperationNotification(string cacheName, DataCacheOperations opType, DataCacheItemVersion version)
 {
     CacheName     = cacheName;
     OperationType = opType;
     Version       = version;
 }
示例#11
0
 static void CacheEvent(string cacheName, string regionName, string itemName, 
                        DataCacheItemVersion v, DataCacheOperations ops, DataCacheNotificationDescriptor d)
 {
     Console.WriteLine(String.Format("CacheEvent Occurred: {0} {1} {2} {3} {4} {5}",cacheName,regionName,itemName,v,ops,d));
 }
示例#12
0
 public DataCacheOperationDescriptor(string cacheName, string regionName, string key, DataCacheOperations opType, DataCacheItemVersion version) : base(cacheName, opType, version)
 {
     RegionName = regionName;
     Key        = key;
 }
        //method invoked by notification "ndCacheLvlAllOps"
        private static void myCacheLvlDelegate(string myCacheName,
            string myRegion,
            string myKey,
            DataCacheItemVersion itemVersion,
            DataCacheOperations OperationId,
            DataCacheNotificationDescriptor nd)
        {
            //try
            //{
                // update the key list
                if (keys != null)
                {
                    if (OperationId == DataCacheOperations.RemoveItem)
                        keys.Remove(myKey);
                    if ((OperationId == DataCacheOperations.AddItem) && (!keys.Contains(myKey)))
                    {
                        // This is where we can try to guess the TYPE, based on how our system works
                        Type thisType = null;

                        if (((myKey.IndexOf("ITEM_") == 0) || (myKey.IndexOf("USERITEM") == 0)))
                        {
                            thisType = typeof(SobekCM_Item);
                        }
                        if ((thisType == null) && ((myKey.IndexOf("ITEMSEARCH_") == 0) || ( myKey.IndexOf("BROWSEBY_") == 0 )))
                        {
                            thisType = typeof(List<string>);
                        }
                        if ((thisType == null) && (myKey.IndexOf("SKIN_") == 0))
                        {
                            thisType = typeof(SobekCM_Skin_Object);
                        }
                        if ((thisType == null) && (myKey.IndexOf("AGGR_") == 0))
                        {
                            thisType = typeof(Item_Aggregation);
                        }

                        keys.Add(myKey, thisType);
                    }
                }
            //}
            //catch
            //{

            //}
        }