基于元数据驱动模型架构在ASP.Net的应用研究
<%@ Import Namespace="Microsoft.XXXXX.Advertising.SystemFrameWork" %>
{
SystemVM VM = new SystemVM();
Application.Lock();
Application["VM"] = VM;
Application.UnLock();
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
{
// 在新会话启动时运行的代码
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
</script>
public class SystemVM
{
//角色模板
private SystemService m_system = null;
private OrderService m_order = null;
private QueryService m_query = null;
private FoundationService m_found = null;
///
/// </summary>
public XmlNode XmlDimension
{
get
{
if (HttpContext.Current.Cache["dimension"] == null)
{
LoadXmlDimension();
}
return (XmlNode)HttpContext.Current.Cache["dimension"];
}
}
/// <summary>
/// 查询模板
/// </summary>
public XmlNode XmlQueryList
{
get
{
if (HttpContext.Current.Cache["querylist"] == null)
{
LoadXmlQueryList();
}
return (XmlNode)HttpContext.Current.Cache["querylist"];
}
}
/// JavaScript模板
/// </summary>
public XmlNode XmlJavaScript
{
get
{
if (HttpContext.Current.Cache["javascript"] == null)
{
LoadXmlJavaScript();
}
return (XmlNode)HttpContext.Current.Cache["javascript"];
}
}
/// <summary>
/// 省分模板
/// </summary>
public XmlNode XmlProvince
{
get
{
if (HttpContext.Current.Cache["province"] == null)
{
LoadXmlProvince();
}
return (XmlNode)HttpContext.Current.Cache["province"];
}
}
#region 多角色模板
/// <summary>
/// 系统角色模板
/// </summary>
public XmlNode XmlTemplate
{
get
{
XmlNode xmlNode = null;
if (HttpContext.Current.Request.Cookies["user"] != null)
{
string sWebSiteType = HttpContext.Current.Request.Cookies["user"]["WebSiteType"];
{
xmlNode = XmlCenterTemplate;
}
if (sWebSiteType == "1")
{
xmlNode = XmlProvinceTemplate;
}
if (sWebSiteType == "2")
{
xmlNode = XmlCityTemplate;
}
return xmlNode;
}
}
{
get
{
if (HttpContext.Current.Cache["CenterTemplate"] == null)
{
LoadXmlCenterTemplate();
}
return (XmlNode)HttpContext.Current.Cache["CenterTemplate"];
}
}
public XmlNode XmlProvinceTemplate
{
get
{
if (HttpContext.Current.Cache["ProvinceTemplate"] == null)
{
LoadXmlProvinceTemplate();
}
return (XmlNode)HttpContext.Current.Cache["ProvinceTemplate"];
}
}
public XmlNode XmlCityTemplate
{
get
{
if (HttpContext.Current.Cache["CityTemplate"] == null)
{
LoadXmlCityTemplate();
}
return (XmlNode)HttpContext.Current.Cache["CityTemplate"];
}
}
/// <summary>
/// 加栽角色权限模板
/// </summary>
private void LoadXmlCenterTemplate()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "CenterTemplate.Config";
doc.Load(sPath);
XmlNode xmlNode = doc.DocumentElement;
HttpContext.Current.Cache.Insert("CenterTemplate", doc.DocumentElement,
new CacheDependency(sPath));
}
private void LoadXmlProvinceTemplate()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "ProvinceTemplate.Config";
doc.Load(sPath);
XmlNode xmlNode = doc.DocumentElement;
HttpContext.Current.Cache.Insert("ProvinceTemplate", doc.DocumentElement,
new CacheDependency(sPath));
}
private void LoadXmlCityTemplate()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "CityCenterTemplate.Config";
doc.Load(sPath);
XmlNode xmlNode = doc.DocumentElement;
HttpContext.Current.Cache.Insert("CityTemplate", doc.DocumentElement,
new CacheDependency(sPath));
}
#endregion
/// <summary>
/// 系统服务
/// </summary>
public SystemService SystemService
{
get
{
return m_system;
}
}
/// <summary>
/// 查询服务
/// </summary>
public QueryService QueryService
{
get
{
return m_query;
}
}
/// <summary>
/// 基础信息
/// </summary>
public FoundationService FoundationService
{
get
{
return m_found;
}
}
/// <summary>
/// 订单管理
/// </summary>
public OrderService OrderService
{
get
{
return m_order;
}
}
public SystemVM()
{
LoadBusinessObj();
}
/// <summary>
/// 根据模板类型,返回系统可以选择的模板种类。
/// </summary>
/// <param name="sType"></param>
/// <returns></returns>
public XmlNodeList GetXmlJavaScriptByType(string sType)
{
XmlNodeList xmlNodeList = XmlJavaScript.SelectNodes("//项[@类型='" + sType + "']");
if (xmlNodeList.Count<0)
{
throw new Exception("找不到类型为["+sType+"]的节点!");
}
return xmlNodeList;
}
/// <summary>
/// 根据模板名称,获取JavaScript模板
/// </summary>
/// <param name="sName"></param>
/// <returns></returns>
public string GetXmlJavaScriptTpl(string sName)
{
StringBuilder sJsTemplate = new StringBuilder("");
XmlNode xmlNode = XmlJavaScript.SelectSingleNode("//项[@名称='" + sName + "']");
if (xmlNode == null)
{
throw new Exception("找不到名称为[" + sName + "]的节点!");
}
string sPath = ToolFunc.GetXmlString(xmlNode, "@模版");
sPath = AppDomain.CurrentDomain.BaseDirectory + sPath;
using (TextReader sr = File.OpenText(sPath))
{
String line;
while ((line = sr.ReadLine()) != null)
{
sJsTemplate.AppendLine(line);
}
}
return sJsTemplate.ToString();
}
public string GetUrlFromJavaScript(string sName)
{
string sUrl = "#";
XmlNode xmlNode = XmlJavaScript.SelectSingleNode("//项[@名称='" + sName + "']");
if (xmlNode == null)
{
throw new Exception("找不到名称为[" + sName + "]的节点!");
}
XmlElement el = (XmlElement)xmlNode;
sUrl = el.GetAttribute("Url");
return sUrl;
}
private void LoadXmlProvince()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "Province.Config";
doc.Load(sPath);
XmlNode xmlNode = doc.DocumentElement;
HttpContext.Current.Cache.Insert("province", doc.DocumentElement,
new CacheDependency(sPath));
}
private void LoadXmlJavaScript()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "JavaScript.Config";
doc.Load(sPath);
HttpContext.Current.Cache.Insert("javascript", doc.DocumentElement,
new CacheDependency(sPath));
}
private void LoadXmlDimension()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "Dimension.Config";
doc.Load(sPath);
HttpContext.Current.Cache.Insert("dimension", doc.DocumentElement,
new CacheDependency(sPath));
}
/// <summary>
///
/// </summary>
private void LoadXmlQueryList()
{
string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
XmlDocument doc = new XmlDocument();
string sPath = strBasePath + @"Template\" + "QueryList.config";
doc.Load(sPath);
HttpContext.Current.Cache.Insert("querylist", doc.DocumentElement,
new CacheDependency(sPath));
}
/// 加载业务对象
/// </summary>
private void LoadBusinessObj()
{
m_system = new SystemService(this);
m_order = new OrderService(this);
m_found = new FoundationService(this);
m_query = new QueryService(this);
}
本文转自
高阳 51CTO博客,原文链接:http://blog.51cto.com/xiaoyinnet/196248 ,如需转载请自行联系原作者