Ejemplo n.º 1
0
        ///// <summary>
        ///// 根据模板信息模型生成对应的模板
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public static string GetTemplate(Model.URLReWriter model)
        //{
        //    string sitePath = @"/";
        //    string tempPath = "templets";
        //    string skinName = "YTSTemp";
        //    string templet = model.Templet;
        //    string fromPage = model.Page;
        //    string inherit = model.Inherit;
        //    string buildPath = "YTSTemp";
        //    string channelName = model.Channel;
        //    string pageSize = model.PageSize;
        //    int nest = 1;
        //    return GetTemplate(sitePath, tempPath, skinName, templet, fromPage, inherit, buildPath, channelName, pageSize, nest);
        //}

        /// <summary>
        /// 根据模板信息模型生成对应的模板
        /// </summary>
        /// <param name="urlReModel"></param>
        /// <returns></returns>
        public static string GetTempate(UrlRewriteModel urlReModel)
        {
            string sitePath    = @"/";
            string tempPath    = "templets";
            string skinName    = "YTSTemp";
            string templet     = urlReModel.templet;
            string fromPage    = urlReModel.page;
            string inherit     = urlReModel.inherit;
            string buildPath   = "YTSTemp";
            string channelName = urlReModel.channel;
            string pageSize    = urlReModel.pagesize;
            int    nest        = 1;

            return(GetTemplate(sitePath, tempPath, skinName, templet, fromPage, inherit, buildPath, channelName, pageSize, nest));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 取得URL配制列表
        /// </summary>
        public List <UrlRewriteModel> GetList(string channel)
        {
            List <UrlRewriteModel> ls = new List <UrlRewriteModel>();
            string      filePath      = Utils.GetXmlMapPath(Names.FILE_URL_XML_CONFING);
            XmlDocument doc           = new XmlDocument();

            doc.Load(filePath);
            XmlNode xn = doc.SelectSingleNode("urls");

            foreach (XmlElement xe in xn.ChildNodes)
            {
                if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite")
                {
                    if (xe.Attributes["name"] != null)
                    {
                        if (!string.IsNullOrEmpty(channel))
                        {
                            if (xe.Attributes["channel"] != null && channel.ToLower() == xe.Attributes["channel"].Value.ToLower())
                            {
                                UrlRewriteModel model = new UrlRewriteModel();
                                if (xe.Attributes["name"] != null)
                                {
                                    model.name = xe.Attributes["name"].Value;
                                }
                                if (xe.Attributes["type"] != null)
                                {
                                    model.type = xe.Attributes["type"].Value;
                                }
                                if (xe.Attributes["page"] != null)
                                {
                                    model.page = xe.Attributes["page"].Value;
                                }
                                if (xe.Attributes["inherit"] != null)
                                {
                                    model.inherit = xe.Attributes["inherit"].Value;
                                }
                                if (xe.Attributes["templet"] != null)
                                {
                                    model.templet = xe.Attributes["templet"].Value;
                                }
                                if (xe.Attributes["channel"] != null)
                                {
                                    model.channel = xe.Attributes["channel"].Value;
                                }
                                if (xe.Attributes["pagesize"] != null)
                                {
                                    model.pagesize = xe.Attributes["pagesize"].Value;
                                }
                                //再次遍历子节点
                                StringBuilder urlRewriteString      = new StringBuilder();
                                List <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                                foreach (XmlElement xe1 in xe.ChildNodes)
                                {
                                    if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                    {
                                        UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                        if (xe1.Attributes["path"] != null)
                                        {
                                            item.path = xe1.Attributes["path"].Value;
                                        }
                                        if (xe1.Attributes["pattern"] != null)
                                        {
                                            item.pattern = xe1.Attributes["pattern"].Value;
                                        }
                                        if (xe1.Attributes["querystring"] != null)
                                        {
                                            item.querystring = xe1.Attributes["querystring"].Value;
                                        }
                                        urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                                        lsItems.Add(item);
                                    }
                                }
                                model.url_rewrite_str   = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                                model.url_rewrite_items = lsItems;
                                ls.Add(model);
                            }
                        }
                        else
                        {
                            UrlRewriteModel model = new UrlRewriteModel();
                            if (xe.Attributes["name"] != null)
                            {
                                model.name = xe.Attributes["name"].Value;
                            }
                            if (xe.Attributes["type"] != null)
                            {
                                model.type = xe.Attributes["type"].Value;
                            }
                            if (xe.Attributes["page"] != null)
                            {
                                model.page = xe.Attributes["page"].Value;
                            }
                            if (xe.Attributes["inherit"] != null)
                            {
                                model.inherit = xe.Attributes["inherit"].Value;
                            }
                            if (xe.Attributes["templet"] != null)
                            {
                                model.templet = xe.Attributes["templet"].Value;
                            }
                            if (xe.Attributes["channel"] != null)
                            {
                                model.channel = xe.Attributes["channel"].Value;
                            }
                            if (xe.Attributes["pagesize"] != null)
                            {
                                model.pagesize = xe.Attributes["pagesize"].Value;
                            }
                            //再次遍历子节点
                            StringBuilder urlRewriteString      = new StringBuilder();
                            List <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                            foreach (XmlElement xe1 in xe.ChildNodes)
                            {
                                if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                {
                                    UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                    if (xe1.Attributes["path"] != null)
                                    {
                                        item.path = xe1.Attributes["path"].Value;
                                    }
                                    if (xe1.Attributes["pattern"] != null)
                                    {
                                        item.pattern = xe1.Attributes["pattern"].Value;
                                    }
                                    if (xe1.Attributes["querystring"] != null)
                                    {
                                        item.querystring = xe1.Attributes["querystring"].Value;
                                    }
                                    urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                                    lsItems.Add(item);
                                }
                            }
                            model.url_rewrite_str   = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                            model.url_rewrite_items = lsItems;
                            ls.Add(model);
                        }
                    }
                }
            }
            return(ls);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据请求的路径进行匹配配置文件当中是否存在此节点对象
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public UrlRewriteModel GetInfoModel_RequestPagePath(string path)
        {
            UrlRewriteModel model    = new UrlRewriteModel();
            string          filePath = Utils.GetXmlMapPath(Names.FILE_URL_XML_CONFING);
            XmlDocument     doc      = new XmlDocument();

            doc.Load(filePath);
            XmlNode     xn     = doc.SelectSingleNode("urls");
            XmlNodeList xnList = xn.ChildNodes;

            if (xnList.Count > 0)
            {
                foreach (XmlElement xe in xnList)
                {
                    string panduan = "/aspx/YTSTemp/" + xe.Attributes["page"].Value.ToLower();
                    if (panduan.ToLower() == path.ToLower())
                    {
                        if (xe.Attributes["name"] != null)
                        {
                            model.name = xe.Attributes["name"].Value;
                        }
                        if (xe.Attributes["type"] != null)
                        {
                            model.type = xe.Attributes["type"].Value;
                        }
                        if (xe.Attributes["page"] != null)
                        {
                            model.page = xe.Attributes["page"].Value;
                        }
                        if (xe.Attributes["inherit"] != null)
                        {
                            model.inherit = xe.Attributes["inherit"].Value;
                        }
                        if (xe.Attributes["templet"] != null)
                        {
                            model.templet = xe.Attributes["templet"].Value;
                        }
                        if (xe.Attributes["channel"] != null)
                        {
                            model.channel = xe.Attributes["channel"].Value;
                        }
                        if (xe.Attributes["pagesize"] != null)
                        {
                            model.pagesize = xe.Attributes["pagesize"].Value;
                        }
                        //再次遍历子节点
                        List <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                        foreach (XmlElement xe1 in xe.ChildNodes)
                        {
                            if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                            {
                                UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                if (xe1.Attributes["path"] != null)
                                {
                                    item.path = xe1.Attributes["path"].Value;
                                }
                                if (xe1.Attributes["pattern"] != null)
                                {
                                    item.pattern = xe1.Attributes["pattern"].Value;
                                }
                                if (xe1.Attributes["querystring"] != null)
                                {
                                    item.querystring = xe1.Attributes["querystring"].Value;
                                }
                                lsItems.Add(item);
                            }
                        }
                        model.url_rewrite_items = lsItems;
                        return(model);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改节点
        /// </summary>
        public bool Edit(UrlRewriteModel model)
        {
            string      filePath = Utils.GetXmlMapPath(Names.FILE_URL_XML_CONFING);
            XmlDocument doc      = new XmlDocument();

            doc.Load(filePath);
            XmlNode     xn     = doc.SelectSingleNode("urls");
            XmlNodeList xnList = xn.ChildNodes;

            if (xnList.Count > 0)
            {
                foreach (XmlElement xe in xnList)
                {
                    if (xe.Attributes["name"].Value.ToLower() == model.name.ToLower())
                    {
                        if (!string.IsNullOrEmpty(model.type))
                        {
                            xe.SetAttribute("type", model.type);
                        }
                        else if (xe.Attributes["type"] != null)
                        {
                            xe.Attributes["type"].RemoveAll();
                        }

                        if (!string.IsNullOrEmpty(model.page))
                        {
                            xe.SetAttribute("page", model.page);
                        }
                        else if (xe.Attributes["page"] != null)
                        {
                            xe.Attributes["page"].RemoveAll();
                        }

                        if (!string.IsNullOrEmpty(model.inherit))
                        {
                            xe.SetAttribute("inherit", model.inherit);
                        }
                        else if (xe.Attributes["inherit"] != null)
                        {
                            xe.Attributes["inherit"].RemoveAll();
                        }

                        if (!string.IsNullOrEmpty(model.templet))
                        {
                            xe.SetAttribute("templet", model.templet);
                        }
                        else if (xe.Attributes["templet"] != null)
                        {
                            xe.Attributes["templet"].RemoveAll();
                        }

                        if (!string.IsNullOrEmpty(model.channel))
                        {
                            xe.SetAttribute("channel", model.channel);
                        }
                        else if (xe.Attributes["channel"] != null)
                        {
                            xe.Attributes["channel"].RemoveAll();
                        }

                        if (!string.IsNullOrEmpty(model.pagesize))
                        {
                            xe.SetAttribute("pagesize", model.pagesize);
                        }
                        else if (xe.Attributes["pagesize"] != null)
                        {
                            xe.Attributes["pagesize"].RemoveAll();
                        }

                        //移除所有的子节点重新添加
                        XmlNodeList itemXnList = xe.ChildNodes;
                        foreach (XmlElement itemXe in itemXnList)
                        {
                            for (int i = itemXnList.Count - 1; i >= 0; i--)
                            {
                                XmlElement xe2 = (XmlElement)itemXnList.Item(i);
                                xe.RemoveChild(xe2);
                            }
                        }
                        //创建子节点
                        foreach (UrlRewrite_ItemModel modelt in model.url_rewrite_items)
                        {
                            XmlElement xeItem = doc.CreateElement("item");
                            if (!string.IsNullOrEmpty(modelt.path))
                            {
                                xeItem.SetAttribute("path", modelt.path);
                            }
                            if (!string.IsNullOrEmpty(modelt.pattern))
                            {
                                xeItem.SetAttribute("pattern", modelt.pattern);
                            }
                            if (!string.IsNullOrEmpty(modelt.querystring))
                            {
                                xeItem.SetAttribute("querystring", modelt.querystring);
                            }
                            xe.AppendChild(xeItem);
                        }

                        doc.Save(filePath);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 增加节点
        /// </summary>
        public bool Add(UrlRewriteModel model)
        {
            try
            {
                string      filePath = Utils.GetXmlMapPath(Names.FILE_URL_XML_CONFING);
                XmlDocument doc      = new XmlDocument();
                doc.Load(filePath);
                XmlNode    xn = doc.SelectSingleNode("urls");
                XmlElement xe = doc.CreateElement("rewrite");
                if (!string.IsNullOrEmpty(model.name))
                {
                    xe.SetAttribute("name", model.name);
                }
                if (!string.IsNullOrEmpty(model.type))
                {
                    xe.SetAttribute("type", model.type);
                }
                if (!string.IsNullOrEmpty(model.page))
                {
                    xe.SetAttribute("page", model.page);
                }
                if (!string.IsNullOrEmpty(model.inherit))
                {
                    xe.SetAttribute("inherit", model.inherit);
                }
                if (!string.IsNullOrEmpty(model.templet))
                {
                    xe.SetAttribute("templet", model.templet);
                }
                if (!string.IsNullOrEmpty(model.channel))
                {
                    xe.SetAttribute("channel", model.channel);
                }
                if (!string.IsNullOrEmpty(model.pagesize))
                {
                    xe.SetAttribute("pagesize", model.pagesize);
                }
                XmlNode newXn = xn.AppendChild(xe);

                //创建子节点
                foreach (UrlRewrite_ItemModel modelt in model.url_rewrite_items)
                {
                    XmlElement xeItem = doc.CreateElement("item");
                    if (!string.IsNullOrEmpty(modelt.path))
                    {
                        xeItem.SetAttribute("path", modelt.path);
                    }
                    if (!string.IsNullOrEmpty(modelt.pattern))
                    {
                        xeItem.SetAttribute("pattern", modelt.pattern);
                    }
                    if (!string.IsNullOrEmpty(modelt.querystring))
                    {
                        xeItem.SetAttribute("querystring", modelt.querystring);
                    }
                    newXn.AppendChild(xeItem);
                }

                doc.Save(filePath);
                return(true);
            }
            catch
            {
                return(false);
            }
        }