Esempio n. 1
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);
                }
            }
        }