当前位置: 首页 > news >正文

steamcn网站是谁做的wordpress win8主题

steamcn网站是谁做的,wordpress win8主题,做谷歌网站使用什么统计代码吗,wordpress福利源码最近在学习.Net Core的过程中#xff0c;发现.Net Framework中常用的ConfigurationManager在Core中竟然被干掉了。 也能理解。Core中使用的配置文件全是Json#xff0c;不像Framework使用的XML#xff0c;暂时不支持也是能理解的#xff0c;但是毕竟全局配置文件这种东西还…最近在学习.Net Core的过程中发现.Net Framework中常用的ConfigurationManager在Core中竟然被干掉了。 也能理解。Core中使用的配置文件全是Json不像Framework使用的XML暂时不支持也是能理解的但是毕竟全局配置文件这种东西还挺重要的阅读了一些文章后目前有3个解决方案。 一、引入扩展System.Configuration.ConfigurationManager 这个扩展库可以直接在Nuget中获取。 使用方法和说明见 .NET Core 2.0迁移技巧之web.config配置文件 读取的文件类型和方法都跟.Net Framework中一致而且仅需引入包就可以瞬间很兴奋有木有 但是在使用过过程中发现这个扩展有问题。项目运行过程中需修改我的app.config文件对我项目中输出的内容没有丝毫影响Debug发现获取到的值的确没有变化。重启项目都没有用。只有把项目重新编译才好使。 不知道是不是因为我的打开方式不对但是最终放弃这个方法。 二、引入扩展Microsoft.Extensions.Options.ConfigurationExtensions 这个扩展库也可以直接在Nuget中获取。 使用方法和说明见 ASP.NET Core实现类库项目读取配置文件 这个可以读取application.json中的配置参数不再使用XML可以说很好的贴近Core的设计理念。 可惜这个也有点美中不足的地方。首先跟上面的那个一样运行时修改json文件读取到的内容不会改变但是至少重启项目可以修改这个让我欣慰很多。另外就是这个方法采用的是反序列化的原理也就是必须有一个跟配置文件对应的实体类才可以这个感觉比较鸡肋放弃。 三、自定义扩展方法 这个是我这次说的重点要是前面两个方法能满足读者你的需求那么就没有必要看下去。 废话少说先上代码 public class ConfigurationManager { /// summary /// 配置内容 /// /summary private static NameValueCollection _configurationCollection new NameValueCollection(); /// summary /// 配置监听响应链堆栈 /// /summary private static StackKeyValuePairstring, FileSystemWatcher FileListeners new StackKeyValuePairstring, FileSystemWatcher(); /// summary /// 默认路径 /// /summary private static string _defaultPath Directory.GetCurrentDirectory() \\appsettings.json; /// summary /// 最终配置文件路径 /// /summary private static string _configPath null; /// summary /// 配置节点关键字 /// /summary private static string _configSection AppSettings; /// summary /// 配置外连接的后缀 /// /summary private static string _configUrlPostfix Url; /// summary /// 最终修改时间戳 /// /summary private static long _timeStamp 0L; /// summary /// 配置外链关键词例如AppSettings.Url /// /summary private static string _configUrlSection { get { return _configSection . _configUrlPostfix; } } static ConfigurationManager() { ConfigFinder(_defaultPath); } /// summary /// 确定配置文件路径 /// /summary private static void ConfigFinder(string Path) { _configPath Path; JObject config_json new JObject(); while (config_json ! null) { config_json null; FileInfo config_info new FileInfo(_configPath); if (!config_info.Exists) break; FileListeners.Push(CreateListener(config_info)); config_json LoadJsonFile(_configPath); if (config_json[_configUrlSection] ! null) _configPath config_json[_configUrlSection].ToString(); else break; } if (config_json null || config_json[_configSection] null) return; LoadConfiguration(); } /// summary /// 读取配置文件内容 /// /summary private static void LoadConfiguration() { FileInfo config new FileInfo(_configPath); var configColltion new NameValueCollection(); JObject config_object LoadJsonFile(_configPath); if (config_object null || !(config_object is JObject)) return; if (config_object[_configSection]!null) { foreach (JProperty prop in config_object[_configSection]) { configColltion[prop.Name] prop.Value.ToString(); } } _configurationCollection configColltion; } /// summary /// 解析Json文件 /// /summary /// param nameFilePath文件路径/param /// returns/returns private static JObject LoadJsonFile(string FilePath) { JObject config_object null; try { StreamReader sr new StreamReader(FilePath, Encoding.Default); config_object JObject.Parse(sr.ReadToEnd()); sr.Close(); } catch { } return config_object; } /// summary /// 添加监听树节点 /// /summary /// param nameinfo/param /// returns/returns private static KeyValuePairstring, FileSystemWatcher CreateListener(FileInfo info) { FileSystemWatcher watcher new FileSystemWatcher(); watcher.BeginInit(); watcher.Path info.DirectoryName; watcher.Filter info.Name; watcher.IncludeSubdirectories false; watcher.EnableRaisingEvents true; watcher.NotifyFilter NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size; watcher.Changed new FileSystemEventHandler(ConfigChangeListener); watcher.EndInit(); return new KeyValuePairstring, FileSystemWatcher(info.FullName, watcher); } private static void ConfigChangeListener(object sender, FileSystemEventArgs e) { long time TimeStamp(); lock (FileListeners) { if (time _timeStamp) { _timeStamp time; if (e.FullPath ! _configPath || e.FullPath _defaultPath) { while (FileListeners.Count 0) { var listener FileListeners.Pop(); listener.Value.Dispose(); if (listener.Key e.FullPath) break; } ConfigFinder(e.FullPath); } else { LoadConfiguration(); } } } } private static long TimeStamp() { return (long)((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds * 100); } private static string c_configSection null; public static string ConfigSection { get { return _configSection; } set { c_configSection value; } } private static string c_configUrlPostfix null; public static string ConfigUrlPostfix { get { return _configUrlPostfix; } set { c_configUrlPostfix value; } } private static string c_defaultPath null; public static string DefaultPath { get { return _defaultPath; } set { c_defaultPath value; } } public static NameValueCollection AppSettings { get { return _configurationCollection; } } /// summary /// 手动刷新配置修改配置后请手动调用此方法以便更新配置参数 /// /summary public static void RefreshConfiguration() { lock (FileListeners) { //修改配置 if (c_configSection ! null) { _configSection c_configSection; c_configSection null; } if (c_configUrlPostfix ! null) { _configUrlPostfix c_configUrlPostfix; c_configUrlPostfix null; } if (c_defaultPath ! null) { _defaultPath c_defaultPath; c_defaultPath null; } //释放掉全部监听响应链 while (FileListeners.Count 0) FileListeners.Pop().Value.Dispose(); ConfigFinder(_defaultPath); } } } 最开始设计的是采用缓存每次调用比对文件的修改时间大小等特征出现变化从新载入配置。后来发现图样图森破 C#提供了专门监听文件系统的方法。所以从新设计了监听响应链堆栈来实现。 使用说明 1、配置节点 可以直接写在项目默认的配置文件appsettings.json中 格式如下 { AppSettings: { Title: Test, Version: 1.2.1, AccessToken: 123456abc.com } } 保证配置节点AppSettings存在剩下的就是以Key-Value的形式来写属性就可以。 2、外部配置文件 像.Net Framework中一样可以通过外部配置文件来实现。格式如下 { AppSettings.Url: D:\\test\\app1.json } 采用格式是“配置节点名.外链后缀”的形式。可以设计多级外部配置文件只要发现有外部配置节点就会向下寻找并监听链上的所有节点文件的变化。 但是需要注意的是一旦存在外部配置节点此文件中的配置节点和参数将不再参与解析 3、可配置初始化参数 包括默认文件路径在内的多个参数均可以修改详情见代码。 修改后需要手动调用RefreshConfiguration方法以使配置内容生效有点像事务处理。建议在项目的Startup方法中修改配置方法。 4、使用 跟.Net Framework中一样直接调用ConfigurationManager.Appsettings[Title]就可以了。 原文地址http://www.cnblogs.com/kasimlz/p/7515810.html .NET社区新闻深度好文微信中搜索dotNET跨平台或扫描二维码关注
http://www.zqtcl.cn/news/362735/

