public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);
            var styleDatabase     =
                await _tableStyleRepository.GetTableStyleAsync(request.TableName, request.AttributeName, relatedIdentities) ??
                new Models.TableStyle();

            bool   isSuccess;
            string errorMessage;

            //数据库中没有此项及父项的表样式 or 数据库中没有此项的表样式,但是有父项的表样式
            if (styleDatabase.Id == 0 && styleDatabase.RelatedIdentity == 0 || styleDatabase.RelatedIdentity != relatedIdentities[0])
            {
                (isSuccess, errorMessage) = await InsertTableStyleAsync(request);

                await _authManager.AddAdminLogAsync("添加表单显示样式", $"字段名:{request.AttributeName}");
            }
            //数据库中有此项的表样式
            else
            {
                (isSuccess, errorMessage) = await UpdateTableStyleAsync(styleDatabase, request);

                await _authManager.AddAdminLogAsync("修改表单显示样式", $"字段名:{request.AttributeName}");
            }

            if (!isSuccess)
            {
                return(this.Error(errorMessage));
            }

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 2
0
 private static void OrWhereNotIn(Query query, QueryInfo queryInfo)
 {
     if (!string.IsNullOrEmpty(queryInfo.Column) && !string.IsNullOrEmpty(queryInfo.Value))
     {
         if (queryInfo.DataType == Datory.DataType.VarChar)
         {
             query.OrWhereNotIn(queryInfo.Column, ListUtils.GetStringList(queryInfo.Value));
         }
         else if (queryInfo.DataType == Datory.DataType.Integer)
         {
             query.OrWhereNotIn(queryInfo.Column, ListUtils.GetIntList(queryInfo.Value));
         }
         else if (queryInfo.DataType == Datory.DataType.DateTime)
         {
             var list = ListUtils.GetStringList(queryInfo.Value)
                        .Select(TranslateUtils.ToDateTime);
             query.OrWhereNotIn(queryInfo.Column, list);
         }
         else if (queryInfo.DataType == Datory.DataType.Decimal)
         {
             var list = ListUtils.GetStringList(queryInfo.Value)
                        .Select(x => TranslateUtils.ToDecimal(x));
             query.OrWhereNotIn(queryInfo.Column, list);
         }
     }
 }
Ejemplo n.º 3
0
        public async Task <List <int> > UpdateSiteIdAsync(Administrator administrator, int siteId)
        {
            if (administrator == null || siteId <= 0)
            {
                return(null);
            }

            var siteIdsLatestAccessed = ListUtils.GetIntList(administrator.SiteIds);

            if (administrator.SiteId != siteId || siteIdsLatestAccessed.FirstOrDefault() != siteId)
            {
                siteIdsLatestAccessed.Remove(siteId);
                siteIdsLatestAccessed.Insert(0, siteId);

                administrator.SiteIds = siteIdsLatestAccessed.Distinct().ToList();
                administrator.SiteId  = siteId;

                var cacheKeys = GetCacheKeys(administrator);

                await _repository.UpdateAsync(Q
                                              .Set(nameof(Administrator.SiteIds), ListUtils.ToString(administrator.SiteIds))
                                              .Set(nameof(Administrator.SiteId), administrator.SiteId)
                                              .Where(nameof(Administrator.Id), administrator.Id)
                                              .CachingRemove(cacheKeys.ToArray())
                                              );
            }

            return(siteIdsLatestAccessed);
        }
