public NewsPublishHandler(string Url) { config = (NewsConfigurationSection)ConfigurationManager.GetSection("publish/newsPublish"); Logger = LogManager.GetLogger(config.Logger); dal = new NewsDataAccess(config); PageParameter = GetParameter(Url); PageFileName = GetPageFileName(); }
private NewsPageParameter GetParameter(string Url) { NewsPageParameter parm = null; string NewsDetailPattern = @"news(_|-)+(?<newsid>\d+)"; string NewsListPattern = @"newslist(_|-)+(?<categoryid>\d+)((_|-)+(?<pageIndex>\d+))?"; if (Url.EndsWith("news")) { Regex reg = new Regex(NewsDetailPattern, RegexOptions.IgnoreCase); Match match = reg.Match(Url); if (match.Success) { parm = new NewsPageParameter(); parm.NewsID = Convert.ToInt32(match.Groups["newsid"].Value); parm.PageType = 2; DataTable dt = dal.GetNewsCategoryInfo(parm.NewsID); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; parm.CategoryID = Convert.ToInt32(row["cateid"]); parm.CategoryPath = Convert.ToString(row["catepath"]); } else { throw new PublishException("新闻不存在"); } } else { throw new PublishException("地址不正确"); } } if (Url.EndsWith("newslist")) { Regex reg = new Regex(NewsListPattern, RegexOptions.IgnoreCase); Match match = reg.Match(Url); if (match.Success) { parm = new NewsPageParameter(); parm.CategoryID = Convert.ToInt32(match.Groups["categoryid"].Value); parm.PageIndex = 1; if (match.Groups["pageIndex"].Success) { parm.PageIndex = Convert.ToInt32(match.Groups["pageIndex"].Value); if (parm.PageIndex <= 0) { parm.PageIndex = 1; } } parm.PageType = 1; DataTable dt = dal.GetCategoryInfo(parm.CategoryID); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; parm.CategoryPath = Convert.ToString(row["catepath"]); } else { throw new PublishException("分类不存在"); } } else { throw new PublishException("地址不正确"); } } return(parm); }
private NewsPageParameter GetParameter(string Url) { NewsPageParameter parm = null; string NewsDetailPattern = @"news(_|-)+(?<newsid>\d+)"; string NewsListPattern = @"newslist(_|-)+(?<categoryid>\d+)((_|-)+(?<pageIndex>\d+))?"; if (Url.EndsWith("news")) { Regex reg = new Regex(NewsDetailPattern, RegexOptions.IgnoreCase); Match match = reg.Match(Url); if (match.Success) { parm = new NewsPageParameter(); parm.NewsID = Convert.ToInt32(match.Groups["newsid"].Value); parm.PageType = 2; DataTable dt = dal.GetNewsCategoryInfo(parm.NewsID); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; parm.CategoryID = Convert.ToInt32(row["cateid"]); parm.CategoryPath = Convert.ToString(row["catepath"]); } else { throw new PublishException("新闻不存在"); } } else { throw new PublishException("地址不正确"); } } if (Url.EndsWith("newslist")) { Regex reg = new Regex(NewsListPattern, RegexOptions.IgnoreCase); Match match = reg.Match(Url); if (match.Success) { parm = new NewsPageParameter(); parm.CategoryID = Convert.ToInt32(match.Groups["categoryid"].Value); parm.PageIndex = 1; if (match.Groups["pageIndex"].Success) { parm.PageIndex = Convert.ToInt32(match.Groups["pageIndex"].Value); if (parm.PageIndex <= 0) parm.PageIndex = 1; } parm.PageType = 1; DataTable dt = dal.GetCategoryInfo(parm.CategoryID); if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; parm.CategoryPath = Convert.ToString(row["catepath"]); } else { throw new PublishException("分类不存在"); } } else { throw new PublishException("地址不正确"); } } return parm; }