相关文章:

  • 杭州做网站的科技公司永川做网站的公司
  • 动物自己做的网站网站优化外包公司
  • 企业网站建设的三种方式并举例手机wap网站是什么
  • 做深圳门户网站起什么名字好建设网站对公司起什么作用是什么
  • 长春企业网站设计建设公司资质查询官网
  • 医疗网站前置审批查询免费网站建设可信赖
  • 摄影师个人网站模板宝坻集团网站建设
  • 比较多人用什么网站做推广wordpress数据库表管理系统
  • 网页开发和游戏开发东莞优化怎么做seo
  • 北京网站搭建开发高级网页设计教程
  • 北京南站是中高风险地区吗网站建设上机实验心得
  • 大学生做兼职的网站有哪些免费行情软件网站有哪些
  • 静安手机网站建设常见的网络营销方法及其效果
  • 怎么改版网站湖南长沙地图
  • 中卫网站推广公司如何自创app软件
  • 无棣网站建设电子商务网站设计原理书籍
  • 做t-shirt素材网站企业网站建设结论
  • 唐山公司做网站查询建筑资质的网站
  • 邯郸的网站建设网站正能量入口
  • 网站导航栏最多可以做几个宝安网站设计排名
  • 自己怎样用手机建网站网件app
  • 周口网站开发西安市建设厅网站
  • 怎么授权小说做游戏网站论坛网站开发语言
  • 烟台商城网站建设怎么样引流顾客到店方法
  • 北京做网站公司的排名python基础教程pdf
  • 网站建设为什么学flash建设工程询价网站有哪些
  • 网站内容建设机制企业管理模式有哪些
  • 中山网站建设文化价格建网站域名注册
  • 手机电影网站怎么做大连最新发布
  • 珠三角网站建设网页制作专业知识