コード例 #1
0
        public void test48_A()
        {
            string key = DateTime.Now.Ticks.ToString();

            _objCache.Write(key, _testData);

            var reply = _objCache.Read <Dictionary <string, dynamic> >(key);

            Assert.AreEqual(_testData, reply);
        }
コード例 #2
0
        public void test50_ReadWrite()
        {
            string key = "storeKey" + DateTime.Now.Ticks;

            _store.Write(key, _testData);

            var data = _store.Read <Dictionary <string, dynamic> >(key);

            Assert.AreEqual(_testData, data);

            var cacheData = _objCache.Read <Dictionary <string, dynamic> >(key);

            Assert.AreEqual(_testData, cacheData);

            bool isExists = System.IO.File.Exists(_store.StoreDirectory + "/" + key + ".json");

            Assert.IsTrue(isExists);
        }
コード例 #3
0
        /// <summary>
        /// Read $data, try cache first
        /// </summary>
        /// <param name="key">Key to search for</param>
        /// <returns> boolean true on success, false</returns>
        public T Read <T>(string key)
        {
            T reply = _cache.Read <T>(key);

            if (reply != null)
            {
                return(reply);
            }

            reply = Fetch <T>(key);
            if (reply != null)
            {
                _cache.Write(key, reply);
                return(reply.Clone());
            }
            else
            {
                return(default(T));
            }
        }
コード例 #4
0
        /// <summary>
        /// Device Detect
        /// </summary>
        /// <param name="data">Data for device detection : HTTP Headers usually</param>
        /// <returns>true on success, false otherwise. Use getReply to inspect results on success.</returns>
        public bool DeviceDetect(Dictionary <string, dynamic> data = null)
        {
            int id = 0;

            if (data == null || !data.Any() || !data.ContainsKey("id"))
            {
                id = Convert.ToInt32(Config["site_id"]);
            }
            else
            {
                id = Convert.ToInt32(data["id"]);
            }

            Dictionary <string, dynamic> requestBody = new Dictionary <string, dynamic>();

            foreach (KeyValuePair <string, dynamic> item in data)
            {
                if (requestBody.ContainsKey(item.Key.ToLower()))
                {
                    requestBody[item.Key.ToLower()] = item.Value;
                }
                else
                {
                    requestBody.Add(item.Key.ToLower(), item.Value);
                }
            }



            string fastKey = "";

            // If caching enabled then check cache
            if (Cacherequests)
            {
                IOrderedEnumerable <dynamic> headersKeys = requestBody.Values.Select(c => c).OrderBy(c => c);
                fastKey = Jss.Serialize(headersKeys).Replace(" ", "");
                Dictionary <string, dynamic> objReply = _cache.Read <Dictionary <string, dynamic> >(fastKey);
                if (objReply != null && objReply.Count > 0)
                {
                    Reply = objReply;
                    SetRawReply();
                    return(SetError(0, "OK"));
                }
            }

            try
            {
                bool result = false;
                if (UseLocal)
                {
                    result = _device.LocalDetect(requestBody);
                    // Log unknown headers if enabled
                    SetError(_device.GetStatus(), _device.GetMessage());
                }
                else
                {
                    result = Remote(string.Format("/device/detect/{0}", id), requestBody);
                }
                if (Cacherequests)
                {
                    _cache.Write(fastKey, GetReply());
                }
                return(result);
            }
            catch (Exception ex)
            {
                SetError(299, "Exception : " + ex.Message + " " + ex.StackTrace);
                return(false);
            }
        }