Пример #1
0
        internal static Filters GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, bool all,
                                                        int level)
        {
            Filters f = new Filters();

            f.id   = gf.GroupFilterID;
            f.name = gf.GroupFilterName;

            List <Filter>          filters = new List <Filter>();
            List <SVR_GroupFilter> allGfs  = RepoFactory.GroupFilter.GetByParentID(f.id)
                                             .Where(a => a.InvisibleInClients == 0 &&
                                                    ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) ||
                                                     (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory))
                                             .ToList();

            foreach (SVR_GroupFilter cgf in allGfs)
            {
                // any level higher than 1 can drain cpu
                filters.Add(Filter.GenerateFromGroupFilter(ctx, cgf, uid, nocast, notag, level - 1, all));
            }

            f.filters = filters.OrderBy(a => a.name).ToList <Filter>();
            f.size    = f.filters.Count();
            f.url     = APIHelper.ConstructFilterIdUrl(ctx, f.id);

            return(f);
        }
Пример #2
0
        internal static Filters GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, bool all,
            int level, bool allpic, int pic, byte tagfilter)
        {
            Filters f = new Filters
            {
                id = gf.GroupFilterID,
                name = gf.GroupFilterName
            };
            List<SVR_GroupFilter> allGfs = RepoFactory.GroupFilter.GetByParentID(f.id)
                .Where(a => a.InvisibleInClients == 0 &&
                            ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) ||
                             (a.FilterType & (int) GroupFilterType.Directory) == (int) GroupFilterType.Directory))
                .ToList();
            List<Filter> filters = allGfs
                .Where(cgf =>
                    (cgf.FilterType & (int) GroupFilterType.Tag) != (int) GroupFilterType.Tag ||
                    TagFilter.ProcessTags(tagfilter, new List<string> {cgf.GroupFilterName}).Count != 0)
                .Select(cgf =>
                    Filter.GenerateFromGroupFilter(ctx, cgf, uid, nocast, notag, level - 1, all, allpic, pic,
                        tagfilter)).ToList();

            if (gf.FilterType == ((int)GroupFilterType.Season | (int)GroupFilterType.Directory))
                f.filters = filters.OrderBy(a => a.name, new SeasonComparator()).ToList();
            else
                f.filters = filters.OrderByNatural(a => a.name).ToList();

            f.size = f.filters.Count();
            f.url = APIHelper.ConstructFilterIdUrl(ctx, f.id);

            return f;
        }
Пример #3
0
        internal static Filters GenerateFromGroupFilter(HttpContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                        bool all, bool allpic, int pic, TagFilter.Filter tagfilter)
        {
            Filters f = new Filters
            {
                id   = gf.GroupFilterID,
                name = gf.GroupFilterName
            };

            var _   = new List <string>();
            var gfs = RepoFactory.GroupFilter.GetByParentID(f.id).AsParallel()
                      // Not invisible in clients
                      .Where(a => a.InvisibleInClients == 0 &&
                      // and Has groups or is a directory
                             ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) ||
                              (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory) &&
                             // and is not a blacklisted tag
                             !((a.FilterType & (int)GroupFilterType.Tag) != 0 &&
                               TagFilter.IsTagBlackListed(a.GroupFilterName, tagfilter)));

            if (level > 0)
            {
                var filters = gfs.Select(cgf =>
                                         Filter.GenerateFromGroupFilter(ctx, cgf, uid, nocast, notag, level - 1, all, allpic, pic,
                                                                        tagfilter)).ToList();

                if (gf.FilterType == ((int)GroupFilterType.Season | (int)GroupFilterType.Directory))
                {
                    f.filters = filters.OrderBy(a => a.name, new SeasonComparator()).Cast <Filters>().ToList();
                }
                else
                {
                    f.filters = filters.OrderByNatural(a => a.name).Cast <Filters>().ToList();
                }
                f.size = filters.Count;
            }
            else
            {
                f.size = gfs.Count();
            }

            f.url = APIV2Helper.ConstructFilterIdUrl(ctx, f.id);

            return(f);
        }
