用asp.net/c#写了自己用的CMS系统,生成各频道静态页面,各个频道页面通过xml配置,解析xml后,在服务器端生成HTML。
,刚搭了个网站宏阳映画艺术设计网,网络地址: www.mzscl.com/index.html
XML配置分为:布局,区域,组,webprat
其中布局配置可以嵌套,布局下面是区域集合,区域下市webpart组集合,组里是webpart集合。
页面配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<cmsPages>
<cmsPage include="home.config"/>
<cmsPage include="list.config"/>
</cmsPages>
<?xml version="1.0" encoding="utf-8" ?>
<cmsPage id="home" autoGenerateID="0">
<profiles>
<profile name="seo">
<seo name="title" value="首页"/>
<seo name="keyword" value="艺术设计"/>
<seo name="description" value="宏阳映画艺术设计网"/>
</profile>
<profile name="css">
<css src="Resources/CSS/Profile.css"/>
</profile>
<profile name="script">
</profile>
</profiles>
<webLayouts>
<webLayout id="layout_banner_1" styleName="layout_lr" orderID="1">
<webPartZone id="webpartzone_banner_1" isShowTitle="0" isShowHeader="0" isShowFooter="0" isShow="1" orderID="1">
<webpartGroup title="网站顶部自动隐藏广告" isShow="1">
<webPart id="webpart_banner_1" styleName="html_skin" dataID="3" columns="1" rows="1" imageLinkEnabled="0" imageLabelEnabled="0" linkMoreEnabled="0" isShow="1" orderID="1">
<dataProvider name="" type="YC330.MINGMING.DataSources.CMSContentDataSource,YC330.MINGMING.DataSources.dll"></dataProvider>
<skinProvider name="" type="YC330.MINGMING.Skins.HTMLSkin,YC330.MINGMING.Skins.dll"></skinProvider>
</webPart>
</webpartGroup>
</webPartZone>
</webLayout>
<webLayout id="layout_page_header" styleName="layout_lr" orderID="2">
<webPartZone id="webpartzone_page_header" isShowTitle="0" isShowHeader="0" isShowFooter="0" isShow="1" orderID="1">
<webpartGroup title="网站头部" isShow="1">
<webPart id="webpart_page_header" styleName="html_skin" dataID="1" columns="1" rows="1" imageLinkEnabled="0" imageLabelEnabled="0" linkMoreEnabled="0" isShow="1" orderID="1">
<dataProvider name="" type="YC330.MINGMING.DataSources.CMSContentDataSource,YC330.MINGMING.DataSources.dll"></dataProvider>
<skinProvider name="" type="YC330.MINGMING.Skins.HTMLSkin,YC330.MINGMING.Skins.dll"></skinProvider>
</webPart>
</webpartGroup>
</webPartZone>
<webPartZone id="webpartzone_page_banner" isShowTitle="0" isShowHeader="0" isShowFooter="0" isShow="1" orderID="2">
<webpartGroup title="首页图文混合广告区" isShow="1">
<webPart id="webpart_page_banner" styleName="html_skin" dataID="4" dataLevel="0" columns="1" rows="1" imageLinkEnabled="0" imageLabelEnabled="0" linkMoreEnabled="0" isShow="1" orderID="1">
<dataProvider name="" type="YC330.MINGMING.DataSources.CMSContentDataSource,YC330.MINGMING.DataSources.dll"></dataProvider>
<skinProvider name="" type="YC330.MINGMING.Skins.HTMLSkin,YC330.MINGMING.Skins.dll"></skinProvider>
</webPart>
</webpartGroup>
</webPartZone>
</webLayout>
</webLayouts>
配置解析:
/// <summary>
/// 文件系统CMSPage解析
/// </summary>
private static void AnalyseCMSConfig()
{
WebPageSettingEntity webPageSetting;
XmlNodeList childNodes = xmlRoot.ChildNodes; //cmsPage集合
for (int i = 0; i < childNodes.Count; i++)
{
if (childNodes[i].NodeType != XmlNodeType.Element) continue;
if (childNodes[i].Attributes["include"] != null)
{
XmlNode includeXMLRoot;
XmlNode profilesNode;
XmlNode layoutsNode;
XmlDocument includeXMLDoc = new XmlDocument();
string includeConfigFilename = WebConfig.CustomConfigRoot + childNodes[i].Attributes["include"].Value;
includeXMLDoc.Load(HttpContext.Current.Server.MapPath(includeConfigFilename));
includeXMLRoot = includeXMLDoc.DocumentElement;
webPageSetting = new WebPageSettingEntity();
webPageSetting.ID = includeXMLRoot.Attributes["id"].Value;
profilesNode = includeXMLRoot.ChildNodes[0];
layoutsNode = includeXMLRoot.ChildNodes[1];
//个性化
WebProfileSettingEntity webProfileSetting = new WebProfileSettingEntity();
//布局集合
List<WebLayoutSettingEntity> webLayoutSettings = new List<WebLayoutSettingEntity>();
//解析WebProfile
Analyse_WebProfile(profilesNode, webProfileSetting);
//解析WebLayout
Analyse_WebLayouts(layoutsNode, webLayoutSettings);
webPageSetting.ProfileSetting = webProfileSetting;
webPageSetting.LayoutSettings = webLayoutSettings;
//新增CMSPage
WebConfig.CMSConfig.CMSPages.Add(webPageSetting);
}
else
{
webPageSetting = new WebPageSettingEntity();
webPageSetting.ID = childNodes[i].Attributes["id"].Value;
//个性化
WebProfileSettingEntity webProfileSetting = new WebProfileSettingEntity();
//布局集合
List<WebLayoutSettingEntity> webLayoutSettings = new List<WebLayoutSettingEntity>();
//解析WebProfile
Analyse_WebProfile(childNodes[i], webProfileSetting);
//解析WebLayout
Analyse_WebLayouts(childNodes[i], webLayoutSettings);
webPageSetting.ProfileSetting = webProfileSetting;
webPageSetting.LayoutSettings = webLayoutSettings;
//新增CMSPage
WebConfig.CMSConfig.CMSPages.Add(webPageSetting);
}
}
}
各频道页面地址如下:
家装彩绘频道 : http://www.mzscl.com/jzch/index.html
质感墙艺频道:http://www.mzscl.com/zgqy/index.html
室内设计频道:http://www.mzscl.com/snsj/index.html
创意设计频道:http://www.mzscl.com/cysj/index.html
汽车彩绘频道:http://www.mzscl.com/qcch/index.html
动画制作频道:http://www.mzscl.com/dhzz/index.html
包装印刷频道:http://www.mzscl.com/ycys/index.html
装饰挂画频道:http://www.mzscl.com/zsgh/index.html
另外还有相册,如下:
家装彩绘相册:http://www.mzscl.com/Gallery/Special.aspx?id=1
质感墙艺术相册:http://www.mzscl.com/Gallery/Special.aspx?id=2
客户留言地址:http://www.mzscl.com/messageboard/index.html
9 个解决方案
#1
广告?炫耀Or资源共享?
#2
不错啊,能GX就更好了,静态页是伪静态URL转发吗?
#3
成熟了会开源分享代码的,现在的代码还很乱,需要重构!
静态页是纯静态,写了自己的页面生成逻辑,页面生成支持NV模板,也可以直接用编译后的模板,就是皮肤!
所有的页面都是xml配置生成的!
using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using YC330.MINGMING;
using YC330.MINGMING.Configurations;
using YC330.MINGMING.Utils;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Address: YICHANG HUBEI CHINA
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.Web.Controls
{
public class MasterPageControl : Control, IMasterPageControl
{
#region //字段
protected string id;
protected string styleName;
protected List<string> title;
protected List<string> keyword;
protected List<string> description;
protected string docType;
protected bool isSettingDocType;
protected List<string> css;
protected List<string> script;
protected RequestPage requestPage;
#endregion
#region //构造方法
public MasterPageControl(RequestPage page)
{
isSettingDocType = true;
this.requestPage = page;
if (!this.requestPage.RequestContext.ContentPlaceHolder && this.requestPage.RequestContext.PagePlaceHolder)
{
((Page)this.requestPage).Controls.Add(this);
}
}
#endregion
#region //重写基类方法
/// <summary>
/// 生成HTML
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
if (!this.requestPage.RequestContext.ContentPlaceHolder)
{
if (this.isSettingDocType)
{
if (!String.IsNullOrEmpty(this.docType))
{
writer.Write(docType);
}
else
{
//writer.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
writer.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
}
}
}
if (!this.requestPage.RequestContext.ContentPlaceHolder)
{
writer.WriteLine();
writer.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
GenericHead(writer);
writer.RenderEndTag();// end head
writer.WriteLine();
writer.RenderBeginTag(HtmlTextWriterTag.Body);
if (!String.IsNullOrEmpty(id))
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, id);
}
if (!String.IsNullOrEmpty(styleName))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, styleName);
}
writer.RenderBeginTag(HtmlTextWriterTag.Div);
base.Render(writer);
writer.RenderEndTag();
writer.RenderEndTag(); // end body
writer.RenderEndTag(); // end html
}
else
{
base.Render(writer);
}
}
protected override void RenderChildren(HtmlTextWriter writer)
{
base.RenderChildren(writer);
}
#endregion
#region //私有方法
/// <summary>
/// 生成HTML Head部分
/// </summary>
/// <param name="writer"></param>
private void GenericHead(HtmlTextWriter writer)
{
GenericHeadHTTP(writer); //生成头部http公共部分
GenericHeadKeyword(writer); //生成头部关键字
GenericHeadDescription(writer); //生成头部描述
GenericHeadTitle(writer); //生成头部标题
GenericHeadCSS(writer); //生成头部样式表
GenericHeadScript(writer); //生成头部脚本调用
}
#endregion
}
}
#4
当把XML配置解析完以后,就可以分析相关配置实体的数据设置,自动生成页面了,如下:
using System;
using System.Collections.Generic;
using YC330.MINGMING.Web.Controls;
using YC330.MINGMING.Configurations;
using YC330.MINGMING.Models.CMS;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Address: YICHANG HUBEI CHINA
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.Builders
{
#region //根据OrderID排序
sealed class WebPartZoneComparer : IComparer<WebpartZoneSettingEntity>
{
}
#endregion
/// <summary>
/// CMS页面基类
/// 分析相关设置,自动生成页面
/// </summary>
public class CMSMasterPageBase : MasterPageBase
{
#region //字段
private ContentPlaceHolderControl contentPlaceHolder;
#endregion
#region //构造方法
public CMSMasterPageBase(RequestPage page)
: base(page)
{
initialize();
}
#endregion
#region //私有方法
private void initialize()
{
initializeMasterPage(); //初始化MasterPage
contentPlaceHolder = new ContentPlaceHolderControl(); //控件容器,继承自LayoutControl控件,拥有对base.MasterControl的访问权
contentPlaceHolder.MasterPage = this;
for (int i = 0; i < WebConfig.CMSConfig.CMSPages.Count; i++) //遍历CMS页
{
if (WebConfig.CMSConfig.CMSPages[i].ID.ToLower() == requestPage.RequestContext.CMSContext.PageID.ToLower())
{
WebPageSettingEntity webPageSetting = WebConfig.CMSConfig.CMSPages[i]; //获取当前CMS页数据
analysePrlfile(webPageSetting.ProfileSetting); //解析当前CMS页个性化数据数据
analyseLayouts(webPageSetting.LayoutSettings, contentPlaceHolder); //解析当前CMS页布局数据
this.Controls.Add(contentPlaceHolder);
break;
}
}
}
/// <summary>
/// 初始化MasterPage
/// </summary>
protected virtual void initializeMasterPage()
{}
/// <summary>
/// 解析个性化数据
/// </summary>
/// <param name="webProfileSetting"></param>
private void analysePrlfile(WebProfileSettingEntity webProfileSetting)
{
this.Title = webProfileSetting.Title;
this.Keyword = webProfileSetting.Keyword;
this.Description = webProfileSetting.Description;
for(int i=0;i<webProfileSetting.CSS.Count;i++){
this.CSS.Add(WebConfig.Site.Root + webProfileSetting.CSS[i]);
}
for (int j = 0; j < webProfileSetting.Script.Count; j++)
{
this.Script.Add(WebConfig.Site.Root + webProfileSetting.Script[j]);
}
}
/// <summary>
/// 解析布局
/// </summary>
/// <param name="webLayoutSettings"></param>
/// <param name="layoutParentControl"></param>
private void analyseLayouts(List<WebLayoutSettingEntity> webLayoutSettings, LayoutControl parentLayout)
{
if (webLayoutSettings != null && webLayoutSettings.Count > 0)
{
for (int j = 0; j < webLayoutSettings.Count; j++)
{
LayoutControl childLayout = new LayoutControl(); //初始化布局控件
analyseWebPartZones(webLayoutSettings[j], childLayout); //解析当前布局下的WebPartZone数据
parentLayout.Controls.Add(childLayout); //把布局添加到容器里
analyseLayouts(webLayoutSettings[j].LayoutSettings, childLayout); //递归布局解析
}
}
}
/// <summary>
/// WebPartZone区域解析
/// </summary>
/// <param name="layoutEntity"></param>
/// <param name="layout"></param>
private void analyseWebPartZones(WebLayoutSettingEntity webLayoutSetting, LayoutControl layout)
{
layout.MasterPage = this;
layout.Setting.ID = webLayoutSetting.ID;
layout.Setting.StyleName = webLayoutSetting.StyleName;
//自定义排序,OrderID升序排列,即1,2,3.......10
WebPartZoneComparer webPartZoneComparer = new WebPartZoneComparer();
WebpartGroupComparer webpartGroupComparer = new WebpartGroupComparer();
WebpartComparer webpartComparer = new WebpartComparer();
webLayoutSetting.ZoneSettings.Sort(webPartZoneComparer); //WebPartZone OrderID 排序
for (int m = 0; m < webLayoutSetting.ZoneSettings.Count; m++)
{
WebpartZone webPartZone = new CMSPartZone(); //实例化区域
webLayoutSetting.ZoneSettings[m].GroupSettings.Sort(webpartGroupComparer); //WebPartGroup OrderID 排序
for (int n = 0; n < webLayoutSetting.ZoneSettings[m].GroupSettings.Count; n++)
{
WebpartGroup webpartGroup = new WebpartGroup(); //实例化WebPartGroup
webpartGroup.GroupSetting = webLayoutSetting.ZoneSettings[m].GroupSettings[n];
webpartGroup.Zone = webPartZone;
webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings.Sort(webpartComparer); //WebPart OrderID 排序
for (int k = 0; k < webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings.Count; k++)
{
Webpart webpart = new Webpart(); //实例化WebPart
webpart.Setting = webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings[k];
webpart.Group = webpartGroup;
WebpartEventArgs e = new WebpartEventArgs();
e.Setting = webpart.Setting;
RequestPage.RaiseWebpart(e);//触发事件钩子
webpartGroup.Webparts.Add(webpart); //加入WebPart到当前WebPartGroup
}
webPartZone.Groups.Add(webpartGroup); //加入WebPartGroup到当前WebPartZone
}
if (String.IsNullOrEmpty(webLayoutSetting.ZoneSettings[m].ID))
{
webLayoutSetting.ZoneSettings[m].ID = layout.ID + "_webpartzone_" + m.ToString().PadLeft(2, '0');
}
webPartZone.ZoneSetting = webLayoutSetting.ZoneSettings[m];
webPartZone.Layout = layout;
webPartZone.Initialize();
}
}
#endregion
}
}
#5
webpart会访问生成器,由生成器来生成具体的页面,生成器里可以用NV模板引擎来生成html,或直接生成html.
下面就是一步一步生成
using System;
using System.Collections.Generic;
using System.Text;
using YC330.MINGMING;
using YC330.MINGMING.Web.Controls;
using YC330.MINGMING.Configurations;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Web: http://www.YC330.MINGMING.net
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.BuilderProviders
{
public abstract class RequestBuilder : IRequestBuilder
{
#region //字段
protected IRequestContext requestContext;
protected Webpart owner;
protected StringBuilder sbHTML;
protected PageControl pageControl;
#endregion
#region //属性
public Webpart Owner
{
get { return owner; }
set { owner = value; }
}
#endregion
#region //构造方法
public RequestBuilder(IRequestContext requestContext)
{
this.requestContext = requestContext;
sbHTML = new StringBuilder();
pageControl = new PageControl();
}
#endregion
#region //方法
public PageControl GetControl()
{
BuilderHeader();
BuilderContent();
BuilderFooter();
pageControl.Text = sbHTML.ToString();
return pageControl;
}
protected virtual void BuilderHeader(){}
protected abstract void BuilderContent();
protected virtual void BuilderFooter()
{
sbHTML.AppendFormat("<div id=\"requestFooter\"><img src=\"{0}Resources/Image/btnPost.jpg\" id=\"btnPost\"></div><div id=\"requestMessage\"></div>",WebConfig.Site.Root);
}
#endregion
}
}
#6
看了....
#7
12
#8
看了又看
#9
佩服,收藏了
#1
广告?炫耀Or资源共享?
#2
不错啊,能GX就更好了,静态页是伪静态URL转发吗?
#3
成熟了会开源分享代码的,现在的代码还很乱,需要重构!
静态页是纯静态,写了自己的页面生成逻辑,页面生成支持NV模板,也可以直接用编译后的模板,就是皮肤!
所有的页面都是xml配置生成的!
using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using YC330.MINGMING;
using YC330.MINGMING.Configurations;
using YC330.MINGMING.Utils;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Address: YICHANG HUBEI CHINA
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.Web.Controls
{
public class MasterPageControl : Control, IMasterPageControl
{
#region //字段
protected string id;
protected string styleName;
protected List<string> title;
protected List<string> keyword;
protected List<string> description;
protected string docType;
protected bool isSettingDocType;
protected List<string> css;
protected List<string> script;
protected RequestPage requestPage;
#endregion
#region //构造方法
public MasterPageControl(RequestPage page)
{
isSettingDocType = true;
this.requestPage = page;
if (!this.requestPage.RequestContext.ContentPlaceHolder && this.requestPage.RequestContext.PagePlaceHolder)
{
((Page)this.requestPage).Controls.Add(this);
}
}
#endregion
#region //重写基类方法
/// <summary>
/// 生成HTML
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
if (!this.requestPage.RequestContext.ContentPlaceHolder)
{
if (this.isSettingDocType)
{
if (!String.IsNullOrEmpty(this.docType))
{
writer.Write(docType);
}
else
{
//writer.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
writer.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
}
}
}
if (!this.requestPage.RequestContext.ContentPlaceHolder)
{
writer.WriteLine();
writer.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
writer.RenderBeginTag(HtmlTextWriterTag.Html);
writer.RenderBeginTag(HtmlTextWriterTag.Head);
GenericHead(writer);
writer.RenderEndTag();// end head
writer.WriteLine();
writer.RenderBeginTag(HtmlTextWriterTag.Body);
if (!String.IsNullOrEmpty(id))
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, id);
}
if (!String.IsNullOrEmpty(styleName))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, styleName);
}
writer.RenderBeginTag(HtmlTextWriterTag.Div);
base.Render(writer);
writer.RenderEndTag();
writer.RenderEndTag(); // end body
writer.RenderEndTag(); // end html
}
else
{
base.Render(writer);
}
}
protected override void RenderChildren(HtmlTextWriter writer)
{
base.RenderChildren(writer);
}
#endregion
#region //私有方法
/// <summary>
/// 生成HTML Head部分
/// </summary>
/// <param name="writer"></param>
private void GenericHead(HtmlTextWriter writer)
{
GenericHeadHTTP(writer); //生成头部http公共部分
GenericHeadKeyword(writer); //生成头部关键字
GenericHeadDescription(writer); //生成头部描述
GenericHeadTitle(writer); //生成头部标题
GenericHeadCSS(writer); //生成头部样式表
GenericHeadScript(writer); //生成头部脚本调用
}
#endregion
}
}
#4
当把XML配置解析完以后,就可以分析相关配置实体的数据设置,自动生成页面了,如下:
using System;
using System.Collections.Generic;
using YC330.MINGMING.Web.Controls;
using YC330.MINGMING.Configurations;
using YC330.MINGMING.Models.CMS;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Address: YICHANG HUBEI CHINA
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.Builders
{
#region //根据OrderID排序
sealed class WebPartZoneComparer : IComparer<WebpartZoneSettingEntity>
{
}
#endregion
/// <summary>
/// CMS页面基类
/// 分析相关设置,自动生成页面
/// </summary>
public class CMSMasterPageBase : MasterPageBase
{
#region //字段
private ContentPlaceHolderControl contentPlaceHolder;
#endregion
#region //构造方法
public CMSMasterPageBase(RequestPage page)
: base(page)
{
initialize();
}
#endregion
#region //私有方法
private void initialize()
{
initializeMasterPage(); //初始化MasterPage
contentPlaceHolder = new ContentPlaceHolderControl(); //控件容器,继承自LayoutControl控件,拥有对base.MasterControl的访问权
contentPlaceHolder.MasterPage = this;
for (int i = 0; i < WebConfig.CMSConfig.CMSPages.Count; i++) //遍历CMS页
{
if (WebConfig.CMSConfig.CMSPages[i].ID.ToLower() == requestPage.RequestContext.CMSContext.PageID.ToLower())
{
WebPageSettingEntity webPageSetting = WebConfig.CMSConfig.CMSPages[i]; //获取当前CMS页数据
analysePrlfile(webPageSetting.ProfileSetting); //解析当前CMS页个性化数据数据
analyseLayouts(webPageSetting.LayoutSettings, contentPlaceHolder); //解析当前CMS页布局数据
this.Controls.Add(contentPlaceHolder);
break;
}
}
}
/// <summary>
/// 初始化MasterPage
/// </summary>
protected virtual void initializeMasterPage()
{}
/// <summary>
/// 解析个性化数据
/// </summary>
/// <param name="webProfileSetting"></param>
private void analysePrlfile(WebProfileSettingEntity webProfileSetting)
{
this.Title = webProfileSetting.Title;
this.Keyword = webProfileSetting.Keyword;
this.Description = webProfileSetting.Description;
for(int i=0;i<webProfileSetting.CSS.Count;i++){
this.CSS.Add(WebConfig.Site.Root + webProfileSetting.CSS[i]);
}
for (int j = 0; j < webProfileSetting.Script.Count; j++)
{
this.Script.Add(WebConfig.Site.Root + webProfileSetting.Script[j]);
}
}
/// <summary>
/// 解析布局
/// </summary>
/// <param name="webLayoutSettings"></param>
/// <param name="layoutParentControl"></param>
private void analyseLayouts(List<WebLayoutSettingEntity> webLayoutSettings, LayoutControl parentLayout)
{
if (webLayoutSettings != null && webLayoutSettings.Count > 0)
{
for (int j = 0; j < webLayoutSettings.Count; j++)
{
LayoutControl childLayout = new LayoutControl(); //初始化布局控件
analyseWebPartZones(webLayoutSettings[j], childLayout); //解析当前布局下的WebPartZone数据
parentLayout.Controls.Add(childLayout); //把布局添加到容器里
analyseLayouts(webLayoutSettings[j].LayoutSettings, childLayout); //递归布局解析
}
}
}
/// <summary>
/// WebPartZone区域解析
/// </summary>
/// <param name="layoutEntity"></param>
/// <param name="layout"></param>
private void analyseWebPartZones(WebLayoutSettingEntity webLayoutSetting, LayoutControl layout)
{
layout.MasterPage = this;
layout.Setting.ID = webLayoutSetting.ID;
layout.Setting.StyleName = webLayoutSetting.StyleName;
//自定义排序,OrderID升序排列,即1,2,3.......10
WebPartZoneComparer webPartZoneComparer = new WebPartZoneComparer();
WebpartGroupComparer webpartGroupComparer = new WebpartGroupComparer();
WebpartComparer webpartComparer = new WebpartComparer();
webLayoutSetting.ZoneSettings.Sort(webPartZoneComparer); //WebPartZone OrderID 排序
for (int m = 0; m < webLayoutSetting.ZoneSettings.Count; m++)
{
WebpartZone webPartZone = new CMSPartZone(); //实例化区域
webLayoutSetting.ZoneSettings[m].GroupSettings.Sort(webpartGroupComparer); //WebPartGroup OrderID 排序
for (int n = 0; n < webLayoutSetting.ZoneSettings[m].GroupSettings.Count; n++)
{
WebpartGroup webpartGroup = new WebpartGroup(); //实例化WebPartGroup
webpartGroup.GroupSetting = webLayoutSetting.ZoneSettings[m].GroupSettings[n];
webpartGroup.Zone = webPartZone;
webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings.Sort(webpartComparer); //WebPart OrderID 排序
for (int k = 0; k < webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings.Count; k++)
{
Webpart webpart = new Webpart(); //实例化WebPart
webpart.Setting = webLayoutSetting.ZoneSettings[m].GroupSettings[n].WebpartSettings[k];
webpart.Group = webpartGroup;
WebpartEventArgs e = new WebpartEventArgs();
e.Setting = webpart.Setting;
RequestPage.RaiseWebpart(e);//触发事件钩子
webpartGroup.Webparts.Add(webpart); //加入WebPart到当前WebPartGroup
}
webPartZone.Groups.Add(webpartGroup); //加入WebPartGroup到当前WebPartZone
}
if (String.IsNullOrEmpty(webLayoutSetting.ZoneSettings[m].ID))
{
webLayoutSetting.ZoneSettings[m].ID = layout.ID + "_webpartzone_" + m.ToString().PadLeft(2, '0');
}
webPartZone.ZoneSetting = webLayoutSetting.ZoneSettings[m];
webPartZone.Layout = layout;
webPartZone.Initialize();
}
}
#endregion
}
}
#5
webpart会访问生成器,由生成器来生成具体的页面,生成器里可以用NV模板引擎来生成html,或直接生成html.
下面就是一步一步生成
using System;
using System.Collections.Generic;
using System.Text;
using YC330.MINGMING;
using YC330.MINGMING.Web.Controls;
using YC330.MINGMING.Configurations;
/*
* **********************************************************************
* -- MINGMING MUSIC v1.0.0.0 - mymingming by coding
* -- Author: mymingming
* -- QQ: 154674958
* -- Msn: chongchong2008@msn.com
* -- Web: http://www.YC330.MINGMING.net
* -- Date: 2008-07-20
* -- LastDate: 2008-08-27
* -- Note:
* -- Copyright(C) 2008 mymingming 7# YanJiang Road YiChang HuBei CHINA
* **********************************************************************
*/
namespace YC330.MINGMING.BuilderProviders
{
public abstract class RequestBuilder : IRequestBuilder
{
#region //字段
protected IRequestContext requestContext;
protected Webpart owner;
protected StringBuilder sbHTML;
protected PageControl pageControl;
#endregion
#region //属性
public Webpart Owner
{
get { return owner; }
set { owner = value; }
}
#endregion
#region //构造方法
public RequestBuilder(IRequestContext requestContext)
{
this.requestContext = requestContext;
sbHTML = new StringBuilder();
pageControl = new PageControl();
}
#endregion
#region //方法
public PageControl GetControl()
{
BuilderHeader();
BuilderContent();
BuilderFooter();
pageControl.Text = sbHTML.ToString();
return pageControl;
}
protected virtual void BuilderHeader(){}
protected abstract void BuilderContent();
protected virtual void BuilderFooter()
{
sbHTML.AppendFormat("<div id=\"requestFooter\"><img src=\"{0}Resources/Image/btnPost.jpg\" id=\"btnPost\"></div><div id=\"requestMessage\"></div>",WebConfig.Site.Root);
}
#endregion
}
}
#6
看了....
#7
12
#8
看了又看
#9
佩服,收藏了