/// <summary> /// 将DIV标签转换为服务器控件 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string ConvertDivTagToControl(string input) { string result = string.Empty; string pattern = @"<we7design[^>]*class[^>]+we7control[^>]+data\s*=\s*\""(?<data>[^\""]*)\""[^>]*>([\s\S]*?)</we7design>"; //替换we7control result = Regex.Replace(input, pattern, delegate(Match m) { var data = m.Groups["data"].Value; data = Base64Helper.Decode(data); var dataDic = JsonConvert.DeserializeObject <Dictionary <string, object> >(data); string type = dataDic["ctr"].ToString(); dataDic.Remove("ctr"); return(BuildeWEC(type, dataDic)); }, RegexOptions.IgnoreCase); return(result); }
/// <summary> /// 将服务器控件包装 /// </summary> /// <param name="input"></param> /// <returns></returns> public static string ConvertControlToDiv(string input) { string result = string.Empty; string pattern = @"\<wec:\w+[^>]*\>(\s*)\</wec:\w+\>"; //替换we7control result = Regex.Replace(input, pattern, delegate(Match m) { //获取字符串 var control = m.Value; //获取属性 Dictionary <string, object> attributes = GetAttributes(control); attributes.Add("subtemplate", false); string data = JsonConvert.SerializeObject(attributes); data = Base64Helper.Encode(data); return(CreateUserControlWarp("we7controltempalte", data, control)); }, RegexOptions.IgnoreCase); return(result); }
public static string ConvertWEC(string input) { string tagPattern = @"</wec:(?<tagname>[^>]+)>"; string tag = Regex.Match(input, tagPattern, RegexOptions.IgnoreCase).Groups["tagname"].Value; string attrPattern = @"(?<attrname>\w+)\s*=\""(?<attrvalue>[^\""]*)\"""; MatchCollection attributes = Regex.Matches(input, attrPattern, RegexOptions.IgnoreCase); Dictionary <string, object> Parameters = new Dictionary <string, object>(); var type = ConvertName(tag); Parameters.Add("ctr", type); for (int i = 0; i < attributes.Count; i++) { if (attributes[i].Success) { var name = attributes[i].Groups["attrname"].Value; var value = attributes[i].Groups["attrvalue"].Value; if (name.Trim().ToLower() == "runat") { continue; } else { Parameters.Add(name.ToLower().Trim(), value); } } } string data = JsonConvert.SerializeObject(Parameters); data = Base64Helper.Encode(data); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("<we7design class=\"we7control\" data=\"{0}\">", data)); sb.AppendLine(input); sb.AppendLine("</we7design>"); return(sb.ToString()); }