示例#1
0
 /// <summary>
 /// Adds the res dependency.
 /// </summary>
 /// <param name="res">The res.</param>
 public void AddResDependency(IResourceDependency res)
 {
     if (!ContainsResDependency(res))
     {
         ResTab.Add(res.DependencyIdentity, res);
     }
 }
示例#2
0
 /// <summary>
 /// Adds the res dependency.
 /// </summary>
 /// <param name="res">The res.</param>
 public void AddResDependency(IResourceDependency res)
 {
     if (!ContainsResDependency(res))
     {
         ResTab.Add(res.DependencyIdentity, res);
     }
 }
示例#3
0
文件: TagBase.cs 项目: ridgew/fmq
        /// <summary>
        /// 获取标签定义的值
        /// </summary>
        /// <returns>根据标签定义和所依赖的资源获取标签的最终值。</returns>
        public virtual object GetTagValue()
        {
            if (this.TagDefinition == null)
            {
                return(null);
            }

            if (!this.IsDependencyTag)
            {
                return(this.TagDefinition);
            }
            else
            {
                IResourceDependency res = this.GetResourceDependency();
                if (res != null && res.IsDefined(this.TagDefinition))
                {
                    return(res.GetDefinition(this.TagDefinition));
                }
                else
                {
                    //直接返回定义继续解析
                    return(this.OuterDefineText);
                }
            }
        }
示例#4
0
文件: ListTag.cs 项目: ridgew/fmq
        /// <summary>
        /// 转化为列表标签,并传递资源依赖对象
        /// </summary>
        public static ListTag Parse(TagBase tag, IResourceDependency res)
        {
            ListTag listTag = new ListTag();

            listTag.SetResourceDependency(res);
            listTag.InheriteFromBase(tag);
            listTag.SetListTemplet(tag.OuterDefineText);
            return(listTag);
        }
示例#5
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="TagParse"/> class.
 /// </summary>
 /// <param name="tagdef">The tagdef.</param>
 /// <param name="res">The res.</param>
 public TagParse(string tagdef, IResourceDependency res)
 {
     if (!tagdef.StartsWith("{#$") || !tagdef.EndsWith("$#}"))
     {
         throw new InvalidProgramException("标签定义错误!");
     }
     else
     {
         SetResourceDependency(res);
         this._tagDef = tagdef;
         InitializeTag(tagdef.Substring(3, tagdef.Length - 6).Trim());
     }
 }
示例#6
0
文件: TagBase.cs 项目: ridgew/fmq
        /// <summary>
        /// 解析包含标签的文本内容
        /// </summary>
        /// <param name="TxtContent">包含标签的文本内容</param>
        /// <param name="res">说依赖的相关资源对象</param>
        public static string InterpretContentWithTags(string TxtContent, IResourceDependency res)
        {
            if (!TxtContent.StartsWith("{#"))
            {
                TxtContent = "#}" + TxtContent + "{#";
            }

            PagerTag txtTag = new PagerTag();

            PagerTag.FilledInTagList(TxtContent, txtTag.tagList, res);
            txtTag.AlwaysShow = true;
            return(txtTag.ToString());
        }
示例#7
0
文件: TagBase.cs 项目: ridgew/fmq
 /// <summary>
 /// 设置该标签所依赖的资源
 /// </summary>
 public void SetResourceDependency(IResourceDependency value)
 {
     this._resDependency = value;
     //if (value is MultiResDependency)
     //{
     //    MultiResDependency mRes = (MultiResDependency)value;
     //    mRes.AddResDependency(value);
     //    this._resDependency = mRes;
     //}
     //else
     //{
     //    this._resDependency = new MultiResDependency(value, RequestResDependency.Instance);
     //}
 }
示例#8
0
 /// <summary>
 /// 释放占用资源
 /// </summary>
 public void Dispose()
 {
     TagTrack            = null;
     this._resDependency = null;
     this._parsedResult  = null;
 }
