/// <summary> /// 设置 web.config 的 AppSettings 中某项的值 /// </summary> /// <param name="key">项的名称</param> /// <param name="value">项的值</param> /// <returns>返回结果</returns> public static Boolean SetAppSettings(String Target, String Value) { try { //指定超级管理员 String XmlPath = PathHelper.Map("~/web.config"); System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument(); xmldoc.Load(XmlPath); System.Xml.XmlNode root = xmldoc.DocumentElement.SelectSingleNode("appSettings"); XmlElement subElement = (XmlElement)root.SelectSingleNode("//add[@key='" + Target + "']"); if (subElement == null) { subElement = xmldoc.CreateElement("add"); subElement.SetAttribute("key", Target); subElement.SetAttribute("value", Value); root.AppendChild(subElement); xmldoc.Save(XmlPath); } else { subElement.SetAttribute("value", Value); xmldoc.Save(XmlPath); } return(true); } catch { return(false); } }
/// <summary> /// 设置是否使用XCoreSessionStateStore来存储会话状态 /// </summary> /// <param name="use"></param> /// <returns></returns> public static Boolean UseXCoreSessionStateStore(Boolean use) { try { //指定超级管理员 String XmlPath = PathHelper.Map("~/web.config"); System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument(); xmldoc.Load(XmlPath); System.Xml.XmlNode root = xmldoc.DocumentElement.SelectSingleNode("//sessionState"); string mode = "InProc"; if (use) { mode = "Custom"; } if (root != null) { root.ParentNode.RemoveChild(root); } root = xmldoc.DocumentElement.SelectSingleNode("//system.web"); XmlElement subElement = xmldoc.CreateElement("sessionState"); subElement.SetAttribute("mode", mode); subElement.SetAttribute("customProvider", "XCoreSessionProvider"); subElement.InnerXml = "<providers><add name=\"XCoreSessionProvider\" type=\"System.XCoreSessionStateStore\" /></providers>"; root.AppendChild(subElement); xmldoc.Save(XmlPath); xmldoc.Save(XmlPath); return(true); } catch { return(false); } }
/// <summary> /// 设置是否使用XCoreSessionStateStore来存储会话状态 /// </summary> /// <param name="use"></param> /// <returns></returns> public static Boolean SetXCoreLoger(Log.LogLevel level = Log.LogLevel.All, Boolean inRealTime = true) { try { String str = "logLevel:" + level.ToString().ToLower() + "\nlogFile:log/log.txt\ninRealTime:" + (inRealTime ? "true" : "false"); file.Write(PathHelper.Map(ConfigRoot + "/log.config"), str); return(true); } catch { return(false); } }
public static String getBySkin(String skinname, String key) { string value = ""; string local = getLangString(); Dictionary <String, String> _core = null; Dictionary <String, String> _lang = null; try { if (_core == null) { try { _core = cfgHelper.Read(PathHelper.Map(cfgHelper.FrameworkRoot + System.TemplateEngine.TeConfig.Instance.TemplateFolder + "/" + skinname + "/lang.config"), '='); } catch { _core = new Dictionary <String, String>(); } } if (_lang == null) { try { _lang = cfgHelper.Read(PathHelper.Map(cfgHelper.FrameworkRoot + System.TemplateEngine.TeConfig.Instance.TemplateFolder + "/" + skinname + "/lang." + local + ".config"), '='); } catch { _core = new Dictionary <String, String>(); } } if (string.IsNullOrEmpty(value)) { try { value = _lang[key]; } catch { } if (string.IsNullOrEmpty(value)) { try { value = _core[key]; } catch { } } } } catch { } return(value); }
public static RegisterInfo GetRegister() { if (!_RegisterInfo.Success) { string filename = PathHelper.Map(cfgHelper.WebRoot + "Wlniao.dll"); if (!file.Exists(filename)) { string content = "Sorry,您的程序需要注册!\t\t"; content += "\n\n机器码:" + GetComputerId() + "\t\t"; content += "\n\n请联系开发商进行注册\t\t"; //content += "\n电话:13075463371\t\t"; //content += "\n网址:http://www.wlniao.com\t\t"; System.IO.StreamWriter sw = new System.IO.StreamWriter(PathHelper.Map(cfgHelper.WebRoot + "Wlniao.dll")); sw.Write(content); sw.Flush(); sw.Close(); } else { string content = ""; try { System.IO.StreamReader sr = new System.IO.StreamReader(filename); //content = sr.ReadToEnd(); //content = ""; for (int i = 0; i < 9; i++) { if (i >= 3 && i < 7) { content += sr.ReadLine(); } else { sr.ReadLine(); } } int length = Convert.ToInt32(content.Substring(0, 4)); content = content.Substring(4, length); string softcode = Data.KvTableUtil.GetString("SoftCode"); if (string.IsNullOrEmpty(softcode)) { softcode = ""; } content = Encryptor.DesDecrypt(content, GetComputerId() + softcode); _RegisterInfo = Json.ToObject <RegisterInfo>(content); } catch { } } } return(_RegisterInfo); }
/// <summary> /// 将 Dictionary 对象持久化到磁盘 /// </summary> /// <param name="dic">一个 Dictionary</param> /// <param name="path">配置文件的路径(相对路径,相对于项目的根目录)</param> /// <param name="separator">键和值之间的分隔符</param> public static void Write(Dictionary <String, String> dic, String path, char separator) { if (strUtil.IsNullOrEmpty(path)) { throw new IOException("config path is empty"); } cfgHelper cfg = new cfgHelper(); cfg.Dic = dic; cfg.setSeparator(separator); file.Write(PathHelper.Map(path), cfg.Content); }
private static Dictionary <String, Dictionary <String, LanguageSetting> > getLangLocale() { System.IO.Directory.CreateDirectory(PathHelper.Map(getLangRootPath())); String dirRoot = PathHelper.Map(getLangRootPath()); String[] dirPaths = Directory.GetDirectories(dirRoot); if (dirPaths.Length == 0) { System.IO.Directory.CreateDirectory(PathHelper.Map(getLangRootPath() + "/zh-cn")); dirPaths = Directory.GetDirectories(dirRoot); } Dictionary <String, Dictionary <String, LanguageSetting> > results = new Dictionary <String, Dictionary <String, LanguageSetting> >(); foreach (String path in dirPaths) { String langName = Path.GetFileName(path); results.Add(langName.ToLower(), getLangList(path)); } return(results); }
public static String getBySkin(String key) { string value = ""; string local = getLangString(); string _skinname = string.Empty; Dictionary <String, String> _core = null; Dictionary <String, String> _lang = null; try { _core = (Dictionary <String, String>)System.Caching.SysCache.Get("TemplateLanguageDic"); } catch { } try { _lang = (Dictionary <String, String>)System.Caching.SysCache.Get("TemplateLanguageDic" + local); } catch { } try { if (_core == null) { try { _core = cfgHelper.Read(PathHelper.Map(cfgHelper.FrameworkRoot + System.TemplateEngine.TeConfig.Instance.TemplateFolder + "/" + System.TemplateEngine.TeConfig.Instance.CurrentSkin + "/lang.config"), '='); System.Caching.SysCache.Put("TemplateLanguageDic", _core); } catch { _core = new Dictionary <String, String>(); System.Caching.SysCache.Put("TemplateLanguageDic", _core); } } if (_lang == null) { try { _lang = cfgHelper.Read(PathHelper.Map(cfgHelper.FrameworkRoot + System.TemplateEngine.TeConfig.Instance.TemplateFolder + "/" + System.TemplateEngine.TeConfig.Instance.CurrentSkin + "/lang." + local + ".config"), '='); System.Caching.SysCache.Put("TemplateLanguageDic" + local, _lang); } catch { _core = new Dictionary <String, String>(); System.Caching.SysCache.Put("TemplateLanguageDic" + local, _core); } } if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) { try { value = _lang[key]; } catch { } if (string.IsNullOrEmpty(value)) { try { value = _core[key]; } catch { } if (string.IsNullOrEmpty(value)) { try { value = getKey(key); } catch { } } } } } } catch {} return(value); }
/// <summary> /// 读取配置文件,返回一个对象。 /// </summary> /// <typeparam name="T">对象的类型</typeparam> /// <param name="fileName">纯文件名称,不包括路径(默认是在 /xcenter/conf/ 目录下)</param> /// <param name="separator">键和值之间的分隔符</param> /// <returns>返回 T 类型的对象</returns> private static T ReadByFile <T>(String fileName, char separator) { String path = PathHelper.Map(strUtil.Join(cfgHelper.ConfigRoot, fileName)); return(Read <T>(path, separator)); }