示例#1
0
        /// <summary>
        /// 创建视图对象
        /// </summary>
        /// <param name="path">相对路径,如:/abc/cyq/a.html</param>
        public static XHtmlAction Create(string path)
        {
            string fullPath = AppConfig.WebRootPath + path.TrimStart('/');//.Replace("/", "\\");
            bool   isExists = File.Exists(fullPath);

            if (!isExists)
            {
                fullPath = AppConfig.WebRootPath + path.TrimStart('/').ToLower();
                isExists = File.Exists(fullPath);
            }
            // System.Web.HttpContext.Current.Response.Write(path);
            if (isExists)
            {
                //System.Web.HttpContext.Current.Response.Write("path ok");
                XHtmlAction view = new XHtmlAction(true, false);

                if (view.Load(fullPath, XmlCacheLevel.Hour, true))
                {
                    // System.Web.HttpContext.Current.Response.Write("load ok");
                    //处理Shared目录下的节点替换。
                    ReplaceItemRef(view, view.GetList("*", "itemref"), false, 0);
                }
                //System.Web.HttpContext.Current.Response.Write(view.OutXml);
                return(view);
            }
            return(null);
        }
示例#2
0
        /// <summary>
        /// 获取Shared文件View
        /// </summary>
        /// <param name="htmlName"></param>
        /// <returns></returns>
        private static XHtmlAction GetSharedView(string htmlName)
        {
            string path = AppConfig.WebRootPath + AppConfig.GetApp("Views", "Views") + "\\Shared\\" + htmlName + ".html";

            if (!File.Exists(path))
            {
                return(null);
            }
            XHtmlAction sharedView = null;
            string      key        = path.GetHashCode().ToString();

            if (sharedViews.ContainsKey(key))
            {
                sharedView = sharedViews[key];
                if (sharedView.IsXHtmlChanged)
                {
                    sharedViews.Remove(key);
                    sharedView = null;
                }
                else
                {
                    return(sharedView);
                }
            }
            sharedView = new XHtmlAction(true, true);
            if (sharedView.Load(path, XmlCacheLevel.Day, true))
            {
                sharedViews.Add(key, sharedView);
                return(sharedView);
            }
            return(null);
        }
示例#3
0
        /// <summary>
        /// 获取Shared文件View
        /// </summary>
        /// <param name="htmlName"></param>
        /// <returns></returns>
        private static XHtmlAction GetSharedView(string htmlName, string htmlPath)
        {
            string path = AppConfig.WebRootPath + AppConfig.GetApp("Views", "Views") + "/Shared/" + htmlName + ".html";

            if (!File.Exists(path))
            {
                path = null;
                string[] files = Directory.GetFiles(Path.GetDirectoryName(htmlPath), htmlName + ".html", SearchOption.AllDirectories);
                if (files != null && files.Length > 0)
                {
                    path = files[0];
                }
                else
                {
                    files = Directory.GetFiles(AppConfig.WebRootPath + AppConfig.GetApp("Views", "Views"), htmlName + ".html", SearchOption.AllDirectories);
                    if (files != null && files.Length > 0)
                    {
                        path = files[0];
                    }
                }
                if (path == null)
                {
                    return(null);
                }
            }
            XHtmlAction sharedView = null;
            string      key        = EncryptHelper.GetHashKey(path);

            if (sharedViews.ContainsKey(key))
            {
                sharedView = sharedViews[key];
                if (sharedView.IsXHtmlChanged)
                {
                    sharedViews.Remove(key);
                    sharedView = null;
                }
                else
                {
                    return(sharedView);
                }
            }

            sharedView = new XHtmlAction(true, true);
            if (sharedView.Load(path, XmlCacheLevel.Day, true))
            {
                lock (lockObj)
                {
                    if (!sharedView.Contains(key))
                    {
                        sharedViews.Add(key, sharedView);
                    }
                }
                return(sharedView);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// 创建视图对象
        /// </summary>
        /// <param name="path">相对路径,如:/abc/cyq/a.html</param>
        public static XHtmlAction Create(string path)
        {
            path = AppConfig.WebRootPath + path.TrimStart('/').Replace("/", "\\");
            if (File.Exists(path))
            {
                XHtmlAction view = new XHtmlAction(true, false);

                if (view.Load(path, XmlCacheLevel.Hour, true))
                {
                    //处理Shared目录下的节点替换。
                    ReplaceItemRef(view, view.GetList("*", "itemref"), false, 0);
                }
                return(view);
            }
            return(null);
        }
示例#5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     CreateTable();
     using (XHtmlAction xml = new XHtmlAction(true, false))
     {
         xml.Load(Server.MapPath("/demo.html"));         //加载html模板。
         using (MAction action = new MAction(tableName)) //数据库操作。
         {
             if (action.Fill("1=1"))                     //查询id=1的数据
             {
                 action.Set(1, "hello...");
                 action.Set(2, DateTime.Now);
                 action.Update();
                 xml.LoadData(action.Data, "txt");
             }
             MDataTable dt = action.Select();
             Response.Write("记录总数:" + dt.Rows.Count);
             xml.LoadData(dt);
             xml.SetForeach("divFor", SetType.InnerXml);
         }
         Response.Write(xml.OutXml);//输出模板
     }
 }
示例#6
0
        /// <summary>
        /// 查询网站正文设定标志列表(xml文件)
        /// </summary>
        /// <returns></returns>
        public List <SiteSign> GetSiteSignList()
        {
            var         list = new List <SiteSign>();
            XHtmlAction xml  = new XHtmlAction();

            if (xml.Load(@"SiteSign.xml"))
            {
                var nodeList = xml.GetList("SiteSign");
                foreach (XmlNode item in nodeList)
                {
                    var sign = new SiteSign();
                    foreach (XmlNode node in item.ChildNodes)
                    {
                        string value = node.InnerXml
                                       .Replace("&amp;", "&")
                                       .Replace("&lt;", "<")
                                       .Replace("&gt;", ">")
                                       .Replace("&quot;", "\"")
                                       .Replace("&apos;", "\'");

                        #region 赋值

                        switch (node.Name)
                        {
                        case "name":
                            sign.name = value;
                            break;

                        case "url":
                            sign.url = value;
                            break;

                        case "ListStart":
                            sign.ListStart = value;
                            break;

                        case "ListEnd":
                            sign.ListEnd = value;
                            break;

                        case "ContentStart":
                            sign.ContentStart = value;
                            break;

                        case "ContentEnd":
                            sign.ContentEnd = value;
                            break;

                        case "NeedDelStr":
                            sign.NeedDelStr = value;
                            break;

                        case "VolumeStart":
                            sign.VolumeStart = value;
                            break;

                        case "VolumeEnd":
                            sign.VolumeEnd = value;
                            break;

                        case "BriefUrlStart":
                            sign.BriefUrlStart = value;
                            break;

                        case "BriefUrlEnd":
                            sign.BriefUrlEnd = value;
                            break;

                        case "AuthorStart":
                            sign.AuthorStart = value;
                            break;

                        case "AuthorEnd":
                            sign.AuthorEnd = value;
                            break;

                        case "BriefStart":
                            sign.BriefStart = value;
                            break;

                        case "BriefEnd":
                            sign.BriefEnd = value;
                            break;

                        case "BookImgUrlStart":
                            sign.BookImgUrlStart = value;
                            break;

                        case "BookImgUrlEnd":
                            sign.BookImgUrlEnd = value;
                            break;

                        default:
                            break;
                        }
                        #endregion
                    }
                    list.Add(sign);
                }
            }
            ;
            return(list);
        }