Esempio n. 1
0
        public Logger()
        {
            Doc = new XmlDocument();
            // since this code is in app code folder
            // we need to go one directory up
            // now we are in the root
            // get the logger directory
            // create if not exists

            if (CacheProxy.Instance().HasKey("Log"))
            {
                Doc.LoadXml(CacheProxy.Instance().GetValue("Log").ToString());
                Root = Doc.DocumentElement;
            }
            else
            {
                // Create the XmlDocument.

                XmlDeclaration xmlDeclaration = Doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                XmlElement     root           = Doc.DocumentElement;
                Doc.InsertBefore(xmlDeclaration, root);

                Root = Doc.CreateElement(string.Empty, "GrockartLog", string.Empty);

                Doc.AppendChild(Root);
                SaveXML();
            }
        }
Esempio n. 2
0
        static BigInteger Fact(int x)
        {
            if (_cache == null)
            {
                _cache = CacheProxy.For((int xx) => FactImpl(xx));
            }

            return _cache.Invoke(x);
        }
Esempio n. 3
0
 public static Logger Instance()
 {
     if (CacheProxy.Instance().HasKey("Log"))
     {
         return(logInstance);
     }
     else
     {
         logInstance = new Logger();
     }
     return(logInstance);
 }
        //获取对应的SQL 语句
        private SqlString[] getSqlString(Type entityType, OperationType operationType)
        {
            ModelMappingInfo mappingInfo = AttMappingManager.Instance.GetModelMappingInfo(entityType);
            string           xmlFileName = mappingInfo.XmlConfigFileName;
            string           sqlName     = getSqlName(operationType);

            MB.Orm.Mapping.Xml.SqlConfigHelper xmlConfig = MB.Orm.Mapping.Xml.SqlConfigHelper.Instance;

            SqlString[] sqlStrs  = xmlConfig.GetSqlString(xmlFileName, sqlName);
            string      cacheKey = GenerateCacheKey(entityType, operationType);

            CacheProxy.CacheSql(cacheKey, sqlStrs);
            return(sqlStrs);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            IFile cacheProxy = new CacheProxy();

            cacheProxy.RequestFile("eerste.txt");
            cacheProxy.RequestFile("eerste.txt");
            cacheProxy.RequestFile("tweede.txt");
            cacheProxy.RequestFile("tweede.txt");
            cacheProxy.RequestFile("eerste.txt");

            ProtectionProxy protectionProxy = new ProtectionProxy();

            protectionProxy.RequestFile("eerste.txt");
            protectionProxy.RequestFile("eerste.txt");
            Console.ReadLine();
        }
        public void GetData_DefaultExpiration()
        {
            var cache = new Mock<CacheMock>() { CallBase = true };

            var proxy = new CacheProxy<DateTime>(() => DateTime.Now, cache: cache.Object, key: KEY);

            var v1 = proxy.GetData();
            Thread.Sleep(50);
            var v2 = proxy.GetData();
            Thread.Sleep(50);
            var v3 = proxy.GetData();

            Assert.Equal(v1, v2);
            Assert.Equal(v2, v3);

            cache.Verify(c => c.Set(KEY, v1, CacheProxy<DateTime>.EXPIRATION_DEFAULT, SerializationFormat.Null), Times.Once);
            cache.Verify(c => c.Get<DateTime>(KEY, SerializationFormat.Null), Times.Exactly(3));
        }
        public void GetData_CustomExpiration()
        {
            var cache = new Mock<CacheMock>() { CallBase = true };

            var expiration = TimeSpan.FromMinutes(1);
            var proxy = new CacheProxy<DateTime>(() => DateTime.Now, cache: cache.Object, key: KEY, expiration: expiration);

            var v1 = proxy.GetData();
            Thread.Sleep(50);
            var v2 = proxy.GetData();
            Thread.Sleep(50);
            var v3 = proxy.GetData();

            Assert.Equal(v1, v2);
            Assert.Equal(v2, v3);

            cache.Verify(c => c.Set(KEY, v1, expiration, SerializationFormat.Null), Times.Once);
            cache.Verify(c => c.Get<DateTime>(KEY, SerializationFormat.Null), Times.Exactly(3));
        }
        public void GetData_Multithreaded()
        {
            var cache = new Mock<CacheMock>() { CallBase = true };

            var proxy = new CacheProxy<DateTime>(() => DateTime.Now, cache: cache.Object, key: KEY);

            DateTime v1 = default(DateTime);
            DateTime v2 = default(DateTime);
            DateTime v3 = default(DateTime);
            Parallel.Invoke(
                () => { v1 = proxy.GetData(); },
                () => { v2 = proxy.GetData(); },
                () => { v3 = proxy.GetData(); });

            Assert.Equal(v1, v2);
            Assert.Equal(v2, v3);

            cache.Verify(c => c.Set(KEY, v1, CacheProxy<DateTime>.EXPIRATION_DEFAULT, SerializationFormat.Null), Times.Once);
            cache.Verify(c => c.Get<DateTime>(KEY, SerializationFormat.Null), Times.Exactly(3));
        }
Esempio n. 9
0
        private static byte[] HandleMessage(StateObject state) 
        { 
            byte[] bytResponse=null; 
            BinaryFormatter b= new BinaryFormatter(); 
            state.ms.Position =0; 
            CacheProxy proxy = (CacheProxy) b.Deserialize(state.ms); 
            if(proxy.Action ==ActionType.Get) 
            { 
                string key=proxy.Key ; 
                string cacheName=proxy.CacheName ; 
                MemoryMappedCache.Cache c= new MemoryMappedCache.Cache(cacheName); 
                object payload =c[key]; 
                // get the cache item from the key, package into a new Cache proxy, 
                // serialize and send out 
                CacheProxy proxyResult = new CacheProxy(cacheName,ActionType.Result ,key,payload); 
				MemoryStream ms = new MemoryStream(); 
                b.Serialize(ms, proxyResult); 
                bytResponse=ms.ToArray(); 
            } else 
                if(proxy.Action ==ActionType.Add) { 
                    string key=proxy.Key ; 
                    string cacheName=proxy.CacheName ; 
                    MemoryMappedCache.Cache c= new MemoryMappedCache.Cache(cacheName); 
                    c[key]=proxy.Payload ; 
                    byte[] bytTemp=System.Text.Encoding.UTF8.GetBytes("true"); 
                    CacheProxy returnProxy = new CacheProxy(cacheName,ActionType.Result,key,bytTemp); 
                    BinaryFormatter bResp=new BinaryFormatter(); 
                    MemoryStream memResp=new MemoryStream(); 
                    bResp.Serialize(memResp,returnProxy); 
                    bytResponse=memResp.ToArray(); 
                } else 
                    if (proxy.Action ==ActionType.Remove) 
                    { 
                        string key=proxy.Key ; 
                        string cacheName=proxy.CacheName ; 
                        MemoryMappedCache.Cache c= new MemoryMappedCache.Cache(cacheName); 
                        c.Remove(key); 
                        byte[] bytTemp=System.Text.Encoding.UTF8.GetBytes("true"); 
                        CacheProxy returnProxy = new CacheProxy(cacheName,ActionType.Result,key,bytTemp); 
                        BinaryFormatter bResp=new BinaryFormatter(); 
                        MemoryStream memResp=new MemoryStream(); 
                        bResp.Serialize(memResp,returnProxy); 
                        bytResponse=memResp.ToArray(); 
                    } 
            return bytResponse; 
        }