Ejemplo n.º 4
0
        public async Task <List <int> > GetVisibleChannelIdsAsync(List <int> channelIdsWithPermissions)
        {
            var visibleChannelIds = new List <int>();

            foreach (var enabledChannelId in channelIdsWithPermissions)
            {
                var enabledChannel = await _databaseManager.ChannelRepository.GetAsync(enabledChannelId);

                if (enabledChannel == null)
                {
                    continue;
                }

                var parentIds = ListUtils.GetIntList(enabledChannel.ParentsPath);
                foreach (var parentId in parentIds.Where(parentId => !visibleChannelIds.Contains(parentId)))
                {
                    visibleChannelIds.Add(parentId);
                }
                if (!visibleChannelIds.Contains(enabledChannelId))
                {
                    visibleChannelIds.Add(enabledChannelId);
                }
            }

            return(visibleChannelIds);
        }
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);
            var style             =
                await _tableStyleRepository.GetTableStyleAsync(request.TableName, request.AttributeName, relatedIdentities);

            style.Rules = request.Rules;

            //数据库中没有此项及父项的表样式 or 数据库中没有此项的表样式,但是有父项的表样式
            if (style.Id == 0 && style.RelatedIdentity == 0 || style.RelatedIdentity != relatedIdentities[0])
            {
                await _tableStyleRepository.InsertAsync(relatedIdentities, style);

                await _authManager.AddAdminLogAsync("添加表单显示样式", $"字段名:{style.AttributeName}");
            }
            //数据库中有此项的表样式
            else
            {
                await _tableStyleRepository.UpdateAsync(style);

                await _authManager.AddAdminLogAsync("修改表单显示样式", $"字段名:{style.AttributeName}");
            }

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 6
0
        public async Task InsertChannelAsync(Channel parentChannel, Channel channel)
        {
            if (parentChannel != null)
            {
                channel.SiteId = parentChannel.SiteId;
                if (string.IsNullOrEmpty(parentChannel.ParentsPath))
                {
                    channel.ParentsPath = parentChannel.Id.ToString();
                }
                else
                {
                    channel.ParentsPath = parentChannel.ParentsPath + "," + parentChannel.Id;
                }
                channel.ParentsCount = parentChannel.ParentsCount + 1;

                var maxTaxis = await GetMaxTaxisAsync(channel.SiteId, channel.ParentId);

                if (maxTaxis == 0)
                {
                    maxTaxis = parentChannel.Taxis;
                }
                channel.Taxis = maxTaxis + 1;
            }
            else
            {
                channel.Taxis = 1;
            }

            channel.ChildrenCount = 0;

            if (channel.SiteId != 0)
            {
                await _repository.IncrementAsync(nameof(Channel.Taxis), Q
                                                 .Where(nameof(Channel.Taxis), ">=", channel.Taxis)
                                                 .Where(nameof(Channel.SiteId), channel.SiteId)
                                                 );
            }

            channel.Id = await _repository.InsertAsync(channel, Q
                                                       .CachingRemove(GetListKey(channel.SiteId))
                                                       );

            if (parentChannel != null)
            {
                await _repository.RemoveCacheAsync(GetEntityKey(parentChannel.Id));
            }

            if (!string.IsNullOrEmpty(channel.ParentsPath))
            {
                await _repository.IncrementAsync(nameof(Channel.ChildrenCount), Q
                                                 .WhereIn(nameof(Channel.Id), ListUtils.GetIntList(channel.ParentsPath))
                                                 );
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);
            var style             = await _tableStyleRepository.GetTableStyleAsync(request.TableName, request.AttributeName, relatedIdentities);

            var options = ListUtils.GetEnums <ValidateType>().Select(validateType =>
                                                                     new Select <string>(validateType.GetValue(), validateType.GetDisplayName()));

            return(new GetResult
            {
                Options = options,
                Rules = TranslateUtils.JsonDeserialize <IEnumerable <InputStyleRule> >(style.RuleValues)
            });
        }
Ejemplo n.º 8
0
 private static void ForPage(Query query, QueryInfo queryInfo)
 {
     if (!string.IsNullOrEmpty(queryInfo.Value))
     {
         var pair = ListUtils.GetIntList(queryInfo.Value);
         if (pair != null && pair.Count == 2)
         {
             query.ForPage(pair[0], pair[1]);
         }
         else
         {
             query.ForPage(TranslateUtils.ToInt(queryInfo.Value));
         }
     }
 }
Ejemplo n.º 9
0
        public async Task DeleteAsync(Site site, int channelId, int adminId)
        {
            var channelEntity = await GetAsync(channelId);

            if (channelEntity == null)
            {
                return;
            }

            var idList = new List <int>();

            if (channelEntity.ChildrenCount > 0)
            {
                idList = await GetChannelIdsAsync(site.Id, channelId, ScopeType.Descendant);
            }
            idList.Add(channelId);

            //_contentRepository.DeleteContentsByDeletedChannelIdList(trans, site, idList);

            var cacheKeys = new List <string> {
                GetListKey(site.Id)
            };

            cacheKeys.AddRange(idList.Select(GetEntityKey));

            var deletedNum = await _repository.DeleteAsync(Q
                                                           .Where(nameof(Channel.SiteId), site.Id)
                                                           .WhereIn(nameof(Channel.Id), idList)
                                                           .CachingRemove(cacheKeys.ToArray())
                                                           );

            if (channelEntity.ParentId != 0)
            {
                await _repository.DecrementAsync(nameof(Channel.Taxis), Q
                                                 .Where(nameof(Channel.SiteId), channelEntity.SiteId)
                                                 .Where(nameof(Channel.Taxis), ">", channelEntity.Taxis)
                                                 .CachingRemove(GetListKey(site.Id))
                                                 , deletedNum);
            }

            if (!string.IsNullOrEmpty(channelEntity.ParentsPath))
            {
                await _repository.DecrementAsync(nameof(Channel.ChildrenCount), Q
                                                 .WhereIn(nameof(Channel.Id), ListUtils.GetIntList(channelEntity.ParentsPath))
                                                 .CachingRemove(GetListKey(site.Id))
                                                 , deletedNum);
            }
        }
        public async Task <ActionResult <GetResult> > List([FromQuery] SiteRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsCreateTrigger))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(this.Error("无法确定内容对应的站点"));
            }

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var cascade = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count  = await _contentRepository.GetCountAsync(site, summary);
                var entity = await _channelRepository.GetAsync(summary.Id);

                var changeNames   = new List <string>();
                var channelIdList = ListUtils.GetIntList(entity.CreateChannelIdsIfContentChanged);
                foreach (var channelId in channelIdList)
                {
                    if (await _channelRepository.IsExistsAsync(channelId))
                    {
                        changeNames.Add(await _channelRepository.GetChannelNameNavigationAsync(request.SiteId, channelId));
                    }
                }

                return(new
                {
                    entity.IndexName,
                    Count = count,
                    ChangeNames = changeNames,
                    entity.IsCreateChannelIfContentChanged,
                    CreateChannelIdsIfContentChanged = channelIdList,
                });
            });

            return(new GetResult
            {
                Channel = cascade
            });
        }
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);

            foreach (var style in request.Styles)
            {
                var styleDatabase =
                    await _tableStyleRepository.GetTableStyleAsync(request.TableName, style.AttributeName, relatedIdentities) ??
                    new Models.TableStyle();

                //数据库中没有此项及父项的表样式 or 数据库中没有此项的表样式,但是有父项的表样式
                if ((styleDatabase.Id != 0 || styleDatabase.RelatedIdentity != 0) &&
                    styleDatabase.RelatedIdentity == relatedIdentities[0])
                {
                    continue;
                }
                var relatedIdentity = relatedIdentities[0];

                if (string.IsNullOrEmpty(style.AttributeName))
                {
                    continue;
                }

                if (await _tableStyleRepository.IsExistsAsync(relatedIdentity, request.TableName, style.AttributeName))
                {
                    continue;
                }

                var tableStyle = await _databaseManager.IsAttributeNameExistsAsync(request.TableName, style.AttributeName) ? await _tableStyleRepository.GetTableStyleAsync(request.TableName, style.AttributeName, relatedIdentities) : new Models.TableStyle();

                tableStyle.RelatedIdentity = relatedIdentity;
                tableStyle.TableName       = request.TableName;
                tableStyle.AttributeName   = style.AttributeName;
                tableStyle.DisplayName     = style.DisplayName;
                tableStyle.InputType       = style.InputType;

                await _tableStyleRepository.InsertAsync(relatedIdentities, tableStyle);
            }

            await _authManager.AddAdminLogAsync("批量添加表单显示样式");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 12
