/// <summary> /// 生成正文页面片内容 /// </summary> static public string GetContentPageContent(string contentId) { try { PageSimpleExXmlElement pageEle = ToHtmlSdsiteService.SdsiteXmlDocument.GetPageElementById(contentId); TmpltXmlDocument tmpltDoc = ToHtmlSdsiteService.SdsiteXmlDocument.GetTmpltDocumentById(pageEle.TmpltId); SnipXmlElement snipEle = tmpltDoc.GetContentSnipEle(); string contentHtml = null; if (snipEle != null) { // lukan, 2008-6-23 10:38:45, 重构 //contentHtml = snipEle.ToRealContentHtml(contentId); //if (snipEle.IsHaveContent == false && tmpltDoc.TmpltType == TmpltType.General) //{ // contentHtml += "<span>您在正文页面片中还没有添加正文,正文部分将无法显示</span>"; //} //if (!string.IsNullOrEmpty(snipEle.ToRealCss())) //{ // ActiveTmpltAndSnip.AddSnipElementIntoDictionary(snipEle); //} } else { return("您还没有添加正文页面片!"); } return(contentHtml); } catch (Exception e) { ExceptionService.CreateException(e); return(string.Empty); } }
/// <summary> /// 取出“”中的内容 /// </summary> public static string GetQuotationMarkComment(string StringName) { try { string comment = null; int frist_Number = 0; int second_Number = 0; char[] charStringName = StringName.ToCharArray(); int i = 0; //frist_Number = i; //second_Number = 0; while (charStringName[i] != '"') { frist_Number += 1; i = i + 1; } i = i + 1; frist_Number += 1; while (charStringName[i] != '"') { second_Number += 1; i = i + 1; } comment = StringName.Substring(frist_Number, second_Number); return(comment); } catch (Exception e) { ExceptionService.CreateException(e); return(null); } }
/// <summary> /// 通过pageID获取shtml文件的那句话 /// </summary> static public string GetPageContent(string pageId) { try { PageSimpleExXmlElement pageEle = ToHtmlSdsiteService.SdsiteXmlDocument.GetPageElementById(pageId); return("");// pageEle.ToHtml(); } catch (Exception e) { ExceptionService.CreateException(e); return(string.Empty); } }
/// <summary> /// 通过模板ID获得模板的TOHTML,并将该TmpltDoc实例加入到字典中,为Tocss做准备 /// </summary> static public string GetTmpltContent(string tmpltId) { try { TmpltXmlDocument tmpltDoc = ToHtmlSdsiteService.SdsiteXmlDocument.GetTmpltDocumentById(tmpltId); ActiveTmpltAndSnip.AddTmpltDocIntoDictionary(tmpltDoc); return(tmpltDoc.ToHtml()); } catch (Exception e) { ExceptionService.CreateException(e); return(string.Empty); } }
private static void LongFileHeadBody(string filePath, Stream putoutStream, string requestType) { FileInfo file = new FileInfo(filePath); HttpHeadInfo ht = new HttpHeadInfo(); ht.Content_Length = file.Length.ToString(); ht.Content_Type = requestType; string strMsgHead = ConstService.OK + ht.GetHttpHead(); byte[] bytesMsgHead = Encoding.UTF8.GetBytes(strMsgHead); if (file.Length > ConstService.MaxCache) { putoutStream.Write(bytesMsgHead, 0, bytesMsgHead.Length); FileStream fileStream = new FileStream(filePath, FileMode.Open); byte[] buffer = new byte[1024 * 1024 * 10]; long iOffset = 0; try { while (iOffset < file.Length) { int m = fileStream.Read(buffer, 0, buffer.Length); if (m <= 0) { break; } putoutStream.Write(buffer, 0, m); iOffset += m; Console.WriteLine("iOffset" + iOffset); } } catch (Exception e) { ExceptionService.CreateException(e); } fileStream.Close(); } else { byte[] bytesMsgBody = File.ReadAllBytes(filePath); byte[] bytesMsgAll = new byte[bytesMsgHead.Length + bytesMsgBody.Length]; Array.Copy(bytesMsgHead, 0, bytesMsgAll, 0, bytesMsgHead.Length); Array.Copy(bytesMsgBody, 0, bytesMsgAll, bytesMsgHead.Length, bytesMsgBody.Length); putoutStream.Write(bytesMsgAll, 0, bytesMsgAll.Length); } putoutStream.Flush(); putoutStream.Close(); }
/// <summary> /// 当发送频道请求情况下,产生该频道下的列表(文件夹,频道,页面) /// </summary> internal static string GetChannelContent(string channelGuid) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<body></body>"); FolderXmlElement channeEle = ToHtmlSdsiteService.SdsiteXmlDocument.GetFolderElementById(channelGuid); if (string.IsNullOrEmpty(channeEle.DefaultPageId)) { foreach (AnyXmlElement anyEle in channeEle.ChildNodes) { if (anyEle.Name != "siteShowItem") { SimpleExIndexXmlElement pageEle = anyEle as SimpleExIndexXmlElement; if (pageEle.Name != "resources" && pageEle.Name != "tmpltRootFolder" && pageEle.IsDeleted == false) { //如果包含主页,则跳转到主页 XmlElement xmlEle = xmlDoc.CreateElement("div"); XmlElement linkEle = xmlDoc.CreateElement("a"); if (pageEle.Name == "channel" || pageEle.Name == "folder") { linkEle.SetAttribute("href", pageEle.OwnerFolderElement.RelativeUrl); } else { linkEle.SetAttribute("href", pageEle.RelativeUrl); } linkEle.InnerXml += pageEle.FileName; xmlEle.AppendChild(linkEle); xmlDoc.DocumentElement.AppendChild(xmlEle); return(string.Format(ConstService.HTMLUTF8Head, channeEle.Title) + xmlDoc.InnerXml + ConstService.HTMLUTF8END); } } } } else { return("<html><head>" + ConstService.UTF8 + "<meta http-equiv=\"refresh\" content=\"0;URL=http://127.0.0.1:" + Perviewer.Port + channeEle.RelativeUrl + "index.shtml\"></head></html>"); } } catch (Exception e) { ExceptionService.CreateException(e); return(ConstService.BAD); } return("该频道(文件夹)下无内容显示!"); }
/// <summary> /// 替换模板中的所有页面片 /// </summary> private static string PhpBody(string phpString, string tmpltId) { List <string> listIncloude = RegexService.GetIncloudeList(phpString); foreach (string incloude in listIncloude) { string snipId = PathService.GetIncludeHtmlGuid(incloude); string replaceHtml = TmpltAndPageService.GetSnipContent(tmpltId, snipId); try { phpString = phpString.Replace(incloude, replaceHtml); } catch (Exception e) { ExceptionService.CreateException(e); } } return(phpString); }
private static string ChangeNoContentPage(string strContent, string strchange) { Regex contentRegex = new Regex(StrShtmlTitle, RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.IgnoreCase); Match m = contentRegex.Match(strContent); try { if (!string.IsNullOrEmpty(m.Value)) { strContent = strContent.Replace(m.Value, m.Value.Substring(0, m.Value.Length - 8) + "(" + strchange + ")" + "</title>"); } } catch (Exception e) { ExceptionService.CreateException(e); } return(strContent); }
/// <summary> /// 通过模板及snipID获得页面片的HTml,并将该SnipEle实例加入到字典中,为Tocss做准备 /// </summary> static public string GetSnipContent(string tmpltId, string snipId) { try { TmpltXmlDocument tmpltDoc = ToHtmlSdsiteService.SdsiteXmlDocument.GetTmpltDocumentById(tmpltId); SnipXmlElement snipEle = tmpltDoc.GetSnipElementById(snipId); string snipHtml = "";// lukan, 2008-6-23 10:38:45, 重构 snipEle.ToRealHtml(); //if (!string.IsNullOrEmpty(snipEle.ToRealCss())) //{ // ActiveTmpltAndSnip.AddSnipElementIntoDictionary(snipEle); //} return(snipHtml); } catch (Exception e) { ExceptionService.CreateException(e); return(string.Empty); } }
/// <summary> /// 通过频道的url返回频道的GUID,没有则返回空 /// </summary> internal static string GetChannelRequestGuid(string index, ToHtmlHelper thh) { //如果为空返回根节点的Guid if (string.IsNullOrEmpty(index) || index == "//") { return("00000000"); } try { FolderXmlElement folderXmlEle = (FolderXmlElement)thh.SdsiteXmlDocument.GetElementById("00000000"); //url = DelFirstPath(url.Substring(1)); index = index.Substring(0, index.Length - 1); string channelName = GetLastPath(index); string url = DelLastPathName(index); //遍历所有要得到频道的父频道,找到其真实的父频道 while (!string.IsNullOrEmpty(url)) { string folder = GetFirstPath(url); folderXmlEle = (FolderXmlElement)folderXmlEle.SelectSingleNode(string.Format("child::*[@fileName='{0}']", folder)); url = DelFirstPath(url); } //通过父频道返回所求频道的id SimpleExIndexXmlElement xmlEle = (SimpleExIndexXmlElement)folderXmlEle.SelectSingleNode(string.Format("child::channel[@fileName='{0}']|child::folder[@fileName='{0}']", channelName)); if (xmlEle != null) { return(xmlEle.Id); } else { return(null); } } catch (Exception e) { ExceptionService.CreateException(e); return(null); } }
/// <summary> /// 随机生成端口号(最多生成十次) 创建 TcpLister /// </summary> static public TcpListener CreatTcpListener() { //随机生成端口号(最多生成十次) TcpListener listener = null; for (int i = 0; i < 10; i++) { _port = CreatePort(); listener = new TcpListener(new IPEndPoint(IPAddress.Any, _port)); try { listener.Start(); return(listener); } catch (Exception e) { ExceptionService.CreateException(e); } } System.Windows.Forms.MessageBox.Show("过多端口被占用,请检查!"); Application.Exit(); return(null); }
private static void CssRequestHeadBody(string index, Stream putoutStream) { byte[] bytesMsgBody = TmpltAndPageService.GetCssByte(index); HttpHeadInfo htx = new HttpHeadInfo(); htx.Content_Length = bytesMsgBody.Length.ToString(); htx.Content_Type = HttpRequestType.Css.MimeType; string strMsgHeadx = ConstService.OK + htx.GetHttpHead(); byte[] bytesMsgHeadx = Encoding.UTF8.GetBytes(strMsgHeadx); byte[] bytesMsgAll = new byte[bytesMsgHeadx.Length + bytesMsgBody.Length]; Array.Copy(bytesMsgHeadx, 0, bytesMsgAll, 0, bytesMsgHeadx.Length); Array.Copy(bytesMsgBody, 0, bytesMsgAll, bytesMsgHeadx.Length, bytesMsgBody.Length); try { putoutStream.Write(bytesMsgAll, 0, bytesMsgAll.Length); putoutStream.Flush(); } catch (Exception e) { ExceptionService.CreateException(e); } putoutStream.Close(); }
/// <summary> /// 替换 include Get /// </summary> static public string ChangeContent(string strContent, string strChange) { Regex contentRegex = new Regex(StrPhpContent, RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.IgnoreCase); Match m = contentRegex.Match(strContent); try { if (!string.IsNullOrEmpty(m.Value)) { strContent = strContent.Replace(m.Value, strChange); } else { strContent = RegexService.ChangeNoContentPage(strContent, strChange); } } catch (Exception e) { ExceptionService.CreateException(e); } return(strContent); }
/// <summary> /// 处理shtml请求 /// </summary> public static void ShtmlHeadBody(string index, Stream ns) { try { string pageId = PathService.GetPageGuid(index); if (!string.IsNullOrEmpty(pageId)) { string shtmlContent = TmpltAndPageService.GetPageContent(pageId); //获取shtml中include所有内容 string strInclude = RegexService.GetShtmlInclude(shtmlContent); //获取引号中所有内容 string quoMarkContent = StringService.GetQuotationMarkComment(strInclude); HttpHeadInfo ht = new HttpHeadInfo(); string content = ConstService.PUBlISHDTD; ht.Content_Type = "text/html"; string path = StringService.DeleteQuest(quoMarkContent); string tmpltId = PathService.GetAnyUrlGuid(path); content += TmpltAndPageService.GetTmpltContent(tmpltId); content = RegexService.ChangeShtmlTag(content, quoMarkContent); if (quoMarkContent.Contains("keywordList=")) { content = ChangeKeyList(content, tmpltId, pageId); } //判断其页面是否含有正文 if (quoMarkContent.Contains("content=")) { string contentId = RegexService.GetContentId(quoMarkContent); //string contentId = PathService.GetContentId(contentPath); //将正文型内容插到模板中 if (TmpltAndPageService.IsContentElement(contentId)) { string strChange = TmpltAndPageService.GetContentPageContent(contentId); //先运行将正文部分替换 content = RegexService.ChangeContent(content, strChange); } //再将其他页面片替换 content = PhpBody(content, tmpltId); } else { content = PhpBody(content, tmpltId); content += ConstService.HTMLUTF8END; } int leng = Encoding.UTF8.GetByteCount(content); ht.Content_Length = leng.ToString(); string shtmlHeadBody = ConstService.OK + ht.GetHttpHead() + content; byte[] shtmlBytes = Encoding.UTF8.GetBytes(shtmlHeadBody); ns.Write(shtmlBytes, 0, shtmlBytes.Length); ns.Flush(); ns.Close(); } else { WrongHeadBody(ns); } } catch (Exception e) { ExceptionService.CreateException(e); } }
//处理异常写入日志文件 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { ExceptionService.CreateException((Exception)e.ExceptionObject); }