示例#9
0
        /// <summary>
        /// 设置输出形式
        /// </summary>
        public override string ToString()
        {
            IResourceDependency res = this.GetResourceDependency();

            if (res == null && TagDefinition.IndexOf("(") == -1 && TagDefinition.IndexOf('[') == -1 && TagDefinition.IndexOf('$') == -1)
            {
                object tagValue = base.GetTagValue();
                return((tagValue == null) ? "" : tagValue.ToString());
            }
            else
            {
                #region 如果资源有直接定义
                if (res != null)
                {
                    string resDefineKey = this.TagDefinition;
                    //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + " " + res.ToString());
                    //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + " " + resDefineKey);
                    if (res.IsDefined(resDefineKey))
                    {
                        //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + resDefineKey + " " + res.ToString());
                        return(res.GetDefinition(resDefineKey).ToString());
                    }
                }
                #endregion

                #region 草稿设计
                //()表示函数 []表示数组
                //{#$["首页","新闻","动态","联系"][2]$#}		= "动态"
                //{#$Now()$#} {#$Now('yyyy-MM-dd HH:mm:ss')$#}	= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

                //函数表达式数据绑定
                //-----------------------------------------------
                //{$Left(源文本,字段长)}
                //->
                //源文本 = {#FieldName},{%Year}
                //字段长 = 12

                //{${%Hour}==12 ? "正午": "其他时间"}
                //{$Contains({#FieldName},"虚数传播") ? "包含" : "不包含"}

                //数据操作符号
                //> < == != ?:
                #endregion

                //避免SVN/VSS关键字替换
                if (this.TagDefinition == "{#$" + "Date$#}")
                {
                    return(DateTime.Now.Date.ToString("yyyy-M-d"));
                }
                else if (this.TagDefinition == "{#$WK$#}")
                {
                    return(DateTime.Now.DayOfWeek.GetHashCode().ToString());
                }
                else if (this.TagDefinition == "{#$Year$#}")
                {
                    return(DateTime.Now.Year.ToString());
                }
                else if (this.TagDefinition == "{#$Month$#}")
                {
                    return(DateTime.Now.Month.ToString());
                }
                else if (this.TagDefinition == "{#$Day$#}")
                {
                    return(DateTime.Now.Day.ToString());
                }
                else if (this.TagDefinition == "{#$Hour$#}")
                {
                    return(DateTime.Now.Hour.ToString());
                }
                else if (this.TagDefinition == "{#$Minute$#}")
                {
                    return(DateTime.Now.Minute.ToString());
                }
                else if (this.TagDefinition == "{#$Second$#}")
                {
                    return(DateTime.Now.Second.ToString());
                }
                else if (this.TagDefinition == "{#$MS$#}")
                {
                    return(DateTime.Now.Millisecond.ToString());
                }
                else if (this.TagDefinition.StartsWith("{#$<") && this.TagDefinition.EndsWith(">$#}"))
                {
                    string urlMatchVal = this.TagDefinition.Substring(4, this.TagDefinition.Length - 8);
                    //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + urlMatchVal);
                    if (HttpContext.Current.Items["UrlMatchGroup"] == null)
                    {
                        //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + this.TagDefinition);
                        return(string.Empty);
                    }
                    else
                    {
                        GroupCollection grpCol = (GroupCollection)HttpContext.Current.Items["UrlMatchGroup"];
                        if (Util.IsNumerical(urlMatchVal))
                        {
                            return(grpCol[Convert.ToInt32(urlMatchVal)].Value);
                        }
                        else
                        {
                            return(grpCol[urlMatchVal].Value);
                        }
                    }
                }
                else
                {
                    string objResult = this.TagDefinition;
                    try
                    {
                        //if (GetResourceDependency() != null)
                        //{
                        //    OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + GetResourceDependency().ToString());
                        //}
                        using (TagParse tgp = new TagParse(objResult, GetResourceDependency()))
                        {
                            objResult = tgp.GetValue();
                        }
                    }
                    catch (Exception exp)
                    {
                        //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + this.TagDefinition + "\n" + res);

                        throw new InvalidOperationException(string.Format("系统标签解析错误,标签定义:{0}\n提示:{1} \n源跟踪:{2}",
                                                                          objResult,
                                                                          exp.Message,
                                                                          exp.StackTrace));
                    }
                    return(objResult);
                }
            }
        }
示例#10
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="InnerExpression"/> class.
 /// </summary>
 /// <param name="exp">The exp.</param>
 /// <param name="res">The res.</param>
 public InnerExpression(string exp, IResourceDependency res)
 {
     SetResourceDependency(res);
     InitialBase(exp);
 }
示例#11
0
 /// <summary>
 /// 设置该模板所依赖的资源
 /// </summary>
 public void SetResourceDependency(IResourceDependency value)
 {
     this._resDependency = value;
 }
