Ejemplo n.º 1
0
        /// <summary>
        /// Performs the render for a tags.
        /// </summary>
        /// <param name="writer">See the <see cref="System.IO.TextWriter"/>.</param>
        /// <param name="collection">The tags collection.</param>
        public virtual void Render(System.IO.TextWriter writer, ITag[] collection)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("\"writer\" cannot be null.");
            }

            if (collection != null && collection.Length > 0)
            {
                for (int i = 0; i < collection.Length; i++)
                {
                    try
                    {
                        var tagResult = TagExecutor.Execute(collection[i], this.Context);
                        if (tagResult != null)
                        {
                            writer.Write(tagResult.ToString());
                        }
                    }
                    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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 呈现内容
        /// </summary>
        /// <param name="writer">TextWriter</param>
        /// <param name="collection">Tags</param>
        public virtual async Task RenderAsync(System.IO.TextWriter writer, ITag[] collection)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("\"writer\" cannot be null.");
            }

            if (collection != null && collection.Length > 0)
            {
                for (int i = 0; i < collection.Length; i++)
                {
                    try
                    {
                        await collection[i].ParseAsync(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);
                    }
                }
            }
        }
Ejemplo n.º 3
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);
                    }
                }
            }
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }
Ejemplo n.º 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);
                    }
                }
            }
        }