/// <summary>
        /// Parse the property name and initialize necessary extractor and
        /// updater.
        /// </summary>
        protected internal void Init()
        {
            // allow composite property name (not documented)
            string name   = m_name;
            int    ofLast = name.LastIndexOf('.');
            string prop   = name.Substring(ofLast + 1);

            IValueExtractor extractor = new ReflectionExtractor(prop); //(m_useIs ? "is" : "get") +
            IValueUpdater   updater   = new ReflectionUpdater(prop); //"set" +

            if (ofLast > 0)
            {
                string[] array = name.Substring(0, ofLast).Split(new char[] {'.'});
                int      count = array.Length;

                IValueExtractor[] veGet = new IValueExtractor[count + 1];
                IValueExtractor[] vePut = new IValueExtractor[count];
                for (int i = 0; i < count; i++)
                {
                    veGet[i] = vePut[i] = new ReflectionExtractor(array[i]); //"get" +
                }
                veGet[count] = extractor;

                extractor = new ChainedExtractor(veGet);
                updater   = new CompositeUpdater(count == 1 ? vePut[0] : new ChainedExtractor(vePut),
                                                 updater);

            }
            m_extractor = extractor;
            m_updater   = updater;
        }
Пример #2
0
        public void TestUpdaterProcessor()
        {
            Temperature     belgrade   = new Temperature(25, 'c', 1);
            IValueUpdater   updater    = new ReflectionUpdater("Value");
            IEntryProcessor processor  = new UpdaterProcessor(updater, 0);
            IEntryProcessor processor1 = new UpdaterProcessor(updater, 0);

            Assert.AreEqual(processor, processor1);
            Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode());
            Assert.AreEqual(processor.ToString(), processor1.ToString());

            LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "belgrade", belgrade);
            processor.Process(entry);
            Assert.AreEqual(0, ((Temperature)entry.Value).Value);

            // testing on Remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Temperature bgd = new Temperature(25, 'c', 12);
            Temperature nyc = new Temperature(99, 'f', 12);

            cache.Insert("BGD", bgd);
            cache.Insert("NYC", nyc);

            updater   = new ReflectionUpdater("setValue");
            processor = new UpdaterProcessor(updater, 0);
            object newTemp = cache.Invoke("BGD", processor);

            Temperature newBGD = (Temperature)cache["BGD"];

            Assert.AreEqual(0, newBGD.Value);

            updater = new ReflectionUpdater("setValue");
            IValueUpdater compositeupdater = new CompositeUpdater(IdentityExtractor.Instance, updater);

            processor = new UpdaterProcessor(compositeupdater, 5);
            cache.Invoke("NYC", processor);
            Temperature newNYC = (Temperature)cache["NYC"];

            Assert.AreEqual(5, newNYC.Value);

            CacheFactory.Shutdown();
        }