internal static string ParseStlElement(string stlElement, PageInfo pageInfo, ContextInfo contextInfo) { string parsedContent = null; var stlElementInfo = StlParserUtility.ParseStlElement(stlElement); if (stlElementInfo != null) { var elementName = stlElementInfo.Name; if (ElementsToTranslateDic.ContainsKey(elementName)) { Func <string, string> func; if (ElementsToTranslateDic.TryGetValue(elementName, out func)) { parsedContent = func(stlElement); } } else if (ElementsToParseDic.ContainsKey(elementName)) { if (stlElementInfo.IsDynamic) { parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo); } else { try { Func <PageInfo, ContextInfo, object> func; if (ElementsToParseDic.TryGetValue(elementName, out func)) { var contextInfoClone = contextInfo.Clone(stlElement, stlElementInfo.InnerHtml, stlElementInfo.Attributes); var obj = func(pageInfo, contextInfoClone); if (obj == null) { parsedContent = string.Empty; } else if (obj is string) { parsedContent = (string)obj; } else { parsedContent = TranslateUtils.JsonSerialize(obj); } } } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(elementName, stlElement, ex); } } } else { var parsers = PluginStlParserContentManager.GetParses(); if (parsers.ContainsKey(elementName)) { if (stlElementInfo.IsDynamic) { parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo); } else { try { Func <PluginParseContext, string> func; if (parsers.TryGetValue(elementName, out func)) { var context = new PluginParseContext(stlElementInfo.OuterHtml, stlElementInfo.InnerHtml, stlElementInfo.Attributes, pageInfo, contextInfo); parsedContent = func(context); } } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(elementName, stlElement, ex); } } } } } return(parsedContent ?? stlElement); }
internal static string ParseStlElement(string stlElement, PageInfo pageInfo, ContextInfo contextInfo) { string parsedContent = null; //var parsedContent = StlCacheManager.ParsedContent.GetParsedContent(stlElement, pageInfo, contextInfo); //if (parsedContent != null) return parsedContent; var xmlDocument = StlParserUtility.GetXmlDocument(stlElement, contextInfo.IsInnerElement); XmlNode node = xmlDocument.DocumentElement; if (node != null) { node = node.FirstChild; if (node?.Name != null) { var elementName = node.Name.ToLower(); if (ElementsToTranslateDic.ContainsKey(elementName)) { Func <string, string> func; if (ElementsToTranslateDic.TryGetValue(elementName, out func)) { parsedContent = func(stlElement); } } else if (ElementsToParseDic.ContainsKey(elementName)) { var isDynamic = false; var attributes = new Dictionary <string, string>(); var innerXml = StringUtils.Trim(node.InnerXml); var childNodes = node.ChildNodes; var ie = node.Attributes?.GetEnumerator(); if (ie != null) { while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; if (StringUtils.EqualsIgnoreCase(attr.Name, "isDynamic")) { isDynamic = TranslateUtils.ToBool(attr.Value, false); } else { var key = attr.Name; if (!string.IsNullOrEmpty(key)) { var value = attr.Value; if (string.IsNullOrEmpty(StringUtils.Trim(value))) { value = string.Empty; } attributes[key] = value; } } } } if (isDynamic) { parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo); } else { try { Func <PageInfo, ContextInfo, string> func; if (ElementsToParseDic.TryGetValue(elementName, out func)) { parsedContent = func(pageInfo, contextInfo.Clone(stlElement, attributes, innerXml, childNodes)); } } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(elementName, stlElement, ex); } } } else { var parsers = PluginStlParserContentManager.GetParses(); if (parsers.ContainsKey(elementName)) { var isDynamic = false; var attributes = new Dictionary <string, string>(); var innerXml = StringUtils.Trim(node.InnerXml); var ie = node.Attributes?.GetEnumerator(); if (ie != null) { while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; if (StringUtils.EqualsIgnoreCase(attr.Name, "isDynamic")) { isDynamic = TranslateUtils.ToBool(attr.Value, false); } else { var key = attr.Name; if (!string.IsNullOrEmpty(key)) { var value = attr.Value; if (string.IsNullOrEmpty(StringUtils.Trim(value))) { value = string.Empty; } attributes[key] = value; } } } } if (isDynamic) { parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo); } else { try { Func <PluginParseContext, string> func; if (parsers.TryGetValue(elementName, out func)) { var context = new PluginParseContext(attributes, innerXml, pageInfo, contextInfo); parsedContent = func(context); } } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(elementName, stlElement, ex); } } } } } } if (parsedContent == null) { parsedContent = stlElement; } else { parsedContent = contextInfo.IsInnerElement ? parsedContent : StlParserUtility.GetBackHtml(parsedContent, pageInfo); } //StlCacheManager.ParsedContent.SetParsedContent(stlElement, pageInfo, contextInfo, parsedContent); return(parsedContent); }