示例#12
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="InnerExpression"/> class.
 /// </summary>
 /// <param name="funName">Name of the fun.</param>
 /// <param name="paramsBody">The params body.</param>
 /// <param name="res">The res.</param>
 public InnerExpression(string funName, string paramsBody, IResourceDependency res)
 {
     SetResourceDependency(res);
     this.IsFunction = true;
     this._equalFun = new InnerFunction(funName, paramsBody, res);
     this.TagDefinition = this._equalFun.TagDefinition;
 }
示例#13
0
文件: TagBase.cs 项目: vbyte/fmq
 /// <summary>
 /// 设置该标签所依赖的资源
 /// </summary>
 public void SetResourceDependency(IResourceDependency value)
 {
     this._resDependency = value;
     //if (value is MultiResDependency)
     //{
     //    MultiResDependency mRes = (MultiResDependency)value;
     //    mRes.AddResDependency(value);
     //    this._resDependency = mRes;
     //}
     //else
     //{
     //    this._resDependency = new MultiResDependency(value, RequestResDependency.Instance);
     //}
 }
示例#14
0
 ///// <summary>
 ///// 获取依赖资源容器集合
 ///// </summary>
 //public List<IResourceDependency> GetResTab()
 //{
 //    return ResTab;
 //}
 /// <summary>
 /// 检测是否包含指定的资源依赖项
 /// </summary>
 /// <param name="res">资源依赖项</param>
 public bool ContainsResDependency(IResourceDependency res)
 {
     return ResTab.ContainsKey(res.DependencyIdentity);
 }
示例#15
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="InnerFunction"/> class.
 /// </summary>
 /// <param name="funName">Name of the fun.</param>
 /// <param name="res">The res.</param>
 /// <param name="objParams">The obj params.</param>
 public InnerFunction(string funName, IResourceDependency res, params InnerParam[] objParams)
 {
     this.FunctionName = funName;
     SetResourceDependency(res);
     StringBuilder paramsBody = new StringBuilder();
     foreach (InnerParam param in objParams)
     {
         this.fParamList.Add(param);
         paramsBody.Append("," + param.TagDefinition);
     }
     this.TagDefinition = string.Format("{0}({1})", funName, paramsBody.ToString().TrimStart(','));
 }
示例#16
0
文件: HtmlTextTag.cs 项目: ridgew/fmq
 public void SetResourceDependency(IResourceDependency value)
 {
 }
示例#17
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="InnerParam"/> class.
 /// </summary>
 /// <param name="paramdef">The paramdef.</param>
 /// <param name="res">The res.</param>
 public InnerParam(string paramdef, IResourceDependency res)
 {
     SetResourceDependency(res);
     //OleDbHelper.AppendToFile("~/debug.txt", "\n\n 参数定义:" + paramdef);
     this.ParamDefine = paramdef;
 }
示例#18
0
文件: HtmlTextTag.cs 项目: vbyte/fmq
 public void SetResourceDependency(IResourceDependency value)
 {
 }
示例#19
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// 获取相关数组指定下标的值
 /// </summary>
 /// <param name="ArrayDat">数组数据</param>
 /// <param name="idx">数组元素的下标</param>
 /// <param name="res">相关依赖资源定义</param>
 /// <returns>如果存在改下标的数据则返回,否则返回空字符。</returns>
 public static object GetArrayItemValue(string[] ArrayDat, int idx, IResourceDependency res)
 {
     if (ArrayDat == null || idx > ArrayDat.Length)
     {
         return "";
     }
     else
     {
         InnerParam param = new InnerParam(ArrayDat[idx], res);
         return param.GetValue();
     }
 }
示例#20
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// 获取相关数组指定下标的值
 /// </summary>
 /// <param name="ArrayBodyDefine">数组定义体,形如:["a","b"]。</param>
 /// <param name="separator">数组元素分隔字符</param>
 /// <param name="idx">数组元素的下标</param>
 /// <param name="res">相关依赖资源定义</param>
 /// <returns>如果存在改下标的数据则返回,否则返回空字符。</returns>
 public static object GetArrayItemValue(string ArrayBodyDefine, char separator, int idx, IResourceDependency res)
 {
     string[] arrDat = ReservedWords.GetStringArray(ArrayBodyDefine, separator, new char[] { '[', '"', '\'', '(' });
     return GetArrayItemValue(arrDat, idx, res);
 }