0
        public async Task TriggerContentChangedEventAsync(int siteId, int channelId)
        {
            if (siteId <= 0 || channelId <= 0)
            {
                return;
            }

            var channelInfo = await _channelRepository.GetAsync(channelId);

            var channelIdList = ListUtils.GetIntList(channelInfo.CreateChannelIdsIfContentChanged);

            if (channelInfo.IsCreateChannelIfContentChanged && !channelIdList.Contains(channelId))
            {
                channelIdList.Add(channelId);
            }
            foreach (var theChannelId in channelIdList)
            {
                await CreateChannelAsync(siteId, theChannelId);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 导出网站内容至默认的临时文件地址
        /// </summary>
        public async Task ExportSiteContentAsync(string siteContentDirectoryPath, bool isSaveContents, bool isSaveAllChannels, IList <int> channelIdArrayList)
        {
            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            var allChannelIdList = await _databaseManager.ChannelRepository.GetChannelIdsAsync(_site.Id);

            var includeChannelIdArrayList = new ArrayList();

            foreach (int channelId in channelIdArrayList)
            {
                var nodeInfo = await _databaseManager.ChannelRepository.GetAsync(channelId);

                var parentIdArrayList = ListUtils.GetIntList(nodeInfo.ParentsPath);
                foreach (int parentId in parentIdArrayList)
                {
                    if (!includeChannelIdArrayList.Contains(parentId))
                    {
                        includeChannelIdArrayList.Add(parentId);
                    }
                }
                if (!includeChannelIdArrayList.Contains(channelId))
                {
                    includeChannelIdArrayList.Add(channelId);
                }
            }

            var siteIe = new SiteIe(_pathManager, _databaseManager, _caching, _site, siteContentDirectoryPath);

            foreach (var channelId in allChannelIdList)
            {
                if (!isSaveAllChannels)
                {
                    if (!includeChannelIdArrayList.Contains(channelId))
                    {
                        continue;
                    }
                }
                await siteIe.ExportAsync(_site, channelId, isSaveContents);
            }
        }
Ejemplo n.º 14
0
        public List <int> GetRelatedIdentities(Channel channel)
        {
            var list = new List <int>();

            if (channel != null)
            {
                var channelIdCollection = "0," + channel.Id;
                if (channel.ParentsCount > 0)
                {
                    channelIdCollection = "0," + channel.ParentsPath + "," + channel.Id;
                }

                list = ListUtils.GetIntList(channelIdCollection);
                list.Reverse();
            }
            else
            {
                list.Add(0);
            }
            return(list);
        }
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId))
            {
                return(Unauthorized());
            }

            var articleIds = ListUtils.GetIntList(request.ArticleIds);

            var groups = await _materialGroupRepository.GetAllAsync(MaterialType.Message);

            var count = await _materialArticleRepository.GetCountAsync(request.GroupId, request.Keyword, articleIds);

            var items = await _materialArticleRepository.GetAllAsync(request.GroupId, request.Keyword, request.Page, request.PerPage, articleIds);

            return(new GetResult
            {
                Groups = groups,
                Count = count,
                Items = items
            });
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsList))
            {
                return(Unauthorized());
            }

            var rule = await _ruleRepository.GetAsync(request.RuleId);

            var site = await _siteRepository.GetAsync(request.SiteId);

            var channels = await _channelRepository.GetCascadeChildrenAsync(site, site.Id,
                                                                            async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            var channel = await _channelRepository.GetAsync(rule.ChannelId);

            var channelIds = new List <int>();

            if (channel != null)
            {
                channelIds = ListUtils.GetIntList(channel.ParentsPath);
                channelIds.Add(rule.ChannelId);
                channelIds.Remove(site.Id);
            }

            return(new GetResult
            {
                Rule = rule,
                Channels = channels,
                ChannelIds = channelIds
            });
        }
