Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);//输出模板
     }
 }
Esempio n. 6
0
 public static void Bind(object ct, object source, string nodeID)
 {
     if (ct == null)
     {
         return;
     }
     if (ct is XHtmlAction)
     {
         #region XHtmlAction 对象处理
         XHtmlAction doc = ct as XHtmlAction;
         MDataTable  dt  = source as MDataTable;
         doc.LoadData(dt);
         XmlNode node = null;
         if (string.IsNullOrEmpty(nodeID))
         {
             doc.SetForeach();
         }
         else
         {
             node = doc.Get(nodeID);
             if (node != null)
             {
                 doc.SetForeach(node, node.InnerXml);
             }
         }
         #endregion
     }
     else
     {
         #region 检测下拉列表控件
         if (ct is ListControl)
         {
             BindList(ct as ListControl, source as MDataTable);
         }
         else if (ct is Win.ListControl)
         {
             BindList(ct as Win.ListControl, source as MDataTable);
         }
         else
         {
             Type         t = ct.GetType();
             PropertyInfo p = t.GetProperty("DataSource");
             if (p != null)
             {
                 #region DataGridView处理
                 MethodInfo meth = t.GetMethod("DataBind");
                 if (meth != null)//web
                 {
                     p.SetValue(ct, source, null);
                     meth.Invoke(ct, null);
                 }
                 else
                 {
                     if (source is MDataTable)
                     {
                         MDataTable dt = source as MDataTable;
                         source = new MDataView(ref dt);
                     }
                     p.SetValue(ct, source, null);//winform
                 }
                 #endregion
             }
             else //wpf,sliverlight
             {
                 p = t.GetProperty("ItemsSource");
                 if (p != null)
                 {
                     MDataTable dt = null;
                     if (source is MDataTable)
                     {
                         dt     = source as MDataTable;
                         source = dt.ToDataTable().DefaultView;
                     }
                     p.SetValue(ct, source, null);           //winform
                     p = t.GetProperty("SelectedValuePath"); //判断是不是下拉列表
                     if (p != null)
                     {
                         p.SetValue(ct, dt.Columns[0].ColumnName, null);
                         p = t.GetProperty("DisplayMemberPath");
                         p.SetValue(ct, dt.Columns[dt.Columns.Count > 1 ? 1 : 0].ColumnName, null);
                     }
                 }
             }
         }
         #endregion
     }
 }
Esempio n. 7
0
        private static void ReplaceItemRef(XHtmlAction view, XmlNodeList list, bool isBreak, int loopCount)
        {
            //处理Shared目录下的节点替换。
            if (list != null && list.Count > 0)
            {
                if (loopCount > 50)
                {
                    throw new Exception("Reference loop : " + list[0].InnerXml);
                }
                string itemref = "itemref";
                for (int i = 0; i < list.Count; i++)
                {
                    string itemValue = list[i].Attributes[itemref].Value;
                    if (!string.IsNullOrEmpty(itemValue))
                    {
                        bool     isOK  = false;
                        string[] items = itemValue.Split('.');
                        if (items.Length == 1)// 只一个节点,从当前节点寻找。
                        {
                            XmlNode xNode = view.Get(items[0]);
                            if (xNode != null)
                            {
                                view.ReplaceNode(xNode, list[i]);
                                view.Remove(xNode);//从自己拿节点的,需要移除
                                isOK = true;
                            }
                        }
                        else
                        {
                            XHtmlAction sharedView = GetSharedView(items[0], view.FileName);//找到masterView
                            if (sharedView != null)
                            {
                                XmlNode xNode = sharedView.Get(items[1]);//找到被替换的节点


                                if (xNode != null)
                                {
                                    view.InsertAfter(xNode, list[i]);                                            //先插入节点。
                                    XmlNodeList childNodeList = view.GetList("*", itemref, list[i].NextSibling); //检测内部是否有引用指向外部。
                                    if (childNodeList != null && childNodeList.Count > 0)
                                    {
                                        loopCount++;
                                        ReplaceItemRef(view, childNodeList, true, loopCount); //下次跳出,避免死循环。
                                    }
                                    view.Remove(list[i]);                                     //移除节点
                                    isOK = true;
                                }
                            }
                        }
                        if (!isOK)
                        {
                            view.Remove(list[i]);//移除没有引用的节点
                            // view.RemoveAttr(list[i], itemref);
                        }
                    }
                }
                loopCount++;
                if (!isBreak)//避免死循环。
                {
                    ReplaceItemRef(view, view.GetList("*", itemref), isBreak, loopCount);
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 public Pager(XHtmlAction view)
 {
     doc = view;
 }