public string TokenReplace(string template, ProcessTokenDelegate processTokenDelegate) { // Replace tokens MatchCollection matchCol = RegTokens.Matches(template); if (matchCol.Count > 0) { foreach (Match match in matchCol) { string token = match.Value.ToUpper(); template = template.Replace(token, processTokenDelegate(token)); } } return(template); }
public static Control ParseTemplate(string templatePath, string templateName, string templateError, bool isLogged, ProcessTokenDelegate processTokenDelegate) { Control templateControl; TemplateInfo templateInfo = GetTemplate(templatePath, templateName, true, isLogged); if (templateInfo != null) { templateControl = new Control(); List <Token> tokens = templateInfo.Tokens; if (tokens != null) { foreach (Token token in templateInfo.Tokens) { string tokenValue = token.Value; if (!string.IsNullOrEmpty(tokenValue)) { Control tokenControl = processTokenDelegate(tokenValue); if (tokenControl != null) { string[] properties = token.Properties; if (properties != null) { foreach (string property in properties) { tokenControl = SetProperty(tokenControl, property); } } templateControl.Controls.Add(tokenControl); } } } } } else { templateControl = new LiteralControl(string.Format(templateError, templateName)); } return(templateControl); }
public static Control ParseTemplate(string templatesPath, string templateName, ProcessTokenDelegate processTokenDelegate) { TemplateInfo templateInfo = GetTemplate(templatesPath, templateName); Control templateControl = new Control(); Control tokenControl; if (templateInfo != null) { string[] tokens = templateInfo.Content.Split(new char[]{'[',']'}); foreach (string token in tokens) { char splitter = (char)254; string[] tokenParts = token.Replace("::", splitter.ToString()).Split(new char[]{splitter}); if (tokenParts[0].Length > 0) { tokenControl = processTokenDelegate(tokenParts[0]); if (tokenControl != null) { if (tokenParts.Length > 1) { for (int i=1; i<tokenParts.Length; i++) { tokenControl = setProperty(tokenControl, tokenParts[i]); } } templateControl.Controls.Add(tokenControl); } } } } else { string _Message = Localization.GetString("TemplateError.Text", "~/DesktopModules/Store/App_LocalResources/Catalog.ascx"); tokenControl = new LiteralControl(string.Format(_Message, templatesPath + templateName)); templateControl.Controls.Add(tokenControl); } return templateControl; }