Ejemplo n.º 17
0
 private static WxUser GetWxUser(UserInfoJson json)
 {
     return(new WxUser
     {
         Subscribe = json.subscribe,
         OpenId = json.openid,
         Nickname = json.nickname,
         Sex = json.sex,
         Language = json.language,
         City = json.city,
         Province = json.province,
         Country = json.country,
         HeadImgUrl = json.headimgurl,
         SubscribeTime = GetDateTimeWithTimeStamp(json.subscribe_time),
         UnionId = json.unionid,
         Remark = json.remark,
         GroupId = json.groupid,
         TagIdList = ListUtils.GetIntList(json.tagid_list),
         SubscribeScene = json.subscribe_scene,
         QrScene = json.qr_scene,
         QrSceneStr = json.qr_scene_str
     });
 }
Ejemplo n.º 18
0
        private static async Task <string> ParseAsync(IParseManager parseManager, string separator, string target, string linkClass, int wordNum, bool isContainSelf)
        {
            var databaseManager = parseManager.DatabaseManager;
            var pageInfo        = parseManager.PageInfo;
            var contextInfo     = parseManager.ContextInfo;

            if (!string.IsNullOrEmpty(contextInfo.InnerHtml))
            {
                separator = contextInfo.InnerHtml;
            }

            var channel = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId);

            var builder = new StringBuilder();

            var parentsCount = channel.ParentsCount;
            var nodePath     = ListUtils.GetIntList(channel.ParentsPath);

            if (isContainSelf)
            {
                nodePath.Add(contextInfo.ChannelId);
            }
            foreach (var currentId in nodePath.Distinct())
            {
                var currentNodeInfo = await databaseManager.ChannelRepository.GetAsync(currentId);

                if (currentId == pageInfo.SiteId)
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetIndexPageUrlAsync(pageInfo.Site, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");

                    if (parentsCount > 0)
                    {
                        builder.Append(separator);
                    }
                }
                else if (currentId == contextInfo.ChannelId)
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, currentNodeInfo, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");
                }
                else
                {
                    var attributes = new NameValueCollection();
                    if (!string.IsNullOrEmpty(target))
                    {
                        attributes["target"] = target;
                    }
                    if (!string.IsNullOrEmpty(linkClass))
                    {
                        attributes["class"] = linkClass;
                    }
                    var url = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, currentNodeInfo, pageInfo.IsLocal);

                    if (url.Equals(PageUtils.UnClickableUrl))
                    {
                        attributes["target"] = string.Empty;
                    }
                    attributes["href"] = url;
                    var innerHtml = StringUtils.MaxLengthText(currentNodeInfo.ChannelName, wordNum);

                    TranslateUtils.AddAttributesIfNotExists(attributes, contextInfo.Attributes);

                    builder.Append($@"<a {TranslateUtils.ToAttributesString(attributes)}>{innerHtml}</a>");

                    if (parentsCount > 0)
                    {
                        builder.Append(separator);
                    }
                }
            }

            return(builder.ToString());
        }
