コード例 #1
0
ファイル: TemplateRegexUtility.cs プロジェクト: zyuhua/devfw
        /// <summary>
        /// 替换模板的部分视图
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        internal static string ReplacePartial(string html)
        {
            //匹配的部分视图编号
            string matchValue;

            //如果包含部分视图,则替换成部分视图的内容
            if (partialRegex.IsMatch(html))
            {
                //替换模板里的部分视图,并将内容添加到模板内容中
                html = Regex.Replace(html, "\\${partial:\"(.+?)\"}", match =>
                {
                    matchValue = match.Groups[1].Value;
                    return(Regex.IsMatch(matchValue, "^[a-z0-9]+$", RegexOptions.IgnoreCase)
                        ? TemplateUtility.Read(match.Groups[1].Value)
                        : match.Value);
                });
            }

            //返回替换部分视图后的内容
            return(html);
        }
コード例 #2
0
        public override string ToString()
        {
            DateTime dt = DateTime.Now;

            //指定了模板ID
            if (!String.IsNullOrEmpty(_templateId))
            {
                //读取内容
                _templateHtml = TemplateUtility.Read(_templateId);

                //替换部分视图
                _templateHtml = TemplateRegexUtility.ReplacePartial(_templateHtml);
            }

            //HttpContext.Current.Response.Write("<br />1." + (DateTime.Now - dt).Milliseconds.ToString());
            //初始化之前发生
            this.PreInit(this.TemplateHandleObject, ref _templateHtml);

            //如果参数不为空,则替换标签并返回内容
            if (this.data.Count != 0)
            {
                foreach (string key in this.data.Keys)
                {
                    _templateHtml = TemplateRegexUtility.ReplaceHtml(_templateHtml, key, this.data[key].ToString());
                }
            }

            //  HttpContext.Current.Response.Write("<br />2." + (DateTime.Now - dt).Milliseconds.ToString());
            //执行模板语法
            _templateHtml = Eval.Complie(dc, _templateHtml, this.TemplateHandleObject);


            //替换自定义变量
            IDictionary <string, object> defineVars = dc.GetDefineVariable();

            if (defineVars != null && defineVars.Count != 0)
            {
                foreach (string key in defineVars.Keys)
                {
                    if (defineVars[key] is Variable)
                    {
                        _templateHtml = Eval.ResolveVariable(_templateHtml, (Variable)defineVars[key]);
                    }
                    else
                    {
                        _templateHtml = TemplateRegexUtility.ReplaceHtml(_templateHtml, key,
                                                                         (defineVars[key] ?? "").ToString());
                    }
                }
            }

            // HttpContext.Current.Response.Write("<br />3." + (DateTime.Now - dt).Milliseconds.ToString());

            //解析实体的值
            //templateHtml = Eval.ExplanEntityProperties(dc,templateHtml);

            //呈现之前处理
            this.PreRender(this.TemplateHandleObject, ref _templateHtml);

            // HttpContext.Current.Response.Write("<br />4."+(DateTime.Now - dt).Milliseconds.ToString());

            return(_templateHtml);
        }
コード例 #3
0
ファイル: TemplateRegexUtility.cs プロジェクト: zyuhua/devfw
        /// <summary>
        /// 替换模板数据
        /// </summary>
        /// <param name="templateID"></param>
        /// <param name="eval"></param>
        /// <returns></returns>
        internal static string ReplaceTemplate(string templateID, MatchEvaluator eval)
        {
            string html = TemplateUtility.Read(templateID);

            return(TemplateRegexUtility.Replace(html, eval));
        }