Пример #4
0
        internal static Filters GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, bool all,
                                                        int level, bool allpic, int pic, byte tagfilter)
        {
            Filters f = new Filters
            {
                id   = gf.GroupFilterID,
                name = gf.GroupFilterName
            };
            List <Filter>          filters = new List <Filter>();
            List <SVR_GroupFilter> allGfs  = RepoFactory.GroupFilter.GetByParentID(f.id)
                                             .Where(a => a.InvisibleInClients == 0 &&
                                                    ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) ||
                                                     (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory))
                                             .ToList();

            foreach (SVR_GroupFilter cgf in allGfs)
            {
                // any level higher than 1 can drain cpu
                if ((cgf.FilterType & (int)GroupFilterType.Tag) == (int)GroupFilterType.Tag &&
                    TagFilter.ProcessTags(tagfilter, new List <string> {
                    cgf.GroupFilterName
                }).Count == 0)
                {
                    continue;
                }

                filters.Add(Filter.GenerateFromGroupFilter(ctx, cgf, uid, nocast, notag, level - 1, all, allpic, pic, tagfilter));
            }

            if (gf.FilterType == ((int)GroupFilterType.Season | (int)GroupFilterType.Directory))
            {
                f.filters = filters.OrderBy(a => a.name, new SeasonComparator()).ToList();
            }
            else
            {
                f.filters = filters.OrderByNatural(a => a.name).ToList();
            }

            f.size = f.filters.Count();
            f.url  = APIHelper.ConstructFilterIdUrl(ctx, f.id);

            return(f);
        }
Пример #5
0
        internal static Filters GenerateFromGroupFilter(HttpContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                        bool all, bool allpic, int pic, TagFilter.Filter tagfilter)
        {
            Filters f = new Filters
            {
                id   = gf.GroupFilterID,
                name = gf.GroupFilterName
            };

            var _   = new List <string>();
            var gfs = Repo.Instance.GroupFilter.GetByParentID(f.id).AsParallel()
                      // Not invisible in clients
                      .Where(a => a.InvisibleInClients == 0 &&
                      // and Has groups or is a directory
                             ((a.GroupsIds.ContainsKey(uid) && a.GroupsIds[uid].Count > 0) ||
                              (a.FilterType & (int)GroupFilterType.Directory) == (int)GroupFilterType.Directory) &&
                             // and is not a blacklisted tag
                             !((a.FilterType & (int)GroupFilterType.Tag) != 0 &&
                               TagFilter.IsTagBlackListed(a.GroupFilterName, tagfilter, ref _)));

            if (_.Count > 0)
            {
                gfs = gfs.Concat(_.Select(tag => Repo.Instance.GroupFilter.GetAll().FirstOrDefault(a =>
                {
                    if (a.FilterType != (int)GroupFilterType.Tag)
                    {
                        return(false);
                    }
                    if (tag.Equals("Original Work"))
                    {
                        return(a.GroupFilterName.Equals("new"));
                    }

                    return(a.GroupFilterName.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
                })).AsParallel());
            }

            if (level > 0)
            {
                var filters = gfs.Select(cgf =>
                                         Filter.GenerateFromGroupFilter(ctx, cgf, uid, nocast, notag, level - 1, all, allpic, pic,
                                                                        tagfilter)).ToList();

                if (gf.FilterType == ((int)GroupFilterType.Season | (int)GroupFilterType.Directory))
                {
                    f.filters = filters.OrderBy(a => a.name, new SeasonComparator()).Cast <Filters>().ToList();
                }
                else
                {
                    f.filters = filters.OrderByNatural(a => a.name).Cast <Filters>().ToList();
                }
                f.size = filters.Count;
            }
            else
            {
                f.size = gfs.Count();
            }

            f.url = APIHelper.ConstructFilterIdUrl(ctx, f.id);

            return(f);
        }