Ejemplo n.º 19
0
        private static bool IsNumber(int number, string testOperate, string testValue)
        {
            var isSuccess = false;

            if (StringUtils.EqualsIgnoreCase(testOperate, OperateEquals))
            {
                if (number == TranslateUtils.ToInt(testValue))
                {
                    isSuccess = true;
                }
            }
            else if (StringUtils.EqualsIgnoreCase(testOperate, OperateNotEquals))
            {
                if (number != TranslateUtils.ToInt(testValue))
                {
                    isSuccess = true;
                }
            }
            else if (StringUtils.EqualsIgnoreCase(testOperate, OperateGreatThan))
            {
                if (number > TranslateUtils.ToInt(testValue))
                {
                    isSuccess = true;
                }
            }
            else if (StringUtils.EqualsIgnoreCase(testOperate, OperateLessThan))
            {
                if (number < TranslateUtils.ToInt(testValue))
                {
                    isSuccess = true;
                }
            }
            else if (StringUtils.EqualsIgnoreCase(testOperate, OperateIn))
            {
                var intArrayList = ListUtils.GetIntList(testValue);
                foreach (int i in intArrayList)
                {
                    if (i == number)
                    {
                        isSuccess = true;
                        break;
                    }
                }
            }
            else if (StringUtils.EqualsIgnoreCase(testOperate, OperateNotIn))
            {
                var intArrayList = ListUtils.GetIntList(testValue);
                var isIn         = false;
                foreach (int i in intArrayList)
                {
                    if (i == number)
                    {
                        isIn = true;
                        break;
                    }
                }
                if (!isIn)
                {
                    isSuccess = true;
                }
            }
            return(isSuccess);
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsAdd))
            {
                return(Unauthorized());
            }

            Rule          rule;
            List <string> contentHtmlClearList;
            List <string> contentHtmlClearTagList;

            if (request.RuleId > 0)
            {
                rule = await _ruleRepository.GetAsync(request.RuleId);

                contentHtmlClearList    = ListUtils.GetStringList(rule.ContentHtmlClearCollection);
                contentHtmlClearTagList = ListUtils.GetStringList(rule.ContentHtmlClearTagCollection);
            }
            else
            {
                rule = new Rule
                {
                    SiteId                        = request.SiteId,
                    Charset                       = Charset.Utf8,
                    IsSaveImage                   = true,
                    ImageSource                   = ImageSource.None,
                    IsOrderByDesc                 = true,
                    GatherUrlIsCollection         = true,
                    ContentHtmlClearCollection    = "",
                    ContentHtmlClearTagCollection = ""
                };
                contentHtmlClearList = new List <string>
                {
                    "script",
                    "object",
                    "iframe"
                };
                contentHtmlClearTagList = new List <string>
                {
                    "font",
                    "div",
                    "span"
                };
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            var channels = await _channelRepository.GetCascadeChildrenAsync(site, site.Id,
                                                                            async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            var charsetList = ListUtils.GetSelects <Charset>();

            var channel = await _channelRepository.GetAsync(rule.ChannelId);

            var channelIds = new List <int>();

            if (channel != null)
            {
                channelIds = ListUtils.GetIntList(channel.ParentsPath);
                channelIds.Add(rule.ChannelId);
                channelIds.Remove(site.Id);
            }

            return(new GetResult
            {
                Rule = rule,
                Channels = channels,
                ChannelIds = channelIds,
                CharsetList = charsetList,
                ContentHtmlClearList = contentHtmlClearList,
                ContentHtmlClearTagList = contentHtmlClearTagList
            });
        }
        private async Task <(bool Success, string ErrorMessage)> InsertTableStyleAsync(SubmitRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);
            var relatedIdentity   = relatedIdentities[0];

            if (string.IsNullOrEmpty(request.AttributeName))
            {
                return(false, "操作失败,字段名不能为空!");
            }

            if (await _tableStyleRepository.IsExistsAsync(relatedIdentity, request.TableName, request.AttributeName))
            {
                return(false, $@"显示样式添加失败:字段名""{request.AttributeName}""已存在");
            }

            var style = await _databaseManager.IsAttributeNameExistsAsync(request.TableName, request.AttributeName) ? await _tableStyleRepository.GetTableStyleAsync(request.TableName, request.AttributeName, relatedIdentities) : new Models.TableStyle();

            style.RelatedIdentity = relatedIdentity;
            style.TableName       = request.TableName;
            style.AttributeName   = request.AttributeName;
            style.DisplayName     = request.DisplayName;
            style.HelpText        = request.HelpText;
            style.Taxis           = request.Taxis;
            style.InputType       = request.InputType;
            style.DefaultValue    = request.DefaultValue;
            style.Horizontal      = request.Horizontal;
            style.Items           = new List <InputStyleItem>();

            if (request.InputType == InputType.CheckBox || request.InputType == InputType.Radio || request.InputType == InputType.SelectMultiple || request.InputType == InputType.SelectOne)
            {
                if (request.IsRapid)
                {
                    foreach (var rapidValue in ListUtils.GetStringListByReturnAndNewline(request.RapidValues))
                    {
                        var itemInfo = new InputStyleItem
                        {
                            Label    = rapidValue,
                            Value    = rapidValue,
                            Selected = false
                        };
                        style.Items.Add(itemInfo);
                    }
                }
                else
                {
                    var isHasSelected = false;
                    foreach (var styleItem in request.Items)
                    {
                        if (request.InputType != InputType.SelectMultiple && request.InputType != InputType.CheckBox && isHasSelected && styleItem.Selected)
                        {
                            return(false, "操作失败,只能有一个初始化时选定项!");
                        }
                        if (styleItem.Selected)
                        {
                            isHasSelected = true;
                        }

                        var itemInfo = new InputStyleItem
                        {
                            Label    = styleItem.Label,
                            Value    = styleItem.Value,
                            Selected = styleItem.Selected
                        };
                        style.Items.Add(itemInfo);
                    }
                }
            }
            else if (request.InputType == InputType.TextArea || request.InputType == InputType.TextEditor)
            {
                style.Height = request.Height;
            }
            else if (request.InputType == InputType.Customize)
            {
                style.CustomizeCode = request.CustomizeCode;
            }

            await _tableStyleRepository.InsertAsync(relatedIdentities, style);

            return(true, string.Empty);
        }
