public static void GetLoading(string innerHtml, out string loading, out string template) { loading = string.Empty; template = string.Empty; if (string.IsNullOrEmpty(innerHtml)) { return; } var stlElementList = ParseUtils.GetStlElements(innerHtml); if (stlElementList.Count > 0) { foreach (var stlElement in stlElementList) { if (ParseUtils.IsSpecifiedStlElement(stlElement, StlLoading.ElementName)) { loading = ParseUtils.GetInnerHtml(stlElement); template = innerHtml.Replace(stlElement, string.Empty); } } } if (string.IsNullOrEmpty(loading) && string.IsNullOrEmpty(template)) { template = innerHtml; } loading = StringUtils.Trim(loading); template = StringUtils.Trim(template); }
public static void GetYesNo(string innerHtml, out string yes, out string no) { yes = string.Empty; no = string.Empty; if (string.IsNullOrEmpty(innerHtml)) { return; } var stlElementList = ParseUtils.GetStlElements(innerHtml); if (stlElementList.Count > 0) { foreach (var theStlElement in stlElementList) { if (ParseUtils.IsSpecifiedStlElement(theStlElement, StlYes.ElementName) || ParseUtils.IsSpecifiedStlElement(theStlElement, StlYes.ElementName2)) { yes = ParseUtils.GetInnerHtml(theStlElement); } else if (ParseUtils.IsSpecifiedStlElement(theStlElement, StlNo.ElementName) || ParseUtils.IsSpecifiedStlElement(theStlElement, StlNo.ElementName2)) { no = ParseUtils.GetInnerHtml(theStlElement); } } } if (string.IsNullOrEmpty(yes) && string.IsNullOrEmpty(no)) { yes = innerHtml; } yes = StringUtils.Trim(yes); no = StringUtils.Trim(no); }
public static async Task <ListInfo> GetListInfoAsync(IParseManager parseManager, ParseType contextType, Query query = null) { var contextInfo = parseManager.ContextInfo; var listInfo = new ListInfo { _contextType = contextType, DatabaseType = parseManager.SettingsManager.DatabaseType, ConnectionString = parseManager.SettingsManager.DatabaseConnectionString, Query = query }; var innerHtml = contextInfo.InnerHtml; var itemTemplate = string.Empty; if (!string.IsNullOrEmpty(innerHtml)) { var stlElementList = ParseUtils.GetStlElements(innerHtml); if (stlElementList.Count > 0) { foreach (var theStlElement in stlElementList) { if (ParseUtils.IsSpecifiedStlElement(theStlElement, StlItemTemplate.ElementName)) { var(templateString, attributes) = ParseUtils.GetInnerHtmlAndAttributes(theStlElement); if (!string.IsNullOrEmpty(templateString)) { foreach (var key in attributes.AllKeys) { if (!StringUtils.EqualsIgnoreCase(key, StlItemTemplate.Type)) { continue; } var type = attributes[key]; if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeItem)) { itemTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeHeader)) { listInfo.HeaderTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeFooter)) { listInfo.FooterTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeAlternatingItem)) { listInfo.AlternatingItemTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeSelectedItem)) { if (!string.IsNullOrEmpty(attributes[StlItemTemplate.Selected])) { var selected = attributes[StlItemTemplate.Selected]; var list = new List <string>(); if (selected.IndexOf(',') != -1) { list.AddRange(selected.Split(',')); } else { if (selected.IndexOf('-') != -1) { var first = TranslateUtils.ToInt(selected.Split('-')[0]); var second = TranslateUtils.ToInt(selected.Split('-')[1]); for (var i = first; i <= second; i++) { list.Add(i.ToString()); } } else { list.Add(selected); } } foreach (string val in list) { listInfo.SelectedItems.Set(val, templateString); } if (!string.IsNullOrEmpty(attributes[StlItemTemplate.SelectedValue])) { var selectedValue = attributes[StlItemTemplate.SelectedValue]; listInfo.SelectedValues.Set(selectedValue, templateString); } } } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeSeparator)) { var selectedValue = TranslateUtils.ToInt(attributes[StlItemTemplate.SelectedValue], 1); if (selectedValue <= 1) { listInfo.SeparatorTemplate = templateString; } else { listInfo.SeparatorRepeatTemplate = templateString; listInfo.SeparatorRepeat = selectedValue; } } } } innerHtml = innerHtml.Replace(theStlElement, string.Empty); } else if (ParseUtils.IsSpecifiedStlElement(theStlElement, StlLoading.ElementName)) { var innerBuilder = new StringBuilder(ParseUtils.GetInnerHtml(theStlElement)); await parseManager.ParseInnerContentAsync(innerBuilder); listInfo.LoadingTemplate = innerBuilder.ToString(); innerHtml = innerHtml.Replace(theStlElement, string.Empty); } else if (ParseUtils.IsSpecifiedStlElement(theStlElement, StlQuery.ElementName)) { if (listInfo.Query == null) { listInfo.Query = Q.NewQuery(); } await listInfo.Query.AddQueryAsync(parseManager, theStlElement); innerHtml = innerHtml.Replace(theStlElement, string.Empty); } else if (contextType == ParseType.SqlContent && ParseUtils.IsSpecifiedStlElement(theStlElement, StlQueryString.ElementName)) { var innerBuilder = new StringBuilder(ParseUtils.GetInnerHtml(theStlElement)); await parseManager.ParseInnerContentAsync(innerBuilder); listInfo.QueryString = innerBuilder.ToString(); innerHtml = innerHtml.Replace(theStlElement, string.Empty); } } } } if (string.IsNullOrEmpty(itemTemplate)) { listInfo.ItemTemplate = !string.IsNullOrEmpty(innerHtml) ? innerHtml : "<stl:a target=\"_blank\"></stl:a>"; } else { listInfo.ItemTemplate = itemTemplate; } var isSetDirection = false;//是否设置了direction属性 foreach (var name in contextInfo.Attributes.AllKeys) { var value = contextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, StlListBase.ChannelIndex) || StringUtils.EqualsIgnoreCase(name, StlListBase.Index)) { listInfo.ChannelIndex = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.ChannelName)) { listInfo.ChannelName = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Parent)) { listInfo.UpLevel = 1; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.UpLevel)) { listInfo.UpLevel = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.TopLevel)) { listInfo.TopLevel = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Scope)) { listInfo.Scope = TranslateUtils.ToEnum(value, ScopeType.Self); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsTop)) { listInfo.IsTop = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsRecommend)) { listInfo.IsRecommend = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsHot)) { listInfo.IsHot = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsColor)) { listInfo.IsColor = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.TotalNum)) { listInfo.TotalNum = TranslateUtils.ToInt(await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value)); } else if (StringUtils.EqualsIgnoreCase(name, StlPageContents.PageNum)) { listInfo.PageNum = TranslateUtils.ToInt(await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value), Constants.PageSize); } else if (StringUtils.EqualsIgnoreCase(name, StlPageContents.MaxPage)) { listInfo.MaxPage = TranslateUtils.ToInt(await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value)); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.StartNum)) { listInfo.StartNum = TranslateUtils.ToInt(await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value)); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Order)) { listInfo.Order = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Where)) { listInfo.Where = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Group)) { if (contextType == ParseType.Channel) { listInfo.GroupChannel = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupChannel)) { listInfo.GroupChannel = "__Empty__"; } } else if (contextType == ParseType.Content) { listInfo.GroupContent = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupContent)) { listInfo.GroupContent = "__Empty__"; } } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupNot)) { if (contextType == ParseType.Channel) { listInfo.GroupChannelNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupChannelNot)) { listInfo.GroupChannelNot = "__Empty__"; } } else if (contextType == ParseType.Content) { listInfo.GroupContentNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupContentNot)) { listInfo.GroupContentNot = "__Empty__"; } } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupChannel)) { listInfo.GroupChannel = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupChannel)) { listInfo.GroupChannel = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupChannelNot)) { listInfo.GroupChannelNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupChannelNot)) { listInfo.GroupChannelNot = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupContent)) { listInfo.GroupContent = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupContent)) { listInfo.GroupContent = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupContentNot)) { listInfo.GroupContentNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupContentNot)) { listInfo.GroupContentNot = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Tags)) { listInfo.Tags = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Columns)) { listInfo.Columns = TranslateUtils.ToInt(value); listInfo.Layout = ListLayout.Table; if (listInfo.Columns > 1 && isSetDirection == false) { listInfo.Direction = "horizontal"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Direction)) { listInfo.Layout = ListLayout.Table; listInfo.Direction = value; isSetDirection = true; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Align)) { listInfo.Align = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.ItemAlign)) { listInfo.ItemAlign = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.ItemVerticalAlign)) { listInfo.ItemVerticalAlign = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.ItemClass)) { listInfo.ItemClass = value; } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsImage)) { listInfo.IsImage = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsVideo)) { listInfo.IsVideo = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.IsFile)) { listInfo.IsFile = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlContents.IsRelatedContents)) { listInfo.IsRelatedContents = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Layout)) { listInfo.Layout = TranslateUtils.ToEnum(value, ListLayout.None); } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.DatabaseTypeName)) { var databaseType = parseManager.SettingsManager.Configuration[value]; if (!string.IsNullOrEmpty(databaseType)) { listInfo.DatabaseType = TranslateUtils.ToEnum(databaseType, DatabaseType.MySql); } } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.DatabaseType)) { listInfo.DatabaseType = TranslateUtils.ToEnum(value, DatabaseType.MySql); } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.ConnectionStringName)) { var connectionString = parseManager.SettingsManager.Configuration[value]; if (!string.IsNullOrEmpty(connectionString)) { listInfo.ConnectionString = connectionString; } } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.ConnectionString)) { listInfo.ConnectionString = value; } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.QueryString)) { listInfo.QueryString = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else { listInfo.Others.Set(name, value); } } return(listInfo); }