示例#1
0
 /// <summary>
 /// 封装shtml请求,如果是主页,找到其频道Guid,找到其主页,否则直接调用请求
 /// </summary>
 public static void AnyShtmlHeadBody(string index, Stream ns)
 {
     if (Path.GetFileName(index) != ConstService.INDEXSHTML)
     {
         ShtmlHeadBody(index, ns);
     }
     else
     {
         string channelStr  = PathService.GetUrlPath(index);;
         string channelGuid = PathService.GetChannelGuid(channelStr);
         if (!string.IsNullOrEmpty(channelGuid))
         {
             string shtmlIndex = TmpltAndPageService.GetIndexPath(channelGuid);
             if (!string.IsNullOrEmpty(shtmlIndex))
             {
                 shtmlIndex = EncodingService.EncodingUTF8(shtmlIndex.Substring(1));
                 ShtmlHeadBody(shtmlIndex, ns);
             }
             else
             {
                 WrongHeadBody(ns);
             }
         }
         else
         {
             WrongHeadBody(ns);
         }
     }
 }
示例#2
0
        /// <summary>
        /// 处理php请求
        /// </summary>
        public static void PhpHeadBody(string index, Stream ns)
        {
            string tmpltId = PathService.GetAnyUrlGuid(index);

            if (TmpltAndPageService.IsContentElement(tmpltId))
            {
                string phpContent = TmpltAndPageService.GetTmpltContent(tmpltId);
                //利用正则表达式替换php中的标题等
                phpContent = RegexService.ChangePhpTag(phpContent);
                string content = PhpBody(phpContent, tmpltId);
                if (!string.IsNullOrEmpty(content))
                {
                    HttpHeadInfo ht = new HttpHeadInfo();
                    content = ConstService.PUBlISHDTD + content;
                    int length = Encoding.UTF8.GetByteCount(content);
                    ht.Content_Length = length.ToString();
                    ht.Content_Type   = "text/html";
                    string strMsgHead = ConstService.OK + ht.GetHttpHead() + content;
                    byte[] bytes      = Encoding.UTF8.GetBytes(strMsgHead);
                    ns.Write(bytes, 0, bytes.Length);
                    ns.Flush();
                    ns.Close();
                }
                else
                {
                    WrongHeadBody(ns);
                }
            }
            else
            {
                WrongHeadBody(ns);
            }
        }
示例#3
0
 /// <summary>
 /// 处理除shtml、php外的其他所有类型
 /// </summary>
 public static void OtherHeadBody(string index, string content_Type, Stream putoutStream)
 {
     try
     {
         string fileName = Path.GetFileName(index);
         string fileType = Path.GetExtension(index).Substring(1);
         //判断是否为CSS请求有责单独处理
         if (content_Type == HttpRequestType.Css.MimeType)
         {
             CssRequestHeadBody(index, putoutStream);
         }
         else
         {
             //判断是否为资源请求,有责找到资源路径(此时请求应均为资源)
             if (index.Substring(0, 2).Contains("Re"))
             {
                 index = PathService.GetResourcesFilePath(index);
             }
             else
             {
                 WrongHeadBody(putoutStream);
             }
             //先进行UTF8解码,再进行Gb2312转吗
             index = EncodingService.EncodingUTF8Change(index);
             if (File.Exists(index))
             {
                 LongFileHeadBody(index, putoutStream, content_Type);
             }
             else
             {
                 index = EncodingService.EncodingGB2312Change(index);
                 if (File.Exists(index))
                 {
                     LongFileHeadBody(index, putoutStream, content_Type);
                 }
                 else
                 {
                     WrongHeadBody(putoutStream);
                 }
             }
         }
     }
     catch (Exception e)
     {
         WrongHeadBody(putoutStream);
     }
 }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <summary>
        /// 判断该CSS为页面片,或模板CSS,找到字典中存储的实例,进行Tocss
        /// </summary>
        internal static byte[] GetCssByte(string index)
        {
            string ElementId = PathService.GetCSSGuid(index);
            string strCss    = null;

            if (ActiveTmpltAndSnip.ActiveTmpltDictionary.ContainsKey(ElementId))
            {
                strCss = "";// ActiveTmpltAndSnip.ActiveTmpltDictionary[ElementId].ToCss();
                ActiveTmpltAndSnip.DeleteTmpltDocmentDictionary(ElementId);
                return(Encoding.UTF8.GetBytes(strCss));
            }
            else if (ActiveTmpltAndSnip.ActiveSnipDictionary.ContainsKey(ElementId))
            {
                strCss = "";//ActiveTmpltAndSnip.ActiveSnipDictionary[ElementId].ToRealCss();
                ActiveTmpltAndSnip.DeleteSnipElementDictionary(ElementId);
                return(Encoding.UTF8.GetBytes(strCss));
            }
            else
            {
                return(Encoding.UTF8.GetBytes(ConstService.BAD));
            }
        }
示例#6
0
        /// <summary>
        /// 获取Channel下子文件的内容
        /// </summary>
        internal static void ChannelHeadBody(string index, Stream ns)
        {
            string channelGuid = PathService.GetChannelGuid(index);

            if (string.IsNullOrEmpty(channelGuid))
            {
                WrongHeadBody(ns);
            }
            else
            {
                HttpHeadInfo ht    = new HttpHeadInfo();
                string       shtml = TmpltAndPageService.GetChannelContent(channelGuid);
                ht.Content_Type = "text/html";
                byte[] bytes = Encoding.UTF8.GetBytes(shtml);
                ht.Content_Length = bytes.Length.ToString();
                shtml             = ConstService.OK + ht.GetHttpHead() + shtml;
                bytes             = Encoding.UTF8.GetBytes(shtml);
                //string respose = ConstService.Redirect +"Location:" + index + "index.shtml\r\n"+ ht.GetHttpHead();
                //byte[] bytes = Encoding.ASCII.GetBytes(respose);
                ns.Write(bytes, 0, bytes.Length);
                ns.Flush();
                ns.Close();
            }
        }
示例#7
0
        /// <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);
            }
        }