Ejemplo n.º 22
0
        public async Task <Query> GetQueryByStlSearchAsync(IDatabaseManager databaseManager, bool isAllSites, string siteName, string siteDir, string siteIds, string channelIndex, string channelName, string channelIds, string type, string word, string dateAttribute, string dateFrom, string dateTo, string since, int siteId, List <string> excludeAttributes, NameValueCollection form)
        {
            var query = Q.NewQuery();

            Site site = null;

            if (!string.IsNullOrEmpty(siteName))
            {
                site = await _siteRepository.GetSiteBySiteNameAsync(siteName);
            }
            else if (!string.IsNullOrEmpty(siteDir))
            {
                site = await _siteRepository.GetSiteByDirectoryAsync(siteDir);
            }
            if (site == null)
            {
                site = await _siteRepository.GetAsync(siteId);
            }

            var channelId = await _channelRepository.GetChannelIdAsync(siteId, siteId, channelIndex, channelName);

            var channel = await _channelRepository.GetAsync(channelId);

            if (isAllSites)
            {
                query.Where(nameof(Content.SiteId), ">", 0);
            }
            else if (!string.IsNullOrEmpty(siteIds))
            {
                query.WhereIn(nameof(Content.SiteId), ListUtils.GetIntList(siteIds));
            }
            else
            {
                query.Where(nameof(Content.SiteId), site.Id);
            }

            if (!string.IsNullOrEmpty(channelIds))
            {
                var channelIdList = new List <int>();
                foreach (var theChannelId in ListUtils.GetIntList(channelIds))
                {
                    var theChannel = await _channelRepository.GetAsync(theChannelId);

                    channelIdList.AddRange(
                        await _channelRepository.GetChannelIdsAsync(theChannel.SiteId, theChannel.Id, ScopeType.All));
                }

                if (channelIdList.Count == 1)
                {
                    query.Where(nameof(Content.ChannelId), channelIdList[0]);
                }
                else
                {
                    query.WhereIn(nameof(Content.ChannelId), channelIdList);
                }
            }
            else if (channelId != siteId)
            {
                var channelIdList = await _channelRepository.GetChannelIdsAsync(siteId, channelId, ScopeType.All);

                if (channelIdList.Count == 1)
                {
                    query.Where(nameof(Content.ChannelId), channelIdList[0]);
                }
                else
                {
                    query.WhereIn(nameof(Content.ChannelId), channelIdList);
                }
            }

            var typeList = new List <string>();

            if (string.IsNullOrEmpty(type))
            {
                typeList.Add(nameof(Content.Title));
            }
            else
            {
                typeList = ListUtils.GetStringList(type);
            }

            var tableName = _channelRepository.GetTableName(site, channel);
            var columns   = await databaseManager.GetTableColumnInfoListAsync(tableName, excludeAttributes);

            if (!string.IsNullOrEmpty(word))
            {
                query.Where(q =>
                {
                    foreach (var attributeName in typeList)
                    {
                        if (StringUtils.EqualsIgnoreCase(attributeName, nameof(ListInfo.Tags)) || StringUtils.EqualsIgnoreCase(attributeName, nameof(Content.TagNames)))
                        {
                            q
                            //.OrWhere(nameof(Content.TagNames), word)
                            .OrWhereLike(nameof(Content.TagNames), $"%{word}%");
                            //.OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $",{word}")
                            //.OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $",{word},")
                            //.OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $"{word},");
                        }
                        else
                        {
                            var column = columns.FirstOrDefault(x =>
                                                                StringUtils.EqualsIgnoreCase(x.AttributeName, attributeName));

                            if (column != null && (column.DataType == DataType.VarChar || column.DataType == DataType.Text))
                            {
                                q.OrWhereLike(column.AttributeName, $"%{word}%");
                            }
                            //else
                            //{
                            //    q.OrWhereLike(AttrExtendValues, $"%{attributeName}={word}%");
                            //}
                        }
                    }

                    return(q);
                }
                            );
            }

            if (string.IsNullOrEmpty(dateAttribute))
            {
                dateAttribute = nameof(Content.AddDate);
            }

            if (!string.IsNullOrEmpty(dateFrom))
            {
                query.WhereDate(dateAttribute, ">=", dateFrom);
            }
            if (!string.IsNullOrEmpty(dateTo))
            {
                query.WhereDate(dateAttribute, "<=", dateTo);
            }
            if (!string.IsNullOrEmpty(since))
            {
                var sinceDate = DateTime.Now.AddHours(-DateUtils.GetSinceHours(since));

                query.WhereBetween(dateAttribute, sinceDate, DateTime.Now);
            }


            //var styleInfoList = RelatedIdentities.GetTableStyleInfoList(site, channel.Id);

            foreach (string attributeName in form.Keys)
            {
                if (ListUtils.ContainsIgnoreCase(excludeAttributes, attributeName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(form[attributeName]))
                {
                    continue;
                }

                var value = StringUtils.Trim(form[attributeName]);
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (StringUtils.EqualsIgnoreCase(attributeName, nameof(ListInfo.Tags)) || StringUtils.EqualsIgnoreCase(attributeName, nameof(Content.TagNames)))
                {
                    query.Where(q => q
                                .Where(nameof(Content.TagNames), word)
                                .OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $",{word}")
                                .OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $",{word},")
                                .OrWhereInStr(Database.DatabaseType, nameof(Content.TagNames), $"{word},"));
                }
                else
                {
                    var column = columns.FirstOrDefault(x =>
                                                        StringUtils.EqualsIgnoreCase(x.AttributeName, attributeName));

                    if (column != null && (column.DataType == DataType.VarChar || column.DataType == DataType.Text))
                    {
                        query.WhereLike(column.AttributeName, $"%{value}%");
                    }
                    //else
                    //{
                    //    query.WhereLike(AttrExtendValues, $"%{attributeName}={value}%");
                    //}
                }
            }

            return(query);
        }
