public void RblOperation_SelectedIndexChanged(object sender, EventArgs e) { var after = (EContentAddAfter)TranslateUtils.ToEnum(typeof(EContentAddAfter), RblOperation.SelectedValue, EContentAddAfter.ContinueAdd); if (after == EContentAddAfter.ContinueAdd) { PageUtils.Redirect(WebUtils.GetContentAddAddUrl(SiteId, _channelInfo.Id, AuthRequest.GetQueryString("ReturnUrl"))); return; } if (after == EContentAddAfter.ManageContents) { PageUtils.Redirect(_returnUrl); return; } if (after == EContentAddAfter.Contribute) { CrossSiteTransUtility.LoadSiteIdDropDownList(DdlSiteId, SiteInfo, _channelInfo.Id); if (DdlSiteId.Items.Count > 0) { DdlSiteId_SelectedIndexChanged(sender, e); } PhSiteId.Visible = PhSubmit.Visible = true; } }
internal static async Task <object> ParseAsync(IParseManager parseManager) { var testTypeStr = string.Empty; var testOperate = string.Empty; var testValue = string.Empty; var onBeforeSend = string.Empty; var onSuccess = string.Empty; var onComplete = string.Empty; var onError = string.Empty; foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, Type) || StringUtils.EqualsIgnoreCase(name, "testType")) { testTypeStr = value; } else if (StringUtils.EqualsIgnoreCase(name, Op) || StringUtils.EqualsIgnoreCase(name, "operate") || StringUtils.EqualsIgnoreCase(name, "testOperate")) { testOperate = value; } else if (StringUtils.EqualsIgnoreCase(name, Value) || StringUtils.EqualsIgnoreCase(name, "testValue")) { testValue = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(testOperate)) { testOperate = OperateEquals; } } else if (StringUtils.EqualsIgnoreCase(name, Context)) { parseManager.ContextInfo.ContextType = TranslateUtils.ToEnum(value, ParseType.Undefined); } else if (StringUtils.EqualsIgnoreCase(name, OnBeforeSend)) { onBeforeSend = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnSuccess)) { onSuccess = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnComplete)) { onComplete = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnError)) { onError = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } } if (string.IsNullOrEmpty(testOperate)) { testOperate = OperateNotEmpty; } return(await ParseImplAsync(parseManager, testTypeStr, testOperate, testValue, onBeforeSend, onSuccess, onComplete, onError)); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var tagLevel = 1; var totalNum = 0; var isOrderByCount = false; foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, TagLevel)) { tagLevel = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, TotalNum)) { totalNum = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, IsOrderByCount)) { isOrderByCount = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, Context)) { parseManager.ContextInfo.ContextType = TranslateUtils.ToEnum(value, parseManager.ContextInfo.ContextType); } } return(await ParseImplAsync(parseManager, tagLevel, totalNum, isOrderByCount)); }
public static bool IsEnvironment(string envSecurityKey, string envDatabaseType, string envDatabaseConnectionString, string envDatabaseHost, string envDatabaseUser, string envDatabasePassword, string envDatabaseName) { if (string.IsNullOrEmpty(envSecurityKey) || string.IsNullOrEmpty(envDatabaseType)) { return(false); } bool isEnvironment; var databaseType = TranslateUtils.ToEnum(envDatabaseType, DatabaseType.MySql); if (databaseType == DatabaseType.SQLite) { isEnvironment = true; } else if (!string.IsNullOrEmpty(envDatabaseConnectionString)) { isEnvironment = true; } else { isEnvironment = !string.IsNullOrEmpty(envDatabaseHost) && !string.IsNullOrEmpty(envDatabaseUser) && !string.IsNullOrEmpty(envDatabasePassword) && !string.IsNullOrEmpty(envDatabaseName); } return(isEnvironment); }
public async Task <ActionResult <DeleteResult> > Delete([FromBody] DeleteRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, AdvertisementUtils.PermissionsList)) { return(Unauthorized()); } await _advertisementRepository.DeleteAsync(request.SiteId, request.AdvertisementId); var advertisements = string.IsNullOrEmpty(request.AdvertisementType) ? await _advertisementRepository.GetAllAsync(request.SiteId) : await _advertisementRepository.GetAllAsync(request.SiteId, TranslateUtils.ToEnum(request.AdvertisementType, AdvertisementType.FloatImage)); foreach (var advertisement in advertisements) { advertisement.Set("display", await GetDisplayAsync(request.SiteId, advertisement)); advertisement.Set("scope", advertisement.ScopeType.GetDisplayName()); advertisement.Set("type", advertisement.AdvertisementType.GetDisplayName()); } return(new DeleteResult { Advertisements = advertisements }); }
internal static async Task <object> ParseAsync(IParseManager parseManager) { var contextInfo = parseManager.ContextInfo; // 如果是实体标签则返回空 if (contextInfo.IsStlEntity) { return(string.Empty); } var inline = false; var onBeforeSend = string.Empty; var onSuccess = string.Empty; var onComplete = string.Empty; var onError = string.Empty; foreach (var name in contextInfo.Attributes.AllKeys) { var value = contextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, Context)) { contextInfo.ContextType = TranslateUtils.ToEnum(value, ParseType.Undefined); } else if (StringUtils.EqualsIgnoreCase(name, Inline)) { inline = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, OnBeforeSend)) { onBeforeSend = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnSuccess)) { onSuccess = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnComplete)) { onComplete = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, OnError)) { onError = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } } StlParserUtility.GetLoading(contextInfo.InnerHtml, out var loading, out var template); if (!string.IsNullOrEmpty(loading)) { var innerBuilder = new StringBuilder(loading); await parseManager.ParseInnerContentAsync(innerBuilder); loading = innerBuilder.ToString(); } return(await ParseAsync(parseManager, contextInfo.Site, loading, template, inline, onBeforeSend, onSuccess, onComplete, onError)); }
public async Task PullMenuAsync(string accessTokenOrAppId, int siteId) { var result = CommonApi.GetMenu(accessTokenOrAppId); if (result == null) { return; } await _wxMenuRepository.DeleteAllAsync(siteId); var json = result.menu.button.ToJson(); var buttons = TranslateUtils.JsonDeserialize <List <MenuFull_RootButton> >(json); var firstTaxis = 1; foreach (var button in buttons) { var first = new WxMenu { SiteId = siteId, ParentId = 0, Taxis = firstTaxis++, Text = button.name, MenuType = TranslateUtils.ToEnum(button.type, WxMenuType.View), Key = button.key, Url = button.url, AppId = button.appid, PagePath = button.pagepath, MediaId = button.media_id }; var menuId = await _wxMenuRepository.InsertAsync(first); if (button.sub_button != null && button.sub_button.Count > 0) { var childTaxis = 1; foreach (var sub in button.sub_button) { var child = new WxMenu { SiteId = siteId, ParentId = menuId, Taxis = childTaxis++, Text = sub.name, MenuType = TranslateUtils.ToEnum(sub.type, WxMenuType.View), Key = sub.key, Url = sub.url, AppId = sub.appid, PagePath = sub.pagepath, MediaId = sub.media_id }; await _wxMenuRepository.InsertAsync(child); } } } }
public async Task ImportChannelAsync(Channel channel, ScopedElementCollection additionalElements, int parentId, IList indexNameList) { channel.LoadExtend(AtomUtility.GetDcElementContent(additionalElements, "ExtendValues")); channel.ChannelName = AtomUtility.GetDcElementContent(additionalElements, new List <string> { nameof(Channel.ChannelName), "NodeName" }); channel.SiteId = _site.Id; var contentModelPluginId = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.ContentModelPluginId)); if (!string.IsNullOrEmpty(contentModelPluginId)) { channel.ContentModelPluginId = contentModelPluginId; } channel.ParentId = parentId; var indexName = AtomUtility.GetDcElementContent(additionalElements, new List <string> { nameof(Channel.IndexName), "NodeIndexName" }); if (!string.IsNullOrEmpty(indexName) && indexNameList.IndexOf(indexName) == -1) { channel.IndexName = indexName; indexNameList.Add(indexName); } channel.GroupNames = ListUtils.GetStringList(AtomUtility.GetDcElementContent(additionalElements, new List <string> { nameof(Channel.GroupNames), "NodeGroupNameCollection" })); channel.AddDate = DateTime.Now; channel.ImageUrl = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.ImageUrl)); channel.Content = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.Content))); channel.FilePath = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.FilePath)); channel.ChannelFilePathRule = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.ChannelFilePathRule)); channel.ContentFilePathRule = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.ContentFilePathRule)); channel.LinkUrl = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.LinkUrl)); channel.LinkType = TranslateUtils.ToEnum(AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.LinkType)), LinkType.None); var channelTemplateName = AtomUtility.GetDcElementContent(additionalElements, ChannelTemplateName); if (!string.IsNullOrEmpty(channelTemplateName)) { channel.ChannelTemplateId = await _databaseManager.TemplateRepository.GetTemplateIdByTemplateNameAsync(_site.Id, TemplateType.ChannelTemplate, channelTemplateName); } var contentTemplateName = AtomUtility.GetDcElementContent(additionalElements, ContentTemplateName); if (!string.IsNullOrEmpty(contentTemplateName)) { channel.ContentTemplateId = await _databaseManager.TemplateRepository.GetTemplateIdByTemplateNameAsync(_site.Id, TemplateType.ContentTemplate, contentTemplateName); } channel.Keywords = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.Keywords)); channel.Description = AtomUtility.GetDcElementContent(additionalElements, nameof(Channel.Description)); }
public void Reload() { var envSecurityKey = GetEnvironmentVariable(EnvSecurityKey); var envDatabaseType = GetEnvironmentVariable(EnvDatabaseType); var envDatabaseHost = GetEnvironmentVariable(EnvDatabaseHost); var envDatabasePort = GetEnvironmentVariable(EnvDatabasePort); var envDatabaseUser = GetEnvironmentVariable(EnvDatabaseUser); var envDatabasePassword = GetEnvironmentVariable(EnvDatabasePassword); var envDatabaseName = GetEnvironmentVariable(EnvDatabaseName); var envDatabaseConnectionString = GetEnvironmentVariable(EnvDatabaseConnectionString); var envRedisConnectionString = GetEnvironmentVariable(EnvRedisConnectionString); var isEnvironment = IsEnvironment(envSecurityKey, envDatabaseType, envDatabaseConnectionString, envDatabaseHost, envDatabaseUser, envDatabasePassword, envDatabaseName); if (isEnvironment) { IsProtectData = false; SecurityKey = envSecurityKey; DatabaseType = TranslateUtils.ToEnum(envDatabaseType, DatabaseType.MySql); DatabaseConnectionString = DatabaseType == DatabaseType.SQLite ? $"Data Source={Constants.LocalDbContainerVirtualPath};Version=3;" : envDatabaseConnectionString; RedisConnectionString = envRedisConnectionString; if (string.IsNullOrEmpty(DatabaseConnectionString)) { var port = TranslateUtils.ToInt(envDatabasePort); DatabaseConnectionString = InstallUtils.GetDatabaseConnectionString(DatabaseType, envDatabaseHost, port == 0, port, envDatabaseUser, envDatabasePassword, envDatabaseName); } } else { IsProtectData = _config.GetValue(nameof(IsProtectData), false); SecurityKey = _config.GetValue <string>(nameof(SecurityKey)); DatabaseType = TranslateUtils.ToEnum( IsProtectData ? Decrypt(_config.GetValue <string>("Database:Type")) : _config.GetValue <string>("Database:Type"), DatabaseType.MySql); DatabaseConnectionString = DatabaseType == DatabaseType.SQLite ? $"Data Source={Constants.LocalDbHostVirtualPath};Version=3;" : IsProtectData ? Decrypt(_config.GetValue <string>("Database:ConnectionString")) : _config.GetValue <string>("Database:ConnectionString"); RedisConnectionString = IsProtectData ? Decrypt(_config.GetValue <string>("Redis:ConnectionString")) : _config.GetValue <string>("Redis:ConnectionString"); } }
//对“翻页项容器”(stl:pageItems)元素进行解析,此元素在生成页面时单独解析,不包含在ParseStlElement方法中。 public static async Task <string> ParseAsync(IParseManager parseManager, string stlElement, int channelId, int contentId, int currentPageIndex, int pageCount, int totalNum, ParseType contextType) { var pageInfo = parseManager.PageInfo; await pageInfo.AddPageHeadCodeIfNotExistsAsync(ParsePage.Const.Jquery); string parsedContent; try { var stlElementInfo = StlParserUtility.ParseStlElement(stlElement); if (stlElementInfo.Attributes[Context] != null) { contextType = TranslateUtils.ToEnum(stlElementInfo.Attributes[Context], ParseType.Undefined); } if (pageCount <= 1) { return(string.Empty); } bool isXmlContent; var index = stlElement.IndexOf(">", StringComparison.Ordinal) + 1; var length = stlElement.LastIndexOf("<", StringComparison.Ordinal) - index; if (index <= 0 || length <= 0) { stlElement = stlElementInfo.InnerHtml; isXmlContent = true; } else { stlElement = stlElement.Substring(index, length); isXmlContent = false; } parsedContent = await parseManager.ParseStlPageItemsAsync(stlElement, channelId, contentId, currentPageIndex, pageCount, totalNum, isXmlContent, contextType); var innerBuilder = new StringBuilder(parsedContent); await parseManager.ParseInnerContentAsync(innerBuilder); parsedContent = innerBuilder.ToString(); } catch (Exception ex) { parsedContent = await parseManager.AddStlErrorLogAsync(ElementName, stlElement, ex); } return(parsedContent); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var type = string.Empty; var channelIndex = string.Empty; var channelName = string.Empty; var upLevel = 0; var topLevel = -1; var scope = ScopeType.Self; var since = string.Empty; foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, Type)) { type = value; } else if (StringUtils.EqualsIgnoreCase(name, ChannelIndex) || StringUtils.EqualsIgnoreCase(name, Index)) { channelIndex = value; } else if (StringUtils.EqualsIgnoreCase(name, ChannelName)) { channelName = value; } else if (StringUtils.EqualsIgnoreCase(name, UpLevel)) { upLevel = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, TopLevel)) { topLevel = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, Scope)) { scope = TranslateUtils.ToEnum(value, ScopeType.Self); } else if (StringUtils.EqualsIgnoreCase(name, Since)) { since = value; } } return(await ParseAsync(parseManager, type, channelIndex, channelName, upLevel, topLevel, scope, since)); }
public void Operation_SelectedIndexChanged(object sender, EventArgs e) { var after = (EContentAddAfter)TranslateUtils.ToEnum(typeof(EContentAddAfter), Operation.SelectedValue, EContentAddAfter.ContinueAdd); if (after == EContentAddAfter.ContinueAdd) { PageUtils.Redirect(WebUtils.GetContentAddAddUrl(PublishmentSystemId, _nodeInfo, Body.GetQueryString("ReturnUrl"))); } else if (after == EContentAddAfter.ManageContents) { PageUtils.Redirect(_returnUrl); } else if (after == EContentAddAfter.Contribute) { CrossSiteTransUtility.LoadPublishmentSystemIDDropDownList(PublishmentSystemIDDropDownList, PublishmentSystemInfo, _nodeInfo.NodeId); if (PublishmentSystemIDDropDownList.Items.Count > 0) { PublishmentSystemID_SelectedIndexChanged(sender, e); } phPublishmentSystemID.Visible = phSubmit.Visible = true; } }
public void Operation_SelectedIndexChanged(object sender, EventArgs e) { var after = (EContentAddAfter)TranslateUtils.ToEnum(typeof(EContentAddAfter), Operation.SelectedValue, EContentAddAfter.ContinueAdd); if (after == EContentAddAfter.ContinueAdd) { PageUtils.Redirect(PageGovPublicContentAdd.GetRedirectUrlOfAdd(PublishmentSystemId, nodeInfo.NodeId, Request.QueryString["ReturnUrl"])); } else if (after == EContentAddAfter.ManageContents) { PageUtils.Redirect(returnUrl); } else if (after == EContentAddAfter.Contribute) { CrossSiteTransUtility.LoadPublishmentSystemIDDropDownList(PublishmentSystemIDDropDownList, PublishmentSystemInfo, nodeInfo.NodeId); if (PublishmentSystemIDDropDownList.Items.Count > 0) { PublishmentSystemID_SelectedIndexChanged(sender, e); } PublishmentSystemIDRow.Visible = NodeIDDropDownListRow.Visible = Submit.Visible = true; } }
public async Task <(bool success, string errorMessage)> ValidateStateAsync(User user) { if (!user.Checked) { return(false, "此账号未审核,无法登录"); } if (user.Locked) { return(false, "此账号被锁定,无法登录"); } var config = await _configRepository.GetAsync(); if (config.IsUserLockLogin) { if (user.CountOfFailedLogin > 0 && user.CountOfFailedLogin >= config.UserLockLoginCount) { var lockType = TranslateUtils.ToEnum(config.UserLockLoginType, LockType.Hours); if (lockType == LockType.Forever) { return(false, "此账号错误登录次数过多,已被永久锁定"); } if (lockType == LockType.Hours && user.LastActivityDate.HasValue) { var ts = new TimeSpan(DateTime.Now.Ticks - user.LastActivityDate.Value.Ticks); var hours = Convert.ToInt32(config.UserLockLoginHours - ts.TotalHours); if (hours > 0) { return(false, $"此账号错误登录次数过多,已被锁定,请等待{hours}小时后重试"); } } } } return(true, null); }
public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, AdvertisementUtils.PermissionsList)) { return(Unauthorized()); } var types = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(string.Empty, "<所有类型>"), new KeyValuePair <string, string>(AdvertisementType.FloatImage.GetValue(), AdvertisementType.FloatImage.GetDisplayName()), new KeyValuePair <string, string>(AdvertisementType.ScreenDown.GetValue(), AdvertisementType.ScreenDown.GetDisplayName()), new KeyValuePair <string, string>(AdvertisementType.OpenWindow.GetValue(), AdvertisementType.OpenWindow.GetDisplayName()) }; var advertisements = string.IsNullOrEmpty(request.AdvertisementType) ? await _advertisementRepository.GetAllAsync(request.SiteId) : await _advertisementRepository.GetAllAsync(request.SiteId, TranslateUtils.ToEnum(request.AdvertisementType, AdvertisementType.FloatImage)); foreach (var advertisement in advertisements) { advertisement.Set("display", await GetDisplayAsync(request.SiteId, advertisement)); advertisement.Set("scope", advertisement.ScopeType.GetDisplayName()); advertisement.Set("type", advertisement.AdvertisementType.GetDisplayName()); } return(new GetResult { Advertisements = advertisements, Types = types }); }
public static async Task <object> ParseAsync(IParseManager parseManager) { // 如果是实体标签则返回空 if (parseManager.ContextInfo.IsStlEntity) { return(string.Empty); } var channelIndex = string.Empty; var channelName = string.Empty; var scopeType = ScopeType.Self; var groupChannel = string.Empty; var groupChannelNot = string.Empty; var groupContent = string.Empty; var groupContentNot = string.Empty; var tags = string.Empty; var orderByString = parseManager.DatabaseManager.GetContentOrderByString(TaxisType.OrderByTaxisDesc); var startNum = 1; var totalNum = 0; var isShowText = true; var isTopText = string.Empty; var titleWordNum = 0; var isTop = false; var isTopExists = false; var isRecommend = false; var isRecommendExists = false; var isHot = false; var isHotExists = false; var isColor = false; var isColorExists = false; var theme = string.Empty; var imageWidth = 260; var imageHeight = 182; var textHeight = 25; var bgColor = string.Empty; var attributes = new NameValueCollection(); foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, AttributeChannelIndex) || StringUtils.EqualsIgnoreCase(name, AttributeIndex)) { channelIndex = value; } else if (StringUtils.EqualsIgnoreCase(name, AttributeChannelName)) { channelName = value; } else if (StringUtils.EqualsIgnoreCase(name, AttributeScope)) { scopeType = TranslateUtils.ToEnum(value, ScopeType.Self); } else if (StringUtils.EqualsIgnoreCase(name, AttributeGroupChannel)) { groupChannel = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeGroupChannelNot)) { groupChannelNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeGroupContent)) { groupContent = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeGroupContentNot)) { groupContentNot = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTags)) { tags = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeOrder)) { var dataManager = new StlDataManager(parseManager.DatabaseManager); orderByString = dataManager.GetContentOrderByString(parseManager.PageInfo.SiteId, value, TaxisType.OrderByTaxisDesc); } else if (StringUtils.EqualsIgnoreCase(name, AttributeStartNum)) { startNum = TranslateUtils.ToInt(value, 1); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTotalNum)) { totalNum = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTitleWordNum)) { titleWordNum = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsTop)) { isTopExists = true; isTop = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsRecommend)) { isRecommendExists = true; isRecommend = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsHot)) { isHotExists = true; isHot = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsColor)) { isColorExists = true; isColor = TranslateUtils.ToBool(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeTheme)) { theme = value; } else if (StringUtils.EqualsIgnoreCase(name, AttributeWidth)) { if (StringUtils.EndsWithIgnoreCase(value, "px")) { value = value.Substring(0, value.Length - 2); } imageWidth = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeHeight)) { if (StringUtils.EndsWithIgnoreCase(value, "px")) { value = value.Substring(0, value.Length - 2); } imageHeight = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, AttributeBgColor)) { bgColor = value; } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsShowText)) { isShowText = TranslateUtils.ToBool(value, true); } else if (StringUtils.EqualsIgnoreCase(name, AttributeIsTopText)) { isTopText = value; } else { attributes[name] = value; } } return(await ParseAsync(parseManager, attributes, channelIndex, channelName, scopeType, groupChannel, groupChannelNot, groupContent, groupContentNot, tags, orderByString, startNum, totalNum, isShowText, isTopText, titleWordNum, isTop, isTopExists, isRecommend, isRecommendExists, isHot, isHotExists, isColor, isColorExists, theme, imageWidth, imageHeight, textHeight, bgColor)); }
public static RepeatLayout ToRepeatLayout(string typeStr) { return((RepeatLayout)TranslateUtils.ToEnum(typeof(RepeatLayout), typeStr, RepeatLayout.Table)); }
public static RepeatDirection ToRepeatDirection(string typeStr) { return((RepeatDirection)TranslateUtils.ToEnum(typeof(RepeatDirection), typeStr, RepeatDirection.Vertical)); }
public static GridLines ToGridLines(string typeStr) { return((GridLines)TranslateUtils.ToEnum(typeof(GridLines), typeStr, GridLines.None)); }
public static VerticalAlign ToVerticalAlign(string typeStr) { return((VerticalAlign)TranslateUtils.ToEnum(typeof(VerticalAlign), typeStr, VerticalAlign.Middle)); }
public static HorizontalAlign ToHorizontalAlign(string typeStr) { return((HorizontalAlign)TranslateUtils.ToEnum(typeof(HorizontalAlign), typeStr, HorizontalAlign.Left)); }
public static async Task <ListInfo> GetListInfoAsync(IParseManager parseManager, ParseType contextType) { var contextInfo = parseManager.ContextInfo; var listInfo = new ListInfo { _contextType = contextType, DatabaseType = parseManager.SettingsManager.DatabaseType, ConnectionString = parseManager.SettingsManager.DatabaseConnectionString }; var innerHtml = contextInfo.InnerHtml; var itemTemplate = string.Empty; if (!string.IsNullOrEmpty(innerHtml)) { var stlElementList = StlParserUtility.GetStlElementList(innerHtml); if (stlElementList.Count > 0) { foreach (var theStlElement in stlElementList) { if (StlParserUtility.IsSpecifiedStlElement(theStlElement, StlItemTemplate.ElementName)) { var attributes = TranslateUtils.NewIgnoreCaseNameValueCollection(); var templateString = StlParserUtility.GetInnerHtml(theStlElement, attributes); 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 (StlParserUtility.IsSpecifiedStlElement(theStlElement, StlLoading.ElementName)) { var innerBuilder = new StringBuilder(StlParserUtility.GetInnerHtml(theStlElement)); await parseManager.ParseInnerContentAsync(innerBuilder); listInfo.LoadingTemplate = innerBuilder.ToString(); innerHtml = innerHtml.Replace(theStlElement, string.Empty); } else if (contextType == ParseType.SqlContent && StlParserUtility.IsSpecifiedStlElement(theStlElement, StlQueryString.ElementName)) { var innerBuilder = new StringBuilder(StlParserUtility.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)) { 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.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) || StringUtils.EqualsIgnoreCase(name, "group")) { listInfo.GroupContent = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (string.IsNullOrEmpty(listInfo.GroupContent)) { listInfo.GroupContent = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.GroupContentNot) || StringUtils.EqualsIgnoreCase(name, "groupNot")) { 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 = Layout.Table; if (listInfo.Columns > 1 && isSetDirection == false) { listInfo.Direction = "horizontal"; } } else if (StringUtils.EqualsIgnoreCase(name, StlListBase.Direction)) { listInfo.Layout = Layout.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, Layout.None); } else if (contextType == ParseType.SqlContent && StringUtils.EqualsIgnoreCase(name, StlSqlContents.DatabaseTypeName)) { var databaseType = parseManager.SettingsManager.Configuration[name]; 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[name]; 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); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var isGetPicUrlFromAttribute = false; var channelIndex = string.Empty; var channelName = string.Empty; var upLevel = 0; var topLevel = -1; var type = nameof(Content.ImageUrl); var no = 0; var isClearTags = false; var isOriginal = false; var src = string.Empty; var altSrc = string.Empty; var attributes = new NameValueCollection(); foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, ChannelIndex) || StringUtils.EqualsIgnoreCase(name, Index)) { channelIndex = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (!string.IsNullOrEmpty(channelIndex)) { isGetPicUrlFromAttribute = true; } } else if (StringUtils.EqualsIgnoreCase(name, ChannelName)) { channelName = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (!string.IsNullOrEmpty(channelName)) { isGetPicUrlFromAttribute = true; } } else if (StringUtils.EqualsIgnoreCase(name, Parent)) { if (TranslateUtils.ToBool(value)) { upLevel = 1; isGetPicUrlFromAttribute = true; } } else if (StringUtils.EqualsIgnoreCase(name, UpLevel)) { upLevel = TranslateUtils.ToInt(value); if (upLevel > 0) { isGetPicUrlFromAttribute = true; } } else if (StringUtils.EqualsIgnoreCase(name, TopLevel)) { topLevel = TranslateUtils.ToInt(value); if (topLevel >= 0) { isGetPicUrlFromAttribute = true; } } else if (StringUtils.EqualsIgnoreCase(name, Context)) { parseManager.ContextInfo.ContextType = TranslateUtils.ToEnum(value, ParseType.Undefined); } else if (StringUtils.EqualsIgnoreCase(name, Type)) { type = value; } else if (StringUtils.EqualsIgnoreCase(name, No)) { no = TranslateUtils.ToInt(value); } else if (StringUtils.EqualsIgnoreCase(name, IsClearTags)) { isClearTags = TranslateUtils.ToBool(value, true); } else if (StringUtils.EqualsIgnoreCase(name, IsOriginal)) { isOriginal = TranslateUtils.ToBool(value, true); } else if (StringUtils.EqualsIgnoreCase(name, Src)) { src = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, AltSrc)) { altSrc = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else { attributes[name] = value; } } return(await ParseAsync(parseManager, attributes, isGetPicUrlFromAttribute, channelIndex, channelName, upLevel, topLevel, type, no, isOriginal, isClearTags, src, altSrc)); }
public static async Task <object> ParseAsync(IParseManager parseManager) { var attributes = new Dictionary <string, string>(); var channelIndex = string.Empty; var channelName = string.Empty; var upLevel = 0; var topLevel = -1; const bool removeTarget = false; var href = string.Empty; var queryString = string.Empty; var host = string.Empty; foreach (var name in parseManager.ContextInfo.Attributes.AllKeys) { var value = parseManager.ContextInfo.Attributes[name]; if (StringUtils.EqualsIgnoreCase(name, ChannelIndex) || StringUtils.EqualsIgnoreCase(name, Index)) { channelIndex = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (!string.IsNullOrEmpty(channelIndex)) { parseManager.ContextInfo.ContextType = ParseType.Channel; } } else if (StringUtils.EqualsIgnoreCase(name, ChannelName)) { channelName = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); if (!string.IsNullOrEmpty(channelName)) { parseManager.ContextInfo.ContextType = ParseType.Channel; } } else if (StringUtils.EqualsIgnoreCase(name, Parent)) { if (TranslateUtils.ToBool(value)) { upLevel = 1; parseManager.ContextInfo.ContextType = ParseType.Channel; } } else if (StringUtils.EqualsIgnoreCase(name, UpLevel)) { upLevel = TranslateUtils.ToInt(value); if (upLevel > 0) { parseManager.ContextInfo.ContextType = ParseType.Channel; } } else if (StringUtils.EqualsIgnoreCase(name, TopLevel)) { topLevel = TranslateUtils.ToInt(value); if (topLevel >= 0) { parseManager.ContextInfo.ContextType = ParseType.Channel; } } else if (StringUtils.EqualsIgnoreCase(name, Context)) { parseManager.ContextInfo.ContextType = TranslateUtils.ToEnum(value, ParseType.Undefined); } else if (StringUtils.EqualsIgnoreCase(name, Href)) { href = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, QueryString)) { queryString = await parseManager.ReplaceStlEntitiesForAttributeValueAsync(value); } else if (StringUtils.EqualsIgnoreCase(name, Host)) { host = value; } else { attributes[name] = value; } } var parsedContent = await ParseImplAsync(parseManager, channelIndex, channelName, upLevel, topLevel, removeTarget, href, queryString, host, attributes); return(parsedContent); }
private static async Task <string> ParseImplAsync(IParseManager parseManager, NameValueCollection attributes, bool isChannel, string channelIndex, string channelName, int upLevel, int topLevel, string scopeTypeString, string groupChannel, string groupChannelNot, string groupContent, string groupContentNot, string tags, string order, int totalNum, int titleWordNum, string queryString, bool isTop, bool isTopExists, bool isRecommend, bool isRecommendExists, bool isHot, bool isHotExists, bool isColor, bool isColorExists, string displayTitle, bool openWin) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; ScopeType scopeType; if (!string.IsNullOrEmpty(scopeTypeString)) { scopeType = TranslateUtils.ToEnum(scopeTypeString, ScopeType.Self); } else { scopeType = isChannel ? ScopeType.Children : ScopeType.Self; } var dataManager = new StlDataManager(parseManager.DatabaseManager); var orderByString = isChannel ? order : dataManager.GetContentOrderByString(pageInfo.SiteId, order, TaxisType.OrderByTaxisDesc); var channelId = await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); channelId = await dataManager.GetChannelIdByChannelIdOrChannelIndexOrChannelNameAsync(pageInfo.SiteId, channelId, channelIndex, channelName); var channel = await databaseManager.ChannelRepository.GetAsync(channelId); var uniqueId = "Select_" + pageInfo.UniqueId; attributes["id"] = uniqueId; string scriptHtml; if (openWin) { scriptHtml = $@" <script language=""javascript"" type=""text/javascript""> <!-- function {uniqueId}_jumpMenu(targ,selObj) {"{"} //v3.0 window.open(selObj.options[selObj.selectedIndex].value); selObj.selectedIndex=0; {"}"} //--> </script>"; attributes["onchange"] = $"{uniqueId}_jumpMenu('parent',this)"; } else { scriptHtml = $"<script language=\"JavaScript\">function {uniqueId}_jumpMenu(targ,selObj,restore){{eval(targ+\".location=\'\"+selObj.options[selObj.selectedIndex].value+\"\'\");if (restore) selObj.selectedIndex=0;}}</script>"; attributes["onchange"] = $"{uniqueId}_jumpMenu('self',this, 0)"; } var htmlBuilder = new StringBuilder(); using (var htmlSelect = new HtmlSelect(htmlBuilder, attributes)) { if (!string.IsNullOrEmpty(displayTitle)) { htmlSelect.AddOption(displayTitle, PageUtils.UnClickableUrl, true); } if (isChannel) { var channelIdList = await dataManager.GetChannelIdListAsync(pageInfo.SiteId, channel.Id, orderByString, scopeType, groupChannel, groupChannelNot, false, false, totalNum); if (channelIdList != null && channelIdList.Any()) { foreach (var channelIdInSelect in channelIdList) { var nodeInfo = await databaseManager.ChannelRepository.GetAsync(channelIdInSelect); if (nodeInfo != null) { var title = StringUtils.MaxLengthText(nodeInfo.ChannelName, titleWordNum); var url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, nodeInfo, pageInfo.IsLocal); if (!string.IsNullOrEmpty(queryString)) { url = PageUtils.AddQueryString(url, queryString); } htmlSelect.AddOption(title, url); } } } } else { var minContentInfoList = await databaseManager.ContentRepository.GetSummariesAsync(parseManager.DatabaseManager, pageInfo.Site, channelId, contextInfo.ContentId, groupContent, groupContentNot, tags, false, false, false, false, false, false, false, 1, totalNum, orderByString, isTopExists, isTop, isRecommendExists, isRecommend, isHotExists, isHot, isColorExists, isColor, scopeType, groupChannel, groupChannelNot, null); if (minContentInfoList != null) { foreach (var minContentInfo in minContentInfoList) { var contentInfo = await databaseManager.ContentRepository.GetAsync(pageInfo.Site, minContentInfo.ChannelId, minContentInfo.Id); var title = StringUtils.MaxLengthText(contentInfo.Title, titleWordNum); var url = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, contentInfo, false); if (!string.IsNullOrEmpty(queryString)) { url = PageUtils.AddQueryString(url, queryString); } htmlSelect.AddOption(title, url); } //foreach (var dataItem in dataSource) //{ // var contentInfo = new BackgroundContentInfo(dataItem); // if (contentInfo != null) // { // var title = StringUtils.MaxLengthText(contentInfo.Title, titleWordNum); // var url = PageUtility.GetContentUrl(pageInfo.Site, contentInfo); // if (!string.IsNullOrEmpty(queryString)) // { // url = PageUtils.AddQueryString(url, queryString); // } // var listitem = new ListItem(title, url); // selectControl.Items.Add(listitem); // } //} } } } return(scriptHtml + htmlBuilder); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string version, string title, string description, string scopeTypeString, string groupChannel, string groupChannelNot, string groupContent, string groupContentNot, string tags, string channelIndex, string channelName, int totalNum, int startNum, string orderByString, bool isTop, bool isTopExists, bool isRecommend, bool isRecommendExists, bool isHot, bool isHotExists, bool isColor, bool isColorExists) { var parsedContent = string.Empty; var feed = new RssFeed(); feed.Encoding = ECharsetUtils.GetEncoding(pageInfo.TemplateInfo.Charset); if (string.IsNullOrEmpty(version)) { feed.Version = RssVersion.RSS20; } else { feed.Version = (RssVersion)TranslateUtils.ToEnum(typeof(RssVersion), version, RssVersion.RSS20); } var channel = new RssChannel(); channel.Title = title; channel.Description = description; EScopeType scopeType; if (!string.IsNullOrEmpty(scopeTypeString)) { scopeType = EScopeTypeUtils.GetEnumType(scopeTypeString); } else { scopeType = EScopeType.All; } var channelID = StlCacheManager.NodeId.GetNodeIdByChannelIdOrChannelIndexOrChannelName(pageInfo.PublishmentSystemId, contextInfo.ChannelID, channelIndex, channelName); var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, channelID); if (string.IsNullOrEmpty(channel.Title)) { channel.Title = nodeInfo.NodeName; } if (string.IsNullOrEmpty(channel.Description)) { channel.Description = nodeInfo.Content; if (string.IsNullOrEmpty(channel.Description)) { channel.Description = nodeInfo.NodeName; } else { channel.Description = StringUtils.MaxLengthText(channel.Description, 200); } } channel.Link = new Uri(PageUtils.AddProtocolToUrl(PageUtility.GetChannelUrl(pageInfo.PublishmentSystemInfo, nodeInfo))); var dataSource = StlDataUtility.GetContentsDataSource(pageInfo.PublishmentSystemInfo, channelID, 0, groupContent, groupContentNot, tags, false, false, false, false, false, false, false, false, startNum, totalNum, orderByString, isTopExists, isTop, isRecommendExists, isRecommend, isHotExists, isHot, isColorExists, isColor, string.Empty, scopeType, groupChannel, groupChannelNot, null); if (dataSource != null) { foreach (var dataItem in dataSource) { var item = new RssItem(); var contentInfo = new BackgroundContentInfo(dataItem); item.Title = StringUtils.Replace("&", contentInfo.Title, "&"); item.Description = contentInfo.Summary; if (string.IsNullOrEmpty(item.Description)) { item.Description = StringUtils.StripTags(contentInfo.Content); if (string.IsNullOrEmpty(item.Description)) { item.Description = contentInfo.Title; } else { item.Description = StringUtils.MaxLengthText(item.Description, 200); } } item.Description = StringUtils.Replace("&", item.Description, "&"); item.PubDate = contentInfo.AddDate; item.Link = new Uri(PageUtils.AddProtocolToUrl(PageUtility.GetContentUrl(pageInfo.PublishmentSystemInfo, contentInfo))); channel.Items.Add(item); } } feed.Channels.Add(channel); var builder = new StringBuilder(); var textWriter = new EncodedStringWriter(builder, ECharsetUtils.GetEncoding(pageInfo.TemplateInfo.Charset)); feed.Write(textWriter); parsedContent = builder.ToString(); return(parsedContent); }
public async Task ExecuteAsync(IPluginJobContext context) { if (!CliUtils.ParseArgs(_options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } var contentRootPath = _settingsManager.ContentRootPath; if (!CliUtils.IsSsCmsExists(contentRootPath)) { var(success, result, failureMessage) = await _apiService.GetReleasesAsync(_settingsManager.Version, null); if (!success) { await WriteUtils.PrintErrorAsync(failureMessage); return; } var proceed = ReadUtils.GetYesNo($"Do you want to install SS CMS in {contentRootPath}?"); if (!proceed) { return; } Console.WriteLine($"Downloading SS CMS {result.Cms.Version}..."); var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version); await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!"); DirectoryUtils.Copy(directoryPath, contentRootPath, true); } InstallUtils.Init(contentRootPath); if (!await _configRepository.IsNeedInstallAsync()) { await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {contentRootPath}"); return; } var databaseTypeInput = ReadUtils.GetSelect("Database type", new List <string> { DatabaseType.MySql.GetValue().ToLower(), DatabaseType.SqlServer.GetValue().ToLower(), DatabaseType.PostgreSql.GetValue().ToLower(), DatabaseType.SQLite.GetValue().ToLower() }); var databaseType = TranslateUtils.ToEnum(databaseTypeInput, DatabaseType.MySql); var databaseName = string.Empty; var databaseHost = string.Empty; var isDatabaseDefaultPort = true; var databasePort = 0; var databaseUserName = string.Empty; var databasePassword = string.Empty; if (databaseType != DatabaseType.SQLite) { databaseHost = ReadUtils.GetString("Database hostname / IP:"); isDatabaseDefaultPort = ReadUtils.GetYesNo("Use default port?"); if (!isDatabaseDefaultPort) { databasePort = ReadUtils.GetInt("Database port:"); } databaseUserName = ReadUtils.GetString("Database userName:"******"Database password:"******"Database name", databaseNames); } var databaseConnectionString = InstallUtils.GetDatabaseConnectionString(databaseType, databaseHost, isDatabaseDefaultPort, databasePort, databaseUserName, databasePassword, databaseName); var isProtectData = ReadUtils.GetYesNo("Protect settings in sscms.json?"); _settingsManager.SaveSettings(isProtectData, false, false, databaseType, databaseConnectionString, string.Empty, string.Empty, null, null); await WriteUtils.PrintSuccessAsync("SS CMS was download and ready for install, please run: sscms install database"); }
public async Task <(User user, string userName, string errorMessage)> ValidateAsync(string account, string password, bool isPasswordMd5) { if (string.IsNullOrEmpty(account)) { return(null, null, "账号不能为空"); } if (string.IsNullOrEmpty(password)) { return(null, null, "密码不能为空"); } var user = await GetByAccountAsync(account); if (string.IsNullOrEmpty(user?.UserName)) { return(null, null, "帐号或密码错误"); } if (!user.Checked) { return(null, user.UserName, "此账号未审核,无法登录"); } if (user.Locked) { return(null, user.UserName, "此账号被锁定,无法登录"); } var config = await _configRepository.GetAsync(); if (config.IsUserLockLogin) { if (user.CountOfFailedLogin > 0 && user.CountOfFailedLogin >= config.UserLockLoginCount) { var lockType = TranslateUtils.ToEnum(config.UserLockLoginType, LockType.Hours); if (lockType == LockType.Forever) { return(null, user.UserName, "此账号错误登录次数过多,已被永久锁定"); } if (lockType == LockType.Hours && user.LastActivityDate.HasValue) { var ts = new TimeSpan(DateTime.Now.Ticks - user.LastActivityDate.Value.Ticks); var hours = Convert.ToInt32(config.UserLockLoginHours - ts.TotalHours); if (hours > 0) { return(null, user.UserName, $"此账号错误登录次数过多,已被锁定,请等待{hours}小时后重试"); } } } } var userEntity = await GetByUserIdAsync(user.Id); if (!CheckPassword(password, isPasswordMd5, userEntity.Password, userEntity.PasswordFormat, userEntity.PasswordSalt)) { await UpdateLastActivityDateAndCountOfFailedLoginAsync(user); return(null, user.UserName, "帐号或密码错误"); } return(user, user.UserName, string.Empty); }
private static QueryInfo Parse(string stlElement) { var(innerHtml, attributes) = ParseUtils.GetInnerHtmlAndAttributes(stlElement); var query = new QueryInfo { Type = nameof(Query.Where), Column = string.Empty, Op = string.Empty, Value = string.Empty, DataType = Datory.DataType.VarChar }; foreach (var name in attributes.AllKeys) { var attributeValue = attributes[name]; if (StringUtils.EqualsIgnoreCase(name, Type)) { query.Type = attributeValue; } else if (StringUtils.EqualsIgnoreCase(name, Column)) { query.Column = attributeValue; } else if (StringUtils.EqualsIgnoreCase(name, Op)) { query.Op = attributeValue; } else if (StringUtils.EqualsIgnoreCase(name, Value)) { query.Value = attributeValue; } else if (StringUtils.EqualsIgnoreCase(name, DataType)) { if (StringUtils.EqualsIgnoreCase(attributeValue, "int")) { query.DataType = Datory.DataType.Integer; } else if (StringUtils.EqualsIgnoreCase(attributeValue, "string")) { query.DataType = Datory.DataType.VarChar; } else if (StringUtils.EqualsIgnoreCase(attributeValue, "bool")) { query.DataType = Datory.DataType.Boolean; } else { query.DataType = TranslateUtils.ToEnum(attributeValue, Datory.DataType.VarChar); } } } if (!string.IsNullOrEmpty(innerHtml)) { var stlElementList = ParseUtils.GetStlElements(innerHtml); if (stlElementList.Count > 0) { foreach (var theStlElement in stlElementList) { if (ParseUtils.IsSpecifiedStlElement(theStlElement, ElementName)) { if (query.Queries == null) { query.Queries = new List <QueryInfo>(); } query.Queries.Add(Parse(theStlElement)); } } } } return(query); }
public Dictionary <DateTime, int> GetTrackingDictionary(DateTime dateFrom, DateTime dateTo, string xType) { var analysisType = TranslateUtils.ToEnum(xType, AnalysisType.Day); var dict = new Dictionary <DateTime, int>(); var builder = new StringBuilder(); builder.Append($" AND CreateDate >= {SqlUtils.GetComparableDate(Database.DatabaseType, dateFrom)}"); builder.Append($" AND CreateDate < {SqlUtils.GetComparableDate(Database.DatabaseType, dateTo)}"); string sqlString = $@" SELECT COUNT(*) AS AddNum, AddYear, AddMonth, AddDay FROM ( SELECT {SqlUtils.GetDatePartYear(Database.DatabaseType, "CreateDate")} AS AddYear, {SqlUtils.GetDatePartMonth(Database.DatabaseType, "CreateDate")} AS AddMonth, {SqlUtils.GetDatePartDay(Database.DatabaseType, "CreateDate")} AS AddDay FROM {TableName} WHERE {SqlUtils.GetDateDiffLessThanDays(Database.DatabaseType, "CreateDate", 30.ToString())} {builder} ) DERIVEDTBL GROUP BY AddYear, AddMonth, AddDay ORDER BY AddYear, AddMonth, AddDay ";//添加日统计 if (analysisType == AnalysisType.Month) { sqlString = $@" SELECT COUNT(*) AS AddNum, AddYear, AddMonth FROM ( SELECT {SqlUtils.GetDatePartYear(Database.DatabaseType, "CreateDate")} AS AddYear, {SqlUtils.GetDatePartMonth(Database.DatabaseType, "CreateDate")} AS AddMonth FROM {TableName} WHERE {SqlUtils.GetDateDiffLessThanMonths(Database.DatabaseType, "CreateDate", 12.ToString())} {builder} ) DERIVEDTBL GROUP BY AddYear, AddMonth ORDER BY AddYear, AddMonth ";//添加月统计 } else if (analysisType == AnalysisType.Year) { sqlString = $@" SELECT COUNT(*) AS AddNum, AddYear FROM ( SELECT {SqlUtils.GetDatePartYear(Database.DatabaseType, "CreateDate")} AS AddYear FROM {TableName} WHERE {SqlUtils.GetDateDiffLessThanYears(Database.DatabaseType, "CreateDate", 10.ToString())} {builder} ) DERIVEDTBL GROUP BY AddYear ORDER BY AddYear ";//添加年统计 } using (var connection = _repository.Database.GetConnection()) { using (var rdr = connection.ExecuteReader(sqlString)) { while (rdr.Read()) { var accessNum = rdr.IsDBNull(0) ? 0 : rdr.GetInt32(0); if (analysisType == AnalysisType.Day) { var year = rdr.GetValue(1); var month = rdr.GetValue(2); var day = rdr.GetValue(3); var dateTime = TranslateUtils.ToDateTime($"{year}-{month}-{day}"); dict.Add(dateTime, accessNum); } else if (analysisType == AnalysisType.Month) { var year = rdr.GetValue(1); var month = rdr.GetValue(2); var dateTime = TranslateUtils.ToDateTime($"{year}-{month}-1"); dict.Add(dateTime, accessNum); } else if (analysisType == AnalysisType.Year) { var year = rdr.GetValue(1); var dateTime = TranslateUtils.ToDateTime($"{year}-1-1"); dict.Add(dateTime, accessNum); } } rdr.Close(); } } return(dict); }