Esempio n. 1
0
File: View.cs Progetto: orapow/yt
        /// <summary>
        /// 执行结果
        /// </summary>
        /// <returns></returns>
        public override byte[] GetResponse()
        {
            var qs = Context.Request.QueryString;
            var v  = qs["v"];

            //var ht = "/html/" + v;
            //ht += ((!string.IsNullOrEmpty(qs["p"]) ? "-" + qs["p"] : "") + ".html").ToLower();

            //var file = Context.Server.MapPath(ht); //Context.Request.RawUrl;

            //if (html_time > 0 || html_time == -1)
            //{
            //    var fi = new FileInfo(file);
            //    if (fi.Exists && (DateTime.Now - fi.LastWriteTime).TotalMinutes < html_time) return File.ReadAllBytes(file);
            //}

            var html = "";

            try
            {
                InitView();
                InitDict();
                html = Tpl.Instance.Merge(GetTplFile() + ".html", dict);
            }
            catch (Exception ex)
            {
                Loger.Error(ex.Message + "\r\n" + ex.StackTrace);
                if (ex.InnerException != null && ex.InnerException is XExcep)
                {
                    throw (XExcep)ex.InnerException;
                }
                throw ex;
            }

            dict?.Clear();

            XForm.GetDictList += XForm_GetDictList;

            html = XForm.Parse(html);

            #region 压缩页面
            //html = Regex.Replace(html, "(/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/)|([^:]//.*)", "");
            //html = Regex.Replace(html, "\\s{2,}", " ");//(>)?\\s+< //去掉空格
            #endregion

            var data = Encoding.UTF8.GetBytes(html);

            //if (html_time > 0 || html_time == -1)
            //{
            //    try
            //    {
            //        Directory.CreateDirectory(file.Substring(0, file.LastIndexOf('\\')));
            //        File.WriteAllBytes(file, data);
            //    }
            //    catch { }
            //}

            return(data);
        }