Ejemplo n.º 23
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            var relatedIdentities = ListUtils.GetIntList(request.RelatedIdentities);
            var style             = await _tableStyleRepository.GetTableStyleAsync(request.TableName, request.AttributeName, relatedIdentities) ?? new Models.TableStyle
            {
                InputType = InputType.Text
            };

            if (style.Items == null)
            {
                style.Items = new List <InputStyleItem>();
            }

            var isRapid     = true;
            var rapidValues = string.Empty;

            if (style.Items.Count == 0)
            {
                style.Items.Add(new InputStyleItem
                {
                    Label    = string.Empty,
                    Value    = string.Empty,
                    Selected = false
                });
            }
            else
            {
                var isSelected  = false;
                var isNotEquals = false;
                var list        = new List <string>();
                foreach (var item in style.Items)
                {
                    list.Add(item.Value);
                    if (item.Selected)
                    {
                        isSelected = true;
                    }
                    if (item.Value != item.Label)
                    {
                        isNotEquals = true;
                    }
                }

                isRapid     = !isSelected && !isNotEquals;
                rapidValues = ListUtils.ToStringByReturnAndNewline(list);
            }

            var form = new SubmitRequest
            {
                TableName         = style.TableName,
                AttributeName     = style.AttributeName,
                RelatedIdentities = request.RelatedIdentities,
                IsRapid           = isRapid,
                RapidValues       = rapidValues,
                Taxis             = style.Taxis,
                DisplayName       = style.DisplayName,
                HelpText          = style.HelpText,
                InputType         = style.InputType,
                DefaultValue      = style.DefaultValue,
                Horizontal        = style.Horizontal,
                Items             = style.Items,
                Height            = style.Height,
                CustomizeLeft     = style.CustomizeLeft,
                CustomizeRight    = style.CustomizeRight
            };

            return(new GetResult
            {
                InputTypes = InputTypeUtils.GetInputTypes(),
                Form = form
            });
        }
        public async Task <ActionResult <GetResult> > Get([FromQuery] TemplateRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, MenuUtils.SitePermissions.Templates))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            Template template;

            if (request.TemplateId > 0)
            {
                template = await _templateRepository.GetAsync(request.TemplateId);
            }
            else
            {
                template = new Template
                {
                    TemplateType = request.TemplateType
                };
            }

            var settings = await GetSettingsAsync(template, site);

            var content = Constants.Html5Empty;

            if (template.Id > 0)
            {
                content = await _pathManager.GetTemplateContentAsync(site, template);
            }
            var channel = await _channelRepository.GetAsync(request.SiteId);

            var channels = new List <Channel>();
            var cascade  = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var entity = await _channelRepository.GetAsync(summary.Id);
                channels.Add(entity);
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            var channelIds = new List <int>
            {
                request.SiteId
            };
            var channelId = 0;
            var contentId = 0;
            var contents  = new List <KeyValuePair <int, string> >();

            if (template.Id > 0 && (template.TemplateType == TemplateType.ChannelTemplate ||
                                    template.TemplateType == TemplateType.ContentTemplate))
            {
                var templateChannelIds = _channelRepository.GetChannelIdsByTemplateId(
                    template.TemplateType == TemplateType.ChannelTemplate,
                    template.Id, channels);
                if (templateChannelIds.Count > 0)
                {
                    channelId = templateChannelIds.FirstOrDefault(x => x != request.SiteId);
                    if (channelId > 0)
                    {
                        var firstChannel = await _channelRepository.GetAsync(channelId);

                        channelIds = ListUtils.GetIntList(firstChannel.ParentsPath);
                        channelIds.Add(channelId);

                        if (template.TemplateType == TemplateType.ContentTemplate)
                        {
                            var contentIds = await _contentRepository.GetContentIdsCheckedAsync(site, firstChannel);

                            foreach (var id in contentIds.Take(30))
                            {
                                if (contentId == 0)
                                {
                                    contentId = id;
                                }
                                var entity = await _contentRepository.GetAsync(site, channel, id);

                                contents.Add(new KeyValuePair <int, string>(entity.Id, entity.Title));
                            }
                        }
                    }
                }
            }

            return(new GetResult
            {
                Settings = settings,
                Content = content,
                Channels = cascade,
                ChannelIds = channelIds,
                ChannelId = channelId,
                Contents = contents,
                ContentId = contentId
            });
        }