示例#21
0
        internal static void FilledInTagList(string tagdef, ArrayList tagList, IResourceDependency res)
        {
            int idxBegin = 0, idxEnd = 0;

            idxBegin = tagdef.IndexOf("#}");
            idxEnd   = tagdef.LastIndexOf("{#");
            tagdef   = tagdef.Substring(idxBegin + 2, idxEnd - idxBegin - 2).Trim();

            Regex regEx = new Regex(TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            idxBegin = idxEnd = 0;
            MatchCollection mc      = regEx.Matches(tagdef, idxBegin);
            HtmlTextTag     htmlTag = null;

            while (mc.Count > 0)
            {
                Match m = mc[0];
                idxEnd = m.Index;

                if (idxEnd > idxBegin)
                {
                    htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin, idxEnd - idxBegin));
                    tagList.Add(htmlTag);
                }

                TagBase tag = new TagBase(m.Value, m.Index, ref tagdef);
                //Util.Debug(tag.Category);
                if (tag.Category == TagCategory.AutoTag)
                {
                    AutoItem item = AutoItem.Parse(tag);
                    if (res.GetType() == typeof(PagerTag))
                    {
                        item.CallerTag = (PagerTag)res;
                    }
                    tagList.Add(item);
                }
                else if (tag.Category == TagCategory.DefineTag)
                {
                    //数据库标签定义格式为 {#%FieldName%#}
                    if (res != null)
                    {
                        htmlTag = new HtmlTextTag(res.GetDefinition(tag.OuterDefineText).ToString());
                        tagList.Add(htmlTag);
                    }
                }
                else if (tag.Category == TagCategory.CustomTag)
                {
                    #region 数据定义标签内包含数据定义标签
                    DbStoredCustomTag dbTag = DbStoredCustomTag.Parse(tag);
                    dbTag.SetResourceDependency(res);
                    if (dbTag.IsExist == true)
                    {
                        htmlTag = new HtmlTextTag(dbTag.GetTagValue().ToString());
                        tagList.Add(htmlTag);
                    }
                    #endregion
                }
                else if (tag.Category == TagCategory.SystemTag)
                {
                    string pageURLKey = ",FirstUrl,PreUrl,NextUrl,LastUrl,CurUrl,";
                    string tagName    = tag.TagName.Trim('$');
                    if (pageURLKey.IndexOf("," + tagName + ",", StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        tagName = tagName.ToLower();
                        PageUrl url = new PageUrl(tag.OuterDefineText);
                        url.IsAutoItem = (res != null && res.GetType() == typeof(AutoItem));
                        url.SetResourceDependency(res);
                        switch (tagName)
                        {
                        case "firsturl": url.UrlCategory = PageUrlCategory.FirstPage; break;

                        case "preurl": url.UrlCategory = PageUrlCategory.PrePage; break;

                        case "nexturl": url.UrlCategory = PageUrlCategory.NextPage; break;

                        case "lasturl": url.UrlCategory = PageUrlCategory.LastPage; break;

                        case "cururl": url.UrlCategory = PageUrlCategory.ThisPage; break;

                        default:
                            url.UrlCategory = PageUrlCategory.ThisPage;
                            break;
                        }
                        tagList.Add(url);
                    }
                    else
                    {
                        SystemTag sys = new SystemTag(tag.OuterDefineText);
                        //Util.Debug(false, res.GetType().ToString());
                        sys.SetResourceDependency(res);
                        tagList.Add(sys);
                    }
                }
                else
                {
                    tagList.Add(tag);
                }
                //Util.Debug(false, "#####\n" + tag.OuterDefineText + "\n#####");
                //TagList.Add(tag);

                idxBegin = tag.DefinedIndexEnd;
                mc       = regEx.Matches(tagdef, idxBegin);
            }

            if (idxBegin < tagdef.Length)
            {
                htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin));
                tagList.Add(htmlTag);
            }
        }
示例#22
0
文件: TempletParse.cs 项目: vbyte/fmq
 /// <summary>
 /// 设置该模板所依赖的资源
 /// </summary>
 public void SetResourceDependency(IResourceDependency value)
 {
     this._resDependency = value;
 }
示例#23
0
        ///// <summary>
        ///// 获取依赖资源容器集合
        ///// </summary>
        //public List<IResourceDependency> GetResTab()
        //{
        //    return ResTab;
        //}

        /// <summary>
        /// 检测是否包含指定的资源依赖项
        /// </summary>
        /// <param name="res">资源依赖项</param>
        public bool ContainsResDependency(IResourceDependency res)
        {
            return(ResTab.ContainsKey(res.DependencyIdentity));
        }
