示例#1
0
 /// <summary>
 /// 添加一个子标签
 /// </summary>
 /// <param name="node"></param>
 public void AddChild(Tag node)
 {
     if (node != null)
     {
         Children.Add(node);
     }
 }
示例#2
0
        /// <summary>
        /// 呈现内容
        /// </summary>
        /// <param name="writer">TextWriter</param>
        public virtual void Render(System.IO.TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            Tag[] collection;
            //缓存功能,待添加
            if (this._content == null)
            {
                writer.Write(this.TemplateContent);
                return;
            }

            if (!String.IsNullOrEmpty(this._content))
            {
                TemplateLexer lexer = new TemplateLexer(this._content);
                TemplateParser parser = new TemplateParser(lexer.Parse());
                collection = parser.ToArray();
            }
            else
            {
                collection = new Tag[0];
            }

            if (collection.Length > 0)
            {
                for (Int32 i = 0; i < collection.Length; i++)
                {
                    try
                    {
                        collection[i].Parse(this._context, writer);
                    }
                    catch (Exception.TemplateException e)
                    {
                        ThrowException(e, collection[i],writer);
                    }
                    catch (System.Exception e)
                    {
                        System.Exception baseException = e.GetBaseException();
                        Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException);
                        ThrowException(ex, collection[i], writer);
                    }
                }
            }
        }
示例#3
0
文件: Tag.cs 项目: webconfig/project
 /// <summary>
 /// 添加一个子标签
 /// </summary>
 /// <param name="node"></param>
 public void AddChild(Tag node)
 {
     //node.Parent = this;
     Children.Add(node);
 }
示例#4
0
 /// <summary>
 /// 异常处理
 /// </summary>
 /// <param name="e">异常信息</param>
 /// <param name="tag">影响标签</param>
 /// <param name="writer">TextWriter</param>
 private void ThrowException(Exception.TemplateException e, Tag tag, System.IO.TextWriter writer)
 {
     if (this._context.ThrowExceptions)
     {
         throw e;
     }
     else
     {
         this._context.AddError(e);
         writer.Write(tag.ToString());
     }
 }
示例#5
0
        /// <summary>
        /// 呈现内容
        /// </summary>
        /// <param name="writer">TextWriter</param>
        public virtual void Render(System.IO.TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("\"writer\" cannot be null.");
            }

            //缓存功能,待添加
            if (this._content == null)
            {
                return;
            }

            Tag[] collection = null;
            if (!String.IsNullOrEmpty(this._content))
            {
                Object value;
                if (Engine.Cache != null && !String.IsNullOrEmpty(this._key))
                {
                    if ((value = Engine.Cache.Get(this._key)) != null)
                    {
                        collection = (Tag[])value;
                    }
                    else
                    {
                        collection = ParseTag();
                        Engine.Cache.Set(this._key, collection);
                    }
                }
                else
                {
                    collection = ParseTag();
                }
            }
            else
            {
                collection = new Tag[0];
            }

            if (collection.Length > 0)
            {
                for (Int32 i = 0; i < collection.Length; i++)
                {
                    try
                    {
                        collection[i].Parse(this._context, writer);
                    }
                    catch (Exception.TemplateException e)
                    {
                        ThrowException(e, collection[i], writer);
                    }
                    catch (System.Exception e)
                    {
                        System.Exception baseException = e.GetBaseException();
                        Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException);
                        ThrowException(ex, collection[i], writer);
                    }
                }
            }
        }