Example #1
0
        /// <summary>
        /// 从文件缓存中构建模板文档对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="charset"></param>
        /// <param name="documentConfig"></param>
        /// <returns></returns>
        public static TemplateDocument FromFileCache(string fileName, Encoding charset, TemplateDocumentConfig documentConfig)
        {
            Cache cache = HttpRuntime.Cache;

            if (documentConfig == null)
            {
                documentConfig = TemplateDocumentConfig.Default;
            }

            //没有缓存则直接返回实例
            if (cache == null)
            {
                return(new TemplateDocument(fileName, charset, documentConfig));
            }
            fileName = Path.GetFullPath(fileName);

            string           cacheKey = string.Format("TEMPLATE_DOCUMENT_CACHE_ITEM_{0}_{1}_{2}", documentConfig.TagOpenMode, documentConfig.CompressText, fileName);
            TemplateDocument document = cache.Get(cacheKey) as TemplateDocument;

            if (document == null)
            {
                document = new TemplateDocument(fileName, charset, documentConfig);
                cache.Insert(cacheKey, document, new CacheDependency(document.FileDependencies));
            }
            //返回副本
            return(document.Clone());
        }
Example #2
0
        /// <summary>
        /// 克隆当前元素到新的宿主模板
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        internal override Element Clone(Template ownerTemplate)
        {
            TemplateDocument tag = new TemplateDocument(this.DocumentConfig);

            //优先拷贝变量
            foreach (Variable var in this.Variables)
            {
                tag.Variables.Add(var.Clone(tag));
            }

            tag.Id   = this.Id;
            tag.Name = this.Name;
            foreach (var att in this.Attributes)
            {
                tag.Attributes.Add(att.Clone(tag));
            }

            tag.Charset          = this.Charset;
            tag.File             = this.File;
            tag.fileDependencies = this.fileDependencies;
            tag.Visible          = this.Visible;

            foreach (Element element in this.InnerElements)
            {
                Element item = element.Clone(tag);
                tag.AppendChild(item);

                if (element is Template && this.DocumentElement == element)
                {
                    tag.DocumentElement = (Template)item;
                }
            }

            if (tag.DocumentElement == null)
            {
                tag.DocumentElement = tag;
            }
            return(tag);
        }
Example #3
0
 /// <summary>
 /// 注册当前呈现的标签
 /// </summary>
 /// <param name="tag"></param>
 internal void RegisterCurrentRenderingTag(Tag tag)
 {
     TemplateDocument.CurrentRenderingDocument = tag == null ? null : tag.OwnerDocument;
     this.CurrentRenderingTag = tag;
 }
        /// <summary>
        /// 克隆当前元素到新的宿主模板
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        internal override Element Clone(Template ownerTemplate)
        {
            TemplateDocument tag = new TemplateDocument(this.DocumentConfig);

            //优先拷贝变量
            foreach (Variable var in this.Variables)
            {
                tag.Variables.Add(var.Clone(tag));
            }

            tag.Id = this.Id;
            tag.Name = this.Name;
            foreach (var att in this.Attributes)
            {
                tag.Attributes.Add(att.Clone(tag));
            }

            tag.Charset = this.Charset;
            tag.File = this.File;
            tag.fileDependencies = this.fileDependencies;
            tag.Visible = this.Visible;

            foreach (Element element in this.InnerElements)
            {
                Element item = element.Clone(tag);
                tag.AppendChild(item);

                if (element is Template && this.DocumentElement == element) tag.DocumentElement = (Template)item;
            }

            if (tag.DocumentElement == null) tag.DocumentElement = tag;
            return tag;
        }
        /// <summary>
        /// 从文件缓存中构建模板文档对象
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="charset"></param>
        /// <param name="documentConfig"></param>
        /// <returns></returns>
        public static TemplateDocument FromFileCache(string fileName, Encoding charset, TemplateDocumentConfig documentConfig)
        {
            Cache cache = HttpRuntime.Cache;
            if (documentConfig == null) documentConfig = TemplateDocumentConfig.Default;

            //没有缓存则直接返回实例
            if (cache == null) return new TemplateDocument(fileName, charset, documentConfig);
            fileName = Path.GetFullPath(fileName);

            string cacheKey = string.Format("TEMPLATE_DOCUMENT_CACHE_ITEM_{0}_{1}_{2}", documentConfig.TagOpenMode, documentConfig.CompressText, fileName);
            TemplateDocument document = cache.Get(cacheKey) as TemplateDocument;
            if (document == null)
            {
                document = new TemplateDocument(fileName, charset, documentConfig);
                cache.Insert(cacheKey, document, new CacheDependency(document.FileDependencies));
            }
            //返回副本
            return document.Clone();
        }
 /// <summary>
 /// 注册当前呈现的标签
 /// </summary>
 /// <param name="tag"></param>
 internal void RegisterCurrentRenderingTag(Tag tag)
 {            
     TemplateDocument.CurrentRenderingDocument = tag == null ? null : tag.OwnerDocument;
     this.CurrentRenderingTag = tag;
 }