Пример #1
0
        private void btnMonitorCacheItem_Click(object sender, EventArgs e)
        {
            string key = txtMonitorItem.Text.Trim();

            if (myCache == null)
            {
                UpdateStatus("First click Connect To Cache");
                return;
            }

            if (key.Length < 1)
            {
                MessageBox.Show("You must enter at least 1 valid key to montior.");
                return;
            }


            try
            {
                DataCacheNotificationDescriptor dcnd = myCache.AddItemLevelCallback(key,
                                                                                    DataCacheOperations.AddItem | DataCacheOperations.RemoveItem | DataCacheOperations.ReplaceItem,
                                                                                    DataCacheItemCallBackHandler);

                callbacks.Add(dcnd);

                //lstboxMontiorItemHistory.Items.Add("Time: " + DateTime.Now.ToLongTimeString() + " Key: " + key + " has been added to monitor list");
                rtbMontiorCache.AppendText("\r" + "Time: " + DateTime.Now.ToLongTimeString() + " Key: " + key + " has been added to monitor list");

                UpdateStatus("Setup ItemLevelCallBack for Item.");
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Пример #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
        //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 BulkNotificationCallback(
            string cacheName,
            IEnumerable<DataCacheOperationDescriptor> operations,
            DataCacheNotificationDescriptor nd)
        {
            var notification = new BulkNotification
                                   {
                                       CacheName = cacheName,
                                       Operations = operations,
                                       NotificationDescriptor = nd
                                   };

            _instance.BeginResumeBookmark(
                new Bookmark(WaitForItemNotification.GetNotificationBookmarkName(nd)),
                notification,
                (asr) => _instance.EndResumeBookmark(asr),
                null);
        }
        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);
        }
Пример #7
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));
 }
Пример #8
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);
     }
 }
 internal static string GetNotificationBookmarkName(DataCacheNotificationDescriptor nd)
 {
     return string.Format(BookmarkName, nd.CacheName, nd.DelegateId);
 }
        internal void NotificationFailureCallback(string cacheName, DataCacheNotificationDescriptor nd)
        {
            var notification = new NotificationFailure
                                   {
                                       CacheName = cacheName,
                                       NotificationDescriptor = nd
                                   };

            _instance.BeginResumeBookmark(
                new Bookmark(WaitForItemNotification.GetNotificationBookmarkName(nd)),
                notification,
                (asr) => _instance.EndResumeBookmark(asr),
                null);
        }
        //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
            //{

            //}
        }