Ejemplo n.º 25
0
        public async Task <string> GetWhereStringByStlSearchAsync(IDatabaseManager databaseManager, bool isAllSites, string siteName, string siteDir, string siteIds, string channelIndex, string channelName, string channelIds, string type, string word, string dateAttribute, string dateFrom, string dateTo, string since, int siteId, List <string> excludeAttributes, NameValueCollection form)
        {
            var whereBuilder = new StringBuilder();

            Site site = null;

            if (!string.IsNullOrEmpty(siteName))
            {
                site = await _siteRepository.GetSiteBySiteNameAsync(siteName);
            }
            else if (!string.IsNullOrEmpty(siteDir))
            {
                site = await _siteRepository.GetSiteByDirectoryAsync(siteDir);
            }
            if (site == null)
            {
                site = await _siteRepository.GetAsync(siteId);
            }

            var channelId = await _channelRepository.GetChannelIdAsync(siteId, siteId, channelIndex, channelName);

            var channel = await _channelRepository.GetAsync(channelId);

            if (isAllSites)
            {
                whereBuilder.Append("(SiteId > 0) ");
            }
            else if (!string.IsNullOrEmpty(siteIds))
            {
                whereBuilder.Append($"(SiteId IN ({TranslateUtils.ToSqlInStringWithoutQuote(ListUtils.GetIntList(siteIds))})) ");
            }
            else
            {
                whereBuilder.Append($"(SiteId = {site.Id}) ");
            }

            if (!string.IsNullOrEmpty(channelIds))
            {
                whereBuilder.Append(" AND ");
                var channelIdList = new List <int>();
                foreach (var theChannelId in ListUtils.GetIntList(channelIds))
                {
                    var theChannel = await _channelRepository.GetAsync(theChannelId);

                    channelIdList.AddRange(
                        await _channelRepository.GetChannelIdsAsync(theChannel.SiteId, theChannel.Id, ScopeType.All));
                }
                whereBuilder.Append(channelIdList.Count == 1
                    ? $"(ChannelId = {channelIdList[0]}) "
                    : $"(ChannelId IN ({TranslateUtils.ToSqlInStringWithoutQuote(channelIdList)})) ");
            }
            else if (channelId != siteId)
            {
                whereBuilder.Append(" AND ");

                var channelIdList = await _channelRepository.GetChannelIdsAsync(siteId, channelId, ScopeType.All);

                whereBuilder.Append(channelIdList.Count == 1
                    ? $"(ChannelId = {channelIdList[0]}) "
                    : $"(ChannelId IN ({TranslateUtils.ToSqlInStringWithoutQuote(channelIdList)})) ");
            }

            var typeList = new List <string>();

            if (string.IsNullOrEmpty(type))
            {
                typeList.Add(nameof(Content.Title));
            }
            else
            {
                typeList = ListUtils.GetStringList(type);
            }

            if (!string.IsNullOrEmpty(word))
            {
                whereBuilder.Append(" AND (");
                foreach (var attributeName in typeList)
                {
                    whereBuilder.Append($"[{attributeName}] LIKE '%{AttackUtils.FilterSql(word)}%' OR ");
                }
                whereBuilder.Length = whereBuilder.Length - 3;
                whereBuilder.Append(")");
            }

            if (string.IsNullOrEmpty(dateAttribute))
            {
                dateAttribute = nameof(Content.AddDate);
            }

            if (!string.IsNullOrEmpty(dateFrom))
            {
                whereBuilder.Append(" AND ");
                whereBuilder.Append($" {dateAttribute} >= {SqlUtils.GetComparableDate(_settingsManager.Database.DatabaseType, TranslateUtils.ToDateTime(dateFrom))} ");
            }
            if (!string.IsNullOrEmpty(dateTo))
            {
                whereBuilder.Append(" AND ");
                whereBuilder.Append($" {dateAttribute} <= {SqlUtils.GetComparableDate(_settingsManager.Database.DatabaseType, TranslateUtils.ToDateTime(dateTo))} ");
            }
            if (!string.IsNullOrEmpty(since))
            {
                var sinceDate = DateTime.Now.AddHours(-DateUtils.GetSinceHours(since));
                whereBuilder.Append($" AND {dateAttribute} BETWEEN {SqlUtils.GetComparableDateTime(_settingsManager.Database.DatabaseType, sinceDate)} AND {SqlUtils.GetComparableNow(_settingsManager.Database.DatabaseType)} ");
            }

            var tableName = _channelRepository.GetTableName(site, channel);

            //var styleInfoList = RelatedIdentities.GetTableStyleInfoList(site, channel.Id);

            foreach (string key in form.Keys)
            {
                if (ListUtils.ContainsIgnoreCase(excludeAttributes, key))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(form[key]))
                {
                    continue;
                }

                var value = StringUtils.Trim(form[key]);
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                var columnInfo = await databaseManager.GetTableColumnInfoAsync(tableName, key);

                if (columnInfo != null && (columnInfo.DataType == DataType.VarChar || columnInfo.DataType == DataType.Text))
                {
                    whereBuilder.Append(" AND ");
                    whereBuilder.Append($"({key} LIKE '%{value}%')");
                }
                //else
                //{
                //    foreach (var tableStyleInfo in styleInfoList)
                //    {
                //        if (StringUtils.EqualsIgnoreCase(tableStyleInfo.AttributeName, key))
                //        {
                //            whereBuilder.Append(" AND ");
                //            whereBuilder.Append($"({ContentAttribute.SettingsXml} LIKE '%{key}={value}%')");
                //            break;
                //        }
                //    }
                //}
            }

            return(whereBuilder.ToString());
        }