示例#24
0
文件: TagBase.cs 项目: vbyte/fmq
        /// <summary>
        /// 获取数据表中的转义数据
        /// </summary>
        /// <param name="CurrentIndex">当前索引</param>
        /// <param name="Tpt">模板内容</param>
        /// <param name="dRow">数据行</param>
        /// <param name="Res">依赖资源</param>
        public static string GetDataEscapedValue(int CurrentIndex, string Tpt, DataRow dRow, IResourceDependency Res)
        {
            // 替换索引
            Tpt = Regex.Replace(Tpt, @"(\{#)?(\$Index\$)(#\})?", CurrentIndex.ToString(), RegexOptions.IgnoreCase | RegexOptions.Compiled);

            StringBuilder sb = new StringBuilder(Tpt.Length);
            Regex RE = new Regex(@"(\{#)?%([\w]+)%(#\})?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = RE.Matches(Tpt);
            int idxBegin = 0, idxEnd = 0;
            foreach (Match m in mc)
            {
                idxEnd = m.Index;
                sb.Append(Tpt.Substring(idxBegin, idxEnd - idxBegin));
                sb.Append(dRow[m.Groups[2].Value]);
                idxBegin = idxEnd + m.Length;
            }
            if (idxBegin < Tpt.Length)
            {
                sb.Append(Tpt.Substring(idxBegin));
            }
            return InterpretContentWithTags(sb.ToString(), Res);
        }
示例#25
0
文件: ListTag.cs 项目: vbyte/fmq
 /// <summary>
 /// 转化为列表标签,并传递资源依赖对象
 /// </summary>
 public static ListTag Parse(TagBase tag, IResourceDependency res)
 {
     ListTag listTag = new ListTag();
     listTag.SetResourceDependency(res);
     listTag.InheriteFromBase(tag);
     listTag.SetListTemplet(tag.OuterDefineText);
     return listTag;
 }
示例#26
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// 初始化一个数组表达式
 /// </summary>
 /// <param name="arryDefine">数组定义</param>
 /// <param name="Separator">分隔字符</param>
 /// <param name="res">依赖资源</param>
 public InnerExpression(string arryDefine, char Separator, IResourceDependency res)
 {
     SetResourceDependency(res);
     ArraySeparator = Separator;
     IsArrayDefine = true;
     InitialBase(arryDefine);
 }
示例#27
0
文件: TempletParse.cs 项目: vbyte/fmq
 /// <summary>
 /// 释放占用资源
 /// </summary>
 public void Dispose()
 {
     TagTrack = null;
     this._resDependency = null;
     this._parsedResult = null;
 }
示例#28
0
文件: TagParse.cs 项目: vbyte/fmq
 /// <summary>
 /// Initializes a new instance of the <see cref="InnerFunction"/> class.
 /// </summary>
 /// <param name="funName">Name of the fun.</param>
 /// <param name="paramsBody">The params body.</param>
 /// <param name="res">The res.</param>
 public InnerFunction(string funName, string paramsBody, IResourceDependency res)
 {
     SetResourceDependency(res);
     this.FunctionName = funName;
     SetFunctionParams(paramsBody);
     this.TagDefinition = string.Format("{0}({1})", funName, paramsBody);
 }
示例#29
0
文件: TagBase.cs 项目: vbyte/fmq
        /// <summary>
        /// 解析包含标签的文本内容
        /// </summary>
        /// <param name="TxtContent">包含标签的文本内容</param>
        /// <param name="res">说依赖的相关资源对象</param>
        public static string InterpretContentWithTags(string TxtContent, IResourceDependency res)
        {
            if (!TxtContent.StartsWith("{#"))
            {
                TxtContent = "#}" + TxtContent + "{#";
            }

            PagerTag txtTag = new PagerTag();
            PagerTag.FilledInTagList(TxtContent, txtTag.tagList, res);
            txtTag.AlwaysShow = true;
            return txtTag.ToString();
        }
示例#30
0
文件: TagBase.cs 项目: ridgew/fmq
        /// <summary>
        /// 获取数据表中的转义数据
        /// </summary>
        /// <param name="CurrentIndex">当前索引</param>
        /// <param name="Tpt">模板内容</param>
        /// <param name="dRow">数据行</param>
        /// <param name="Res">依赖资源</param>
        public static string GetDataEscapedValue(int CurrentIndex, string Tpt, DataRow dRow, IResourceDependency Res)
        {
            // 替换索引
            Tpt = Regex.Replace(Tpt, @"(\{#)?(\$Index\$)(#\})?", CurrentIndex.ToString(), RegexOptions.IgnoreCase | RegexOptions.Compiled);

            StringBuilder   sb = new StringBuilder(Tpt.Length);
            Regex           RE = new Regex(@"(\{#)?%([\w]+)%(#\})?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = RE.Matches(Tpt);
            int             idxBegin = 0, idxEnd = 0;

            foreach (Match m in mc)
            {
                idxEnd = m.Index;
                sb.Append(Tpt.Substring(idxBegin, idxEnd - idxBegin));
                sb.Append(dRow[m.Groups[2].Value]);
                idxBegin = idxEnd + m.Length;
            }
            if (idxBegin < Tpt.Length)
            {
                sb.Append(Tpt.Substring(idxBegin));
            }
            return(InterpretContentWithTags(sb.ToString(), Res));
        }
示例#31
0
文件: PagerTag.cs 项目: vbyte/fmq
        internal static void FilledInTagList(string tagdef, ArrayList tagList, IResourceDependency res)
        {
            int idxBegin = 0, idxEnd = 0;
            idxBegin = tagdef.IndexOf("#}");
            idxEnd = tagdef.LastIndexOf("{#");
            tagdef = tagdef.Substring(idxBegin+2, idxEnd - idxBegin-2).Trim();

            Regex regEx = new Regex(TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            idxBegin = idxEnd = 0;
            MatchCollection mc = regEx.Matches(tagdef, idxBegin);
            HtmlTextTag htmlTag = null;
            while (mc.Count > 0)
            {
                Match m = mc[0];
                idxEnd = m.Index;

                if (idxEnd > idxBegin)
                {
                    htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin, idxEnd - idxBegin));
                    tagList.Add(htmlTag);
                }

                TagBase tag = new TagBase(m.Value, m.Index, ref tagdef);
                //Util.Debug(tag.Category);
                if (tag.Category == TagCategory.AutoTag)
                {
                    AutoItem item = AutoItem.Parse(tag);
                    if (res.GetType() == typeof(PagerTag))
                    {
                        item.CallerTag = (PagerTag)res;
                    }
                    tagList.Add(item);
                }
                else if (tag.Category == TagCategory.DefineTag)
                {
                    //数据库标签定义格式为 {#%FieldName%#}
                    if (res != null)
                    {
                        htmlTag = new HtmlTextTag(res.GetDefinition(tag.OuterDefineText).ToString());
                        tagList.Add(htmlTag);
                    }
                }
                else if (tag.Category == TagCategory.CustomTag)
                {
                    #region 数据定义标签内包含数据定义标签
                    DbStoredCustomTag dbTag = DbStoredCustomTag.Parse(tag);
                    dbTag.SetResourceDependency(res);
                    if (dbTag.IsExist == true)
                    {
                        htmlTag = new HtmlTextTag(dbTag.GetTagValue().ToString());
                        tagList.Add(htmlTag);
                    }
                    #endregion
                }
                else if (tag.Category == TagCategory.SystemTag)
                {
                    string pageURLKey = ",FirstUrl,PreUrl,NextUrl,LastUrl,CurUrl,";
                    string tagName = tag.TagName.Trim('$');
                    if (pageURLKey.IndexOf("," + tagName + ",", StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        tagName = tagName.ToLower();
                        PageUrl url = new PageUrl(tag.OuterDefineText);
                        url.IsAutoItem = (res != null && res.GetType() == typeof(AutoItem));
                        url.SetResourceDependency(res);
                        switch (tagName)
                        {
                            case "firsturl": url.UrlCategory = PageUrlCategory.FirstPage; break;
                            case "preurl": url.UrlCategory = PageUrlCategory.PrePage; break;
                            case "nexturl": url.UrlCategory = PageUrlCategory.NextPage; break;
                            case "lasturl": url.UrlCategory = PageUrlCategory.LastPage; break;
                            case "cururl": url.UrlCategory = PageUrlCategory.ThisPage; break;
                            default:
                                url.UrlCategory = PageUrlCategory.ThisPage;
                                break;
                        }
                        tagList.Add(url);
                    }
                    else
                    {
                        SystemTag sys = new SystemTag(tag.OuterDefineText);
                        //Util.Debug(false, res.GetType().ToString());
                        sys.SetResourceDependency(res);
                        tagList.Add(sys);
                    }
                }
                else
                {
                    tagList.Add(tag);
                }
                //Util.Debug(false, "#####\n" + tag.OuterDefineText + "\n#####");
                //TagList.Add(tag);

                idxBegin = tag.DefinedIndexEnd;
                mc = regEx.Matches(tagdef, idxBegin);
            }

            if (idxBegin < tagdef.Length)
            {
                htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin));
                tagList.Add(htmlTag);
            }
        }
示例#32
0
文件: TagParse.cs 项目: vbyte/fmq
        /// <summary>
        /// 转换描述文本为表达式数组
        /// </summary>
        /// <remarks>
        /// a: {#$ TrimHTML(%Title%) $#}
        /// b: {#$ Repeat(5,%Title%) $#}
        /// c: {#$ Length(TrimHTML(%Title%)) $#}
        /// d: {#$ Length(TrimHTML(%Title%)) > 3 ? "太长" : "OK" $#}
        /// e: {#$ Replace(TrimHTML(%Title%), "电子"," ") $#}
        /// f: {#$ ReplaceX(TrimHTML(%Title%), "\w","") $#}
        /// </remarks>
        public static List<InnerExpression> GetInnerExpressions(string ExpPaper, IResourceDependency Res)
        {
            //OleDbHelper.AppendToFile("~/debug.txt", "\n\n 解析:" + ExpPaper);
            List<InnerExpression> expList = new List<InnerExpression>();

            int lenT = ExpPaper.Length;
            int cursor = 0, iflag = 0;
            char chr = ExpPaper[cursor];
            string strTemp = "", strExpression = "";
            ReservedWords words = null;

            while (cursor < lenT)
            {
                #region 字符扫描
                chr = ExpPaper[cursor];
                if (!ReservedWords.IsReservedChar(chr))
                {
                    ++cursor;
                    continue;
                }
                else
                {
                    if (cursor > iflag)
                    {
                        strTemp = ExpPaper.Substring(iflag, cursor - iflag).Trim();
                    }
                    iflag = cursor;

                    words = new ReservedWords(chr);
                    if (words.IsBraceChar())
                    {
                        #region 配对字符解析
                        ReservedWords.MoveToCharBrace(chr, ReservedWords.GetBraceChar(chr),
                                ref cursor, ref ExpPaper);

                        if (chr == '(')
                        {
                            //Function
                            strExpression = ExpPaper.Substring(iflag + 1, cursor - iflag - 1);
                            //OleDbHelper.AppendToFile("~/debug.txt", "\n 函数体:" + strExpression);
                            if (strTemp.Length == 0) strTemp = null;
                            expList.Add(new InnerExpression(strTemp, strExpression, Res));
                        }
                        else if (chr == '?')
                        {
                            strExpression = ExpPaper.Substring(iflag + 1, cursor - iflag - 1).Trim();
                            #region 跳出双引号里面的 : 操作符号
                            if (strExpression.IndexOf('"') != -1 && strExpression[0] != '"')
                            {
                                ReservedWords.MoveToCharBrace('"', '"', ref cursor, ref ExpPaper);
                                ReservedWords.MoveToCharBrace(ExpPaper[cursor], ':', ref cursor, ref ExpPaper);
                                strExpression = ExpPaper.Substring(iflag + 1, cursor - iflag - 1).Trim();
                            }
                            #endregion

                            #region 跳出单引号里面的 : 操作符号
                            if (strExpression.IndexOf('\'') != -1 && strExpression[0] != '\'')
                            {
                                ReservedWords.MoveToCharBrace('\'', '\'', ref cursor, ref ExpPaper);
                                ReservedWords.MoveToCharBrace(ExpPaper[cursor], ':', ref cursor, ref ExpPaper);
                                strExpression = ExpPaper.Substring(iflag + 1, cursor - iflag - 1).Trim();
                            }
                            #endregion

                            if (strTemp.Length > 0)
                            {
                                expList.Add(new InnerExpression(strTemp));
                            }
                            expList.Add(new InnerExpression("?"));
                            expList.Add(new InnerExpression(strExpression));
                            expList.Add(new InnerExpression(":"));

                            //Util.Debug(false, ExpPaper.Substring(cursor));
                        }
                        else if (chr == '[')
                        {
                            // {#$["首页","新闻","动态","联系"][2]$#}	= "动态"
                            #region 数组情况
                            if (cursor < lenT - 1)
                            {
                                char aIdx = ExpPaper[cursor + 1];
                                while (aIdx == '[')
                                {
                                    cursor++;
                                    ReservedWords.MoveToCharBrace(aIdx, ReservedWords.GetBraceChar(aIdx), ref cursor, ref ExpPaper);
                                    if (cursor < (lenT - 1))
                                    {
                                        aIdx = ExpPaper[cursor + 1];
                                    }
                                    else { break; }
                                }
                                strExpression = ExpPaper.Substring(iflag, cursor - iflag + 1);
                                expList.Add(new InnerExpression(strExpression, ',', Res));
                            }
                            else
                            {
                                #region 获取数组下标操作TODO
                                strExpression = ExpPaper.Substring(iflag, cursor - iflag + 1);
                                expList.Add(new InnerExpression(strExpression, Res));
                                #endregion
                            }
                            #endregion
                        }
                        else if (chr == '$')
                        {
                            #region 内置系统标签
                            strExpression = ExpPaper.Substring(iflag, cursor - iflag + 1);
                            SystemTag sysTag = new SystemTag(string.Concat("{#", strExpression, "#}"));
                            sysTag.SetResourceDependency(Res);
                            //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + string.Concat("{#", strExpression, "#}", "\n", sysTag.ToString()));
                            expList.Add(new InnerExpression(sysTag.ToString()));
                            #endregion
                        }
                        else if (chr == '"' || chr == '\'')
                        {
                            strExpression = ExpPaper.Substring(iflag, cursor - iflag + 1);
                            //Util.Debug(false, "Find String:" + strExpression);
                            expList.Add(new InnerExpression(strExpression));
                        }
                        #endregion

                        iflag = cursor + 1;
                    }
                    else if (words.IsOperator())
                    {
                        strExpression = strTemp;
                        if (strExpression.Length > 0)
                        {
                            InnerExpression exp = new InnerExpression(strExpression);
                            expList.Add(exp);
                        }

                        #region 处理操作符号

                    ParseOperator:

                        char chrNext = ExpPaper[cursor + 1];
                        if ((chr == '+' || chr == '-') && char.IsNumber(chrNext))
                        {
                            #region 正负号处理
                            ++cursor;
                            if (cursor < lenT)
                            {
                                ReservedWords.MoveToCharInRange(ref cursor, ref ExpPaper, ' ', '*', '/', '%', '+', '-', '>', '<', '=', '!', '&', '^', '|');
                                expList.Add(new InnerExpression(ExpPaper.Substring(iflag, cursor - iflag)));

                                #region 如遇操作符
                                if (cursor < lenT && ExpPaper[cursor] != ' ')
                                {
                                    iflag = cursor;
                                    chr = ExpPaper[cursor];
                                    //Util.Debug(false, "new char: = [" + chr.ToString() + "]");
                                    goto ParseOperator;
                                }
                                #endregion
                            }
                            #endregion
                        }
                        else
                        {
                            // *= += -= ++ -- <>
                            if (ReservedWords.IsCharInRange(chrNext, '=', '+', '-', '>'))
                            {
                                expList.Add(new InnerExpression(chr.ToString() + chrNext.ToString()));
                                ++cursor;
                            }
                            else
                            {
                                expList.Add(new InnerExpression(chr.ToString()));
                            }
                        }
                        #endregion

                        iflag = cursor + 1;
                    }
                    else
                    {
                        if (strTemp.Length > 0)
                        {
                            expList.Add(new InnerExpression(strTemp));
                        }
                        //Util.Debug(false, "11 - [" + strTemp.Trim() + "]" + "chr=[" + chr.ToString() + "]");
                    }
                }
                ++cursor;
                #endregion
            }

            if (iflag < cursor)
            {
                expList.Add(new InnerExpression(ExpPaper.Substring(iflag, cursor - iflag).Trim()));
            }

            //#region 解析结果查看
            //foreach (InnerExpression ext in expList)
            //{
            //    //Util.Debug(false, string.Concat("Exp定义:", ext.TagDefinition));
            //    OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + string.Concat("Exp定义:", ext.TagDefinition));
            //}
            //#endregion
            return expList;
        }