public static string GetToken() { var cacheKEY = "TOKEN_" + Config.CORPID + Config.CORPSECRET; var cache = CacheUtility.GetCache <string>(cacheKEY); if (cache == null) { var token = Get.GetJson <GetTokenResult>(string.Format(URL_GETTOKEN, Config.CORPID, Config.CORPSECRET)); if (token != null) { cache = token.access_token; CacheUtility.PutCache(cacheKEY, cache, 7000); } } Console.WriteLine("TOKEN:" + cache); return(cache); }
private void GetWholeNode() { _navlist = CacheUtility.GetCache("Navigator") as IList <Johnny.CMS.OM.SystemInfo.Navigator>; if (_navlist == null) { Johnny.CMS.BLL.SystemInfo.Navigator bll = new Johnny.CMS.BLL.SystemInfo.Navigator(); try { _navlist = bll.GetList(); } catch (Exception ex) { } if (_navlist != null) { //add file to cache CacheUtility.InsertCache("Navigator", _navlist); } } }
public static string GetMessage(string msgId, string param) { if (msgId == null || msgId.Length == 0) { return(""); } string xmlFile = ""; if (GlobalizationCulture == "zh-cn") { xmlFile = "Message_zh-CHS.xml"; } else if (GlobalizationCulture == "en-us") { xmlFile = "Message_en-US.xml"; } else { xmlFile = "Message_en-US.xml"; } XmlDocument xmlDoc = CacheUtility.GetCache(xmlFile) as XmlDocument; if (xmlDoc == null) { xmlDoc = new XmlDocument(); try { Assembly asm = Assembly.GetExecutingAssembly(); XmlTextReader reader = new XmlTextReader(asm.GetManifestResourceStream(asm.GetName().Name + ".Message." + xmlFile)); xmlDoc.Load(reader); } catch (Exception ex) { } if (xmlDoc != null) { //add file to cache CacheUtility.InsertCache(xmlFile, xmlDoc); } else { return(""); } } XmlNode node1 = xmlDoc.SelectSingleNode("//msg[@id='" + msgId + "']"); if (node1 == null) { return(""); } XmlAttributeCollection attr; attr = node1.Attributes; if (attr == null) { return(""); } if (param == string.Empty) { return(attr["text"].Value); } else { return(String.Format(attr["text"].Value, param)); } }
public void GetArticlePictureByPath(string path) { string rootPath = ArticlePictureRootPath; path = Path.Combine(rootPath, Server.UrlDecode(path.Trim('\\'))); if (System.IO.File.Exists(path)) { FileInfo fi = new FileInfo(path); string fileName = Path.GetFileName(path); Response.Clear(); Response.AddHeader("Content-Length", fi.Length.ToString()); Response.ContentType = GetFileContentType(fileName); if (Request.UserAgent.ToLower().IndexOf("msie") > -1) { Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlPathEncode(fileName)); } else if (Request.UserAgent.ToLower().IndexOf("firefox") > -1) { Response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); } else { Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); } //读取缓存 string cacheKey = path.Replace(":", "").Replace("\\", "_"); byte[] fileBytes = CacheUtility.GetCache(cacheKey) as byte[]; int bufferLength = 10240; if (fileBytes == null || fileBytes.Length == 0) { MemoryStream ms = new MemoryStream(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); byte[] buffer = new byte[bufferLength]; int n = fs.Read(buffer, 0, buffer.Length); while (n > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, n); Response.Flush(); Response.Clear(); } ms.Write(buffer, 0, n); n = fs.Read(buffer, 0, buffer.Length); } fs.Close(); //写入缓存 fileBytes = new byte[ms.Length]; ms.Position = 0; ms.Read(fileBytes, 0, (int)ms.Length); ms.Close(); CacheUtility.SetCache(cacheKey, fileBytes, DateTime.Now.AddHours(10), TimeSpan.Zero); } else { int bufferCount = fileBytes.Length / bufferLength + 1; for (int i = 0; i < bufferCount; i++) { if (i == bufferCount - 1) { if (fileBytes.Length > i * bufferLength) { Response.OutputStream.Write(fileBytes, i * bufferLength, fileBytes.Length - i * bufferLength); } } else { if (Response.IsClientConnected) { Response.OutputStream.Write(fileBytes, i * bufferLength, bufferLength); Response.Flush(); Response.Clear(); } else { break; } } } } Response.End(); } }
public static string GetLabelText(string key) { if (String.IsNullOrEmpty(key)) { return(""); } string xmlFile = ""; if (GlobalizationCulture == "zh-cn") { xmlFile = "Label_zh-CHS.xml"; } else if (GlobalizationCulture == "en-us") { xmlFile = "Label_en-US.xml"; } else { xmlFile = "Label_en-US.xml"; } XmlDocument xmlDoc = CacheUtility.GetCache(xmlFile) as XmlDocument; if (xmlDoc == null) { xmlDoc = new XmlDocument(); try { Assembly asm = Assembly.GetExecutingAssembly(); XmlTextReader reader = new XmlTextReader(asm.GetManifestResourceStream(asm.GetName().Name + ".Label." + xmlFile)); xmlDoc.Load(reader); } catch (Exception ex) { } if (xmlDoc != null) { //add file to cache CacheUtility.InsertCache(xmlFile, xmlDoc); } else { return(""); } } XmlNode node1 = xmlDoc.SelectSingleNode("//label[@key='" + key + "']"); if (node1 == null) { return(""); } XmlAttributeCollection attr; attr = node1.Attributes; if (attr == null) { return(""); } return(attr["value"].Value); }