概要:自从上次写了一篇关于YZR.Data和YZR.Data webconfig配置的相关介绍之后,就没有再提及到相关的点了,这里会补上这些天框架的补充优化以及各部分再单独提一下,也简单写一下使用场合.
YZR.Entity类库使用的是枚举的形式,在进行框架编写的时候,没有面向对象那样操作起来简单,但是性能是强于实体的,而且也更容易操作和理解,因为枚举比对象简单得多.
Custom文件夹:考虑到开发往往需要自定义,这里提供一个入口进行自定义实体的定义.
TableNames:面向单数据库的开发,那么TableNames枚举就可以搞定了,但考虑到大项目复杂的数据库设计,这边就需要手动增加相应的枚举类文件.
namespace YZR.UI.AppStart { using YZR.Config; public static class AppStart { /// <summary> /// 应用程序入口 By YZR /// </summary> public static void Init() { string Title = WebSettingManager.WebSetting.BaseSetting.title + " - " + WebSettingManager.WebSetting.BaseSetting.subTitle; int count = WebSettingManager.WebSetting.StrConnSetting.Count; Dictionary<string, string> dic = new Dictionary<string, string>(); for (int i = 0; i < count; i++) { connSection section = WebSettingManager.WebSetting.StrConnSetting[i]; dic.Add(section.Rname, section.Rvalue); } //string strConn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["default"].ConnectionString; //string connString = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ToString(); string ProviderName = System.Configuration.ConfigurationManager.ConnectionStrings["connString"].ProviderName; string path = AppDomain.CurrentDomain.BaseDirectory; Assembly ass = Assembly.LoadFrom(path + "bin\\YZR.Data.dll"); //Assembly ass = Assembly.Load("YZR.Entity"); //TODO:Oracle数据库使用RAtion,Sqlserver使用RMotion Type type = null; string value = dic["Oracle"]; if (value.Equals(ProviderName, StringComparison.OrdinalIgnoreCase)) { type = ass.GetType("YZR.Data." + "RAction"); } else { value = dic["Sqlserver"]; if (value.Equals(ProviderName, StringComparison.OrdinalIgnoreCase)) { type = ass.GetType("YZR.Data." + "RMotion"); } else throw new Exception("配置节点出错"); } //ConstructorInfo c = type.GetConstructor(new Type[] { typeof(string) });//构造函数的实参类型 //c.Invoke(new object[] { "SYS_ADMIN" });//实参 //TODO:在这里需要将所有Entity注册进DbUtilityManager中 if (type != null) { Type tableType = typeof(TableNames); string[] tableNames = tableType.GetEnumNames(); for (int i = 0; i < tableNames.Length; i++) { object fobj = Activator.CreateInstance(type, new object[] { tableNames[i] }); DbUtilityManager.RegistDbUtility(tableNames[i], fobj); } } } } }
R_System:存放开发的处理程序和页面
webconfig:详细请看YZR.Data webconfig文章.
日志操作类:
RSystemError:简单的文本文件的方式记录.(单文件的写入)
LogHelper:使用Log4Net日志组件.相关请查看我的博客:Log4Net日志组件
缓存处理类:
Cache:存放缓存处理类
Enum:枚举缓存Type
ICache:Cache的接口父类
RCache是作为统一的处理类.
namespace YZR.RCache { public class RCache { private static ICache Icache; // cache对象 private static RCache instance = null; //缓存实例 public static RCache GetInstance(CacheType type) { switch (type) { case CacheType.MemCache: //Icache = new MemCachedStrategy(); break; case CacheType.MemCacheAndWebCache: //Icache = new MemCachedAndWebStrategy(); break; case CacheType.WebCache: Icache = new WebCache(); break; case CacheType.XMLCache: //Icache = new XMLCacheStrategy(); break; case CacheType.RedisCache: //Icache = new RedisCacheStrategy(); break; } if (instance != null) return instance; RCache temp = new RCache(); System.Threading.Interlocked.CompareExchange(ref instance, temp, null); return instance; } //构造方法让它私有化,这样外界就不能通过 new 来实例化了 private RCache() { } /// <summary> /// 添加缓存 /// </summary> /// <param name="key"></param> /// <param name="obj"></param> public virtual void AddItem(string key, object obj) { Icache.Add(key, obj); } /// <summary> /// 新增或者更新缓存 推荐使用 /// </summary> /// <param name="key"></param> /// <param name="obj"></param> public virtual void SetItem(string key, object obj) { Icache.Set(key, obj); } /// <summary> /// 添加缓存依赖文件 /// </summary> /// <param name="key"></param> /// <param name="obj"></param> public virtual void AddItemWithFileChange(string key, object obj, string[] files) { Icache.AddItemWithFileChange(key, obj, files); } /// <summary> /// 移除单个缓存 /// </summary> /// <param name="key"></param> public virtual void RemoveItem(string key) { Icache.Remove(key); } /// <summary> /// 移除所有缓存 /// </summary> public virtual void RemoveALLItem() { Icache.RemoveALL(); } /// <summary> /// 获取缓存对象 /// </summary> /// <param name="xpath"></param> /// <returns></returns> public virtual object GetItem(string key) { return Icache.GetItem(key); } } }
缓存代理类:
YZR.Comm,YZR.Utility是常用类,帮助类,比如WebHelper.cs,ScriptHelper.cs,EncrpytHelper.cs等
YZR.Config是webconfig节点的配置类库.
就介绍到这里了!
原文:http://www.cnblogs.com/Francis-YZR/p/4995914.html