/// <summary> /// 克隆当前元素到新的宿主模板 /// </summary> /// <param name="ownerTemplate"></param> /// <returns></returns> internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate) { DMEWeb_TemplateDocument tag = new DMEWeb_TemplateDocument(this.DocumentConfig); //优先拷贝变量 foreach (DMEWeb_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 (DMEWeb_Element element in this.InnerElements) { DMEWeb_Element item = element.Clone(tag); tag.AppendChild(item); if (element is DMEWeb_Template && this.DocumentElement == element) tag.DocumentElement = (DMEWeb_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 DMEWeb_TemplateDocument FromFileCache(string fileName, Encoding charset, DMEWeb_TemplateDocumentConfig documentConfig) { Cache cache = HttpRuntime.Cache; if (documentConfig == null) documentConfig = DMEWeb_TemplateDocumentConfig.Default; //没有缓存则直接返回实例 if (cache == null) return new DMEWeb_TemplateDocument(fileName, charset, documentConfig); fileName = Path.GetFullPath(fileName); string cacheKey = string.Format("TEMPLATE_DOCUMENT_CACHE_ITEM_{0}_{1}_{2}", documentConfig.TagOpenMode, documentConfig.CompressText, fileName); DMEWeb_TemplateDocument document = cache.Get(cacheKey) as DMEWeb_TemplateDocument; if (document == null) { document = new DMEWeb_TemplateDocument(fileName, charset, documentConfig); cache.Insert(cacheKey, document, new CacheDependency(document.FileDependencies)); } //返回副本 return document.Clone(); }