Ejemplo n.º 1
0
 public void SetGroupFilterSortingOnForms(GroupFilterVM gf)
 {
     ViewGroupsForms.SortDescriptions.Clear();
     if (gf != null)
     {
         List <SortDescription> sortlist = GroupFilterHelper.GetSortDescriptions(gf);
         foreach (SortDescription sd in sortlist)
         {
             ViewGroupsForms.SortDescriptions.Add(sd);
         }
     }
 }
Ejemplo n.º 2
0
        public static bool DialogSelectGFQuickSort(ref string sortType, ref GroupFilterSortDirection sortDirection, string previousMenu)
        {
            //show the selection dialog
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return(false);
            }

            List <string> sortTypes = GroupFilterHelper.GetQuickSortTypes();

            while (true)
            {
                dlg.Reset();

                dlg.SetHeading(Translation.QuickSort);

                dlg.Add("<<< " + previousMenu);

                string menu = string.Format("{1} ({0}) >>>", sortDirection == GroupFilterSortDirection.Asc ? Translation.Asc : Translation.Desc, Translation.SortDirection);

                dlg.Add(menu);

                int index = 0;
                foreach (string srt in sortTypes)
                {
                    dlg.Add(srt);
                    index++;
                }

                dlg.DoModal(GUIWindowManager.ActiveWindow);
                int selection = dlg.SelectedLabel;

                if (selection <= 0)
                {
                    return(true);
                }

                if (selection == 1)
                {
                    DialogSelectGFQuickSortDirection(ref sortDirection, Translation.QuickSort);
                    // display quick sort again
                }
                else
                {
                    sortType = sortTypes[selection - 2];
                    return(false);
                }
            }
        }
        void cboConditionType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());

            cboConditionOperator.Items.Clear();
            foreach (string op in GroupFilterHelper.GetAllowedOperators(conditionType))
            {
                cboConditionOperator.Items.Add(op);
            }

            cboConditionOperator.SelectedIndex = 0;

            EvaluateConditionsAndOperators();
        }
Ejemplo n.º 4
0
        void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (cboSortType.Items.Count == 0)
            {
                this.DialogResult = false;
                this.Close();
            }

            // get the details from the form
            groupFilterSortingCriteria.GroupFilterID = groupFilter.GroupFilterID;
            groupFilterSortingCriteria.SortType      = GroupFilterHelper.GetEnumForText_Sorting(cboSortType.SelectedItem.ToString());
            groupFilterSortingCriteria.SortDirection = GroupFilterHelper.GetEnumForText_SortDirection(cboDirection.SelectedItem.ToString());

            this.DialogResult = true;
            this.Close();
        }
Ejemplo n.º 5
0
        public void Init(GroupFilterVM gf, GroupFilterSortingCriteria gfsc)
        {
            groupFilter = gf;
            groupFilterSortingCriteria = gfsc;

            try
            {
                cboSortType.Items.Clear();
                foreach (string stype in GroupFilterHelper.GetAllSortTypes())
                {
                    if (gf != null)
                    {
                        bool alreadyExists = false;
                        foreach (GroupFilterSortingCriteria gfsc_old in gf.SortCriteriaList)
                        {
                            if (GroupFilterHelper.GetTextForEnum_Sorting(gfsc_old.SortType) == stype)
                            {
                                alreadyExists = true;
                                break;
                            }
                        }

                        if (!alreadyExists)
                        {
                            cboSortType.Items.Add(stype);
                        }
                    }
                }
                if (cboSortType.Items.Count > 0)
                {
                    cboSortType.SelectedIndex = 0;
                }



                cboDirection.Items.Clear();
                cboDirection.Items.Add(GroupFilterHelper.GetTextForEnum_SortDirection(GroupFilterSortDirection.Asc));
                cboDirection.Items.Add(GroupFilterHelper.GetTextForEnum_SortDirection(GroupFilterSortDirection.Desc));
                cboDirection.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Ejemplo n.º 6
0
 //[LogExecutionTime]
 public void SetGroupFilterSortingOnMainList()
 {
     if (CurrentWrapper is GroupFilterVM)
     {
         GroupFilterVM gf = CurrentWrapper as GroupFilterVM;
         ViewGroups.SortDescriptions.Clear();
         if (gf != null)
         {
             List <SortDescription> sortlist = GroupFilterHelper.GetSortDescriptions(gf);
             foreach (SortDescription sd in sortlist)
             {
                 ViewGroups.SortDescriptions.Add(sd);
             }
         }
     }
     else
     {
         ViewGroups.SortDescriptions.Clear();
     }
 }
        public void Init(GroupFilterVM gf, GroupFilterConditionVM gfc)
        {
            groupFilter          = gf;
            groupFilterCondition = gfc;


            try
            {
                cboConditionType.Items.Clear();
                foreach (string cond in GroupFilterHelper.GetAllConditionTypes())
                {
                    cboConditionType.Items.Add(cond);
                }

                PopulateAnimeGroups();
                PopulateTags();
                PopulateCustomTags();
                PopulateVideoQuality();
                PopulateAnimeTypes();
                PopulateLanguages();

                // find the right condition
                int idx = 0;
                for (int i = 0; i < cboConditionType.Items.Count; i++)
                {
                    GroupFilterConditionType conditionTypeTemp = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.Items[i].ToString());
                    if (conditionTypeTemp == gfc.ConditionTypeEnum)
                    {
                        idx = i;
                        break;
                    }
                }
                cboConditionType.SelectedIndex = idx;
                GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());

                cboConditionOperator.Items.Clear();
                foreach (string op in GroupFilterHelper.GetAllowedOperators(conditionType))
                {
                    cboConditionOperator.Items.Add(op);
                }

                cboConditionType.SelectionChanged     += new SelectionChangedEventHandler(cboConditionType_SelectionChanged);
                cboConditionOperator.SelectionChanged += new SelectionChangedEventHandler(cboConditionOperator_SelectionChanged);

                // find the right operator
                idx = 0;
                for (int i = 0; i < cboConditionOperator.Items.Count; i++)
                {
                    GroupFilterOperator opTypeTemp = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.Items[i].ToString());
                    if (opTypeTemp == gfc.ConditionOperatorEnum)
                    {
                        idx = i;
                        break;
                    }
                }
                cboConditionOperator.SelectedIndex = idx;
                GroupFilterOperator opType = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.Items[idx].ToString());

                // display the selected filter value
                switch (conditionType)
                {
                case GroupFilterConditionType.AirDate:
                case GroupFilterConditionType.SeriesCreatedDate:
                case GroupFilterConditionType.EpisodeAddedDate:
                case GroupFilterConditionType.EpisodeWatchedDate:
                case GroupFilterConditionType.LatestEpisodeAirDate:

                    if (opType == GroupFilterOperator.LastXDays)
                    {
                        txtParameter.Text = gfc.ConditionParameter;
                    }
                    else
                    {
                        DateTime airDate = GroupFilterHelper.GetDateFromString(gfc.ConditionParameter);
                        dpDate.SelectedDate = airDate;
                    }
                    break;

                case GroupFilterConditionType.AnimeGroup:

                    // don't display anything
                    break;

                case GroupFilterConditionType.AnimeType:
                case GroupFilterConditionType.Tag:
                case GroupFilterConditionType.CustomTags:
                case GroupFilterConditionType.ReleaseGroup:
                case GroupFilterConditionType.Studio:
                case GroupFilterConditionType.VideoQuality:
                case GroupFilterConditionType.AniDBRating:
                case GroupFilterConditionType.UserRating:
                case GroupFilterConditionType.AudioLanguage:
                case GroupFilterConditionType.SubtitleLanguage:
                case GroupFilterConditionType.Year:
                    txtParameter.Text = gfc.ConditionParameter;
                    break;
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
        private void EvaluateConditionsAndOperators()
        {
            if (cboConditionType.SelectedItem == null || cboConditionOperator.SelectedItem == null)
            {
                return;
            }

            GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
            GroupFilterOperator      opType        = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.SelectedItem.ToString());

            IsParameterDate             = false;
            IsParameterAnimeGroup       = false;
            IsParameterAnimeType        = false;
            IsParameterText             = false;
            IsParameterInNotIn          = false;
            IsParameterTag              = false;
            IsParameterCustomTag        = false;
            IsParameterRating           = false;
            IsParameterLastXDays        = false;
            IsParameterVideoQuality     = false;
            IsParameterAudioLanguage    = false;
            IsParameterSubtitleLanguage = false;
            IsParameterInteger          = false;

            switch (conditionType)
            {
            case GroupFilterConditionType.AirDate:
            case GroupFilterConditionType.SeriesCreatedDate:
            case GroupFilterConditionType.EpisodeAddedDate:
            case GroupFilterConditionType.EpisodeWatchedDate:
            case GroupFilterConditionType.LatestEpisodeAirDate:
                if (opType == GroupFilterOperator.LastXDays)
                {
                    IsParameterLastXDays = true;
                    IsParameterText      = true;
                }
                else
                {
                    IsParameterDate = true;
                }
                break;

            case GroupFilterConditionType.AnimeGroup:
                IsParameterAnimeGroup = true;
                break;

            case GroupFilterConditionType.AnimeType:
                IsParameterAnimeType = true; break;

            case GroupFilterConditionType.ReleaseGroup:
            case GroupFilterConditionType.Studio:
                IsParameterInNotIn = true; break;

            case GroupFilterConditionType.Tag:
                IsParameterInNotIn = true;
                IsParameterTag     = true;
                break;

            case GroupFilterConditionType.CustomTags:
                IsParameterInNotIn   = true;
                IsParameterCustomTag = true;
                break;

            case GroupFilterConditionType.AudioLanguage:
                IsParameterInNotIn       = true;
                IsParameterAudioLanguage = true;
                break;

            case GroupFilterConditionType.SubtitleLanguage:
                IsParameterInNotIn          = true;
                IsParameterSubtitleLanguage = true;
                break;

            case GroupFilterConditionType.Year:
                IsParameterInNotIn = true;
                break;

            case GroupFilterConditionType.VideoQuality:
                IsParameterInNotIn      = true;
                IsParameterVideoQuality = true;
                break;

            case GroupFilterConditionType.AniDBRating:
            case GroupFilterConditionType.UserRating:
                IsParameterText   = true;
                IsParameterRating = true;
                break;

            case GroupFilterConditionType.EpisodeCount:
                IsParameterText    = true;
                IsParameterInteger = true;
                break;
            }
        }
        void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            // get the details from the form
            groupFilterCondition.ConditionType     = (int)GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
            groupFilterCondition.ConditionOperator = (int)GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.SelectedItem.ToString());

            NumberStyles style   = NumberStyles.Number;
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-GB");


            // get the parameter details
            if (IsParameterDate)
            {
                if (dpDate.SelectedDate == null)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_SelectDate, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    dpDate.Focus();
                    return;
                }
                else
                {
                    groupFilterCondition.ConditionParameter = GroupFilterHelper.GetDateAsString(dpDate.SelectedDate.Value);
                }
            }

            if (IsParameterRating)
            {
                if (txtParameter.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    decimal dRating = -1;
                    decimal.TryParse(txtParameter.Text, style, culture, out dRating);
                    if (dRating <= 0 || dRating > 10)
                    {
                        MessageBox.Show(Properties.Resources.MSG_ERR_RatingValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        txtParameter.Focus();
                        return;
                    }

                    groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
                }
            }

            if (IsParameterInteger)
            {
                if (txtParameter.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    int parmInt = -1;
                    if (!int.TryParse(txtParameter.Text, out parmInt))
                    {
                        MessageBox.Show(Properties.Resources.GroupFilter_IntegerOnly, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        txtParameter.Focus();
                        return;
                    }

                    groupFilterCondition.ConditionParameter = parmInt.ToString();
                }
            }

            if (IsParameterLastXDays)
            {
                if (txtParameter.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    int days = -1;
                    int.TryParse(txtParameter.Text, out days);
                    if (days < 1 || days > int.MaxValue)
                    {
                        MessageBox.Show(Properties.Resources.MSG_ERR_DaysValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        txtParameter.Focus();
                        return;
                    }

                    groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
                }
            }


            if (IsParameterTag)
            {
                if (txtSelectedTags.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] cats = txtSelectedTags.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string cat in cats)
                    {
                        if (cat.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (cat.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += cat;
                    }
                }
            }

            if (IsParameterCustomTag)
            {
                if (txtSelectedCustomTags.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtSelectedCustomTags.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] tags = txtSelectedCustomTags.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string tag in tags)
                    {
                        if (tag.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (tag.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += tag;
                    }
                }
            }

            if (IsParameterVideoQuality)
            {
                if (txtSelectedVideoQuality.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] vidQuals = txtSelectedVideoQuality.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string vidq in vidQuals)
                    {
                        if (vidq.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (vidq.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += vidq;
                    }
                }
            }

            if (IsParameterAudioLanguage)
            {
                if (txtSelectedAudioLanguages.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] languages = txtSelectedAudioLanguages.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string lanName in languages)
                    {
                        if (lanName.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (lanName.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += lanName;
                    }
                }
            }

            if (IsParameterSubtitleLanguage)
            {
                if (txtSelectedSubtitleLanguages.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] languages = txtSelectedSubtitleLanguages.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string lanName in languages)
                    {
                        if (lanName.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (lanName.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += lanName;
                    }
                }
            }

            if (IsParameterAnimeType)
            {
                if (txtSelectedAnimeTypes.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    // validate
                    string[] aTypes = txtSelectedAnimeTypes.Text.Trim().Split(',');
                    groupFilterCondition.ConditionParameter = "";
                    foreach (string aType in aTypes)
                    {
                        if (aType.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (aType.Trim() == ", ")
                        {
                            continue;
                        }

                        if (groupFilterCondition.ConditionParameter.Length > 0)
                        {
                            groupFilterCondition.ConditionParameter += ", ";
                        }
                        groupFilterCondition.ConditionParameter += aType;
                    }
                }
            }

            if (IsParameterAnimeGroup)
            {
                if (lbGroups.SelectedItem == null)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_GroupSelectionRequired, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    lbGroups.Focus();
                    return;
                }
                else
                {
                    AnimeGroupVM grp = lbGroups.SelectedItem as AnimeGroupVM;
                    groupFilterCondition.ConditionParameter = grp.AnimeGroupID.Value.ToString();
                }
            }

            if (IsParameterText)
            {
                if (txtParameter.Text.Trim().Length == 0)
                {
                    MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                    txtParameter.Focus();
                    return;
                }
                else
                {
                    groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
                }
            }

            this.DialogResult = true;
            this.Close();
        }
Ejemplo n.º 10
0
        internal new static Filter GenerateFromGroupFilter(HttpContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                           bool all, bool allpic, int pic, TagFilter.Filter tagfilter)
        {
            List <Group> groups = new List <Group>();
            Filter       filter = new Filter
            {
                name = gf.GroupFilterName,
                id   = gf.GroupFilterID,
                size = 0
            };

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;

                    // Populate Random Art
                    List <SVR_AnimeGroup> groupsList;

                    List <SVR_AnimeSeries> arts = null;
                    if (gf.SeriesIds.ContainsKey(uid))
                    {
                        var seriesList = gf.SeriesIds[uid].Select(Repo.Instance.AnimeSeries.GetByID).ToList();
                        groupsList = seriesList.Select(a => a.AnimeGroupID).Distinct()
                                     .Select(Repo.Instance.AnimeGroup.GetByID).ToList();
                        if (pic == 1)
                        {
                            arts = seriesList.Where(SeriesHasCompleteArt).Where(a => a != null).ToList();
                            if (arts.Count == 0)
                            {
                                arts = seriesList.Where(SeriesHasMostlyCompleteArt).Where(a => a != null).ToList();
                            }
                            if (arts.Count == 0)
                            {
                                arts = seriesList;
                            }
                        }
                    }
                    else
                    {
                        groupsList = new List <SVR_AnimeGroup>();
                    }

                    if (arts?.Count > 0)
                    {
                        Random rand  = new Random();
                        var    anime = arts[rand.Next(arts.Count)];

                        var fanarts = GetFanartFromSeries(anime);
                        if (fanarts.Any())
                        {
                            var fanart = fanarts[rand.Next(fanarts.Count)];
                            filter.art.fanart.Add(new Art
                            {
                                index = 0,
                                url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_FanArt,
                                                                                  fanart.TvDB_ImageFanartID)
                            });
                        }

                        var banners = GetBannersFromSeries(anime);
                        if (banners.Any())
                        {
                            var banner = banners[rand.Next(banners.Count)];
                            filter.art.banner.Add(new Art()
                            {
                                index = 0,
                                url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Banner,
                                                                                  banner.TvDB_ImageWideBannerID)
                            });
                        }

                        filter.art.thumb.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.AniDB_Cover,
                                                                            anime.AniDB_ID),
                            index = 0
                        });
                    }

                    Dictionary <CL_AnimeGroup_User, Group> order = new Dictionary <CL_AnimeGroup_User, Group>();
                    if (level > 0)
                    {
                        foreach (SVR_AnimeGroup ag in groupsList)
                        {
                            Group group =
                                Group.GenerateFromAnimeGroup(ctx, ag, uid, nocast, notag, (level - 1), all,
                                                             filter.id, allpic, pic, tagfilter);
                            groups.Add(group);
                            order.Add(ag.GetUserContract(uid), group);
                        }
                    }

                    if (groups.Count > 0)
                    {
                        // Proper Sorting!
                        IEnumerable <CL_AnimeGroup_User> grps = order.Keys;
                        grps = gf.SortCriteriaList.Count != 0
                            ? GroupFilterHelper.Sort(grps, gf)
                            : grps.OrderBy(a => a.GroupName);
                        groups        = grps.Select(a => order[a]).ToList();
                        filter.groups = groups;
                    }
                }
            }

            filter.viewed = 0;
            filter.url    = APIHelper.ConstructFilterIdUrl(ctx, filter.id);

            return(filter);
        }
Ejemplo n.º 11
0
 public static List <VM_GroupFilter> GetChildFilters(VM_GroupFilter pre)
 {
     return(GroupFilterHelper.GetChildGroupFilters(pre));
 }
Ejemplo n.º 12
0
 public static List <VM_GroupFilter> GetTopLevelGroupFilters()
 {
     return(GroupFilterHelper.GetTopLevelGroupFilters());
 }
Ejemplo n.º 13
0
        internal static Filter GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                       bool all, bool allpic, int pic, byte tagfilter)
        {
            List <Group> groups = new List <Group>();
            Filter       filter = new Filter
            {
                name = gf.GroupFilterName,
                id   = gf.GroupFilterID,
                size = 0
            };

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;

                    // Populate Random Art
                    List <SVR_AnimeGroup> groupsList;

                    List <CL_AniDB_Anime> arts;
                    if (gf.ApplyToSeries == 1 && gf.SeriesIds.ContainsKey(uid))
                    {
                        var seriesList = gf.SeriesIds[uid].Select(RepoFactory.AnimeSeries.GetByID).ToList();
                        groupsList = seriesList.Select(a => a.AnimeGroupID).Distinct()
                                     .Select(RepoFactory.AnimeGroup.GetByID).ToList();
                        arts = seriesList.Where(SeriesHasCompleteArt).Select(a => a?.GetAnime()?.Contract?.AniDBAnime)
                               .Where(a => a != null).ToList();
                        if (arts.Count == 0)
                        {
                            arts = seriesList.Where(SeriesHasMostlyCompleteArt)
                                   .Select(a => a?.GetAnime()?.Contract?.AniDBAnime).Where(a => a != null).ToList();
                        }
                        if (arts.Count == 0)
                        {
                            arts = seriesList.Select(a => a?.GetAnime()?.Contract?.AniDBAnime).Where(a => a != null)
                                   .ToList();
                        }
                    }
                    else
                    {
                        groupsList = groupsh.Select(a => RepoFactory.AnimeGroup.GetByID(a))
                                     .Where(a => a != null)
                                     .ToList();
                        arts = groupsList.Where(GroupHasCompleteArt).Select(GetAnimeContractFromGroup).ToList();
                        if (arts.Count == 0)
                        {
                            arts = groupsList.Where(GroupHasMostlyCompleteArt).Select(GetAnimeContractFromGroup)
                                   .ToList();
                        }
                        if (arts.Count == 0)
                        {
                            arts = groupsList.Where(a => (a.Anime?.Count ?? 0) > 0).Select(GetAnimeContractFromGroup)
                                   .ToList();
                        }
                    }

                    if (arts.Count > 0)
                    {
                        Random rand  = new Random();
                        var    anime = arts[rand.Next(arts.Count)];

                        if (anime.Fanarts?.Count > 0)
                        {
                            var fanart = anime.Fanarts[rand.Next(anime.Fanarts.Count)];
                            filter.art.fanart.Add(new Art
                            {
                                index = 0,
                                url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, fanart.ImageType,
                                                                                  fanart.AniDB_Anime_DefaultImageID)
                            });
                        }

                        if (anime.Banners?.Count > 0)
                        {
                            var banner = anime.Banners[rand.Next(anime.Banners.Count)];
                            filter.art.banner.Add(new Art()
                            {
                                index = 0,
                                url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, banner.ImageType,
                                                                                  banner.AniDB_Anime_DefaultImageID)
                            });
                        }

                        filter.art.thumb.Add(new Art()
                        {
                            url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.AniDB_Cover,
                                                                            anime.AnimeID),
                            index = 0
                        });
                    }

                    Dictionary <CL_AnimeGroup_User, Group> order = new Dictionary <CL_AnimeGroup_User, Group>();
                    if (level > 0)
                    {
                        foreach (SVR_AnimeGroup ag in groupsList)
                        {
                            Group group =
                                Group.GenerateFromAnimeGroup(ctx, ag, uid, nocast, notag, (level - 1), all,
                                                             filter.id, allpic, pic, tagfilter);
                            groups.Add(group);
                            order.Add(ag.GetUserContract(uid), group);
                        }
                    }

                    if (groups.Count > 0)
                    {
                        // Proper Sorting!
                        IEnumerable <CL_AnimeGroup_User> grps = order.Keys;
                        grps = gf.SortCriteriaList.Count != 0
                            ? GroupFilterHelper.Sort(grps, gf)
                            : grps.OrderBy(a => a.GroupName);
                        groups        = grps.Select(a => order[a]).ToList();
                        filter.groups = groups;
                    }
                }
            }

            filter.viewed = 0;
            filter.url    = APIHelper.ConstructFilterIdUrl(ctx, filter.id);

            return(filter);
        }
Ejemplo n.º 14
0
        internal static Filter GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                       bool all, bool allpic, int pic)
        {
            List <Group> groups = new List <Group>();
            Filter       filter = new Filter
            {
                name = gf.GroupFilterName,
                id   = gf.GroupFilterID,
                size = 0
            };

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;

                    // Populate Random Art
                    List <SVR_AnimeGroup> groupsList = groupsh.Select(a => RepoFactory.AnimeGroup.GetByID(a))
                                                       .Where(a => a != null)
                                                       .ToList();

                    List <Video> arts = groupsList.Select(a => a.GetPlexContract(uid)).Where(contract =>
                    {
                        if (!(contract.Fanarts?.Any() ?? false))
                        {
                            return(false);
                        }
                        if (!(contract.Banners?.Any() ?? false))
                        {
                            return(false);
                        }
                        return(!string.IsNullOrEmpty(contract.Art));
                    }).ToList();

                    if (arts.Count > 0)
                    {
                        Random rand   = new Random();
                        Video  art    = arts[rand.Next(arts.Count)];
                        var    fanart = art.Fanarts[rand.Next(art.Fanarts.Count)];
                        filter.art.fanart.Add(new Art()
                        {
                            index = 0,
                            url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, fanart.ImageType, fanart.ImageID)
                        });
                        var banner = art.Banners[rand.Next(art.Banners.Count)];
                        filter.art.banner.Add(new Art()
                        {
                            index = 0,
                            url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, banner.ImageType, banner.ImageID)
                        });
                        filter.art.thumb.Add(new Art()
                        {
                            index = 0,
                            url   = APIHelper.ConstructImageLinkFromRest(ctx, art.Thumb)
                        });
                    }

                    Dictionary <CL_AnimeGroup_User, Group> order = new Dictionary <CL_AnimeGroup_User, Group>();
                    if (level > 0)
                    {
                        foreach (SVR_AnimeGroup ag in groupsList)
                        {
                            Group group =
                                Group.GenerateFromAnimeGroup(ctx, ag, uid, nocast, notag, (level - 1), all,
                                                             filter.id, allpic, pic);
                            groups.Add(group);
                            order.Add(ag.GetUserContract(uid), group);
                        }
                    }

                    if (groups.Count > 0)
                    {
                        // Proper Sorting!
                        IEnumerable <CL_AnimeGroup_User> grps = order.Keys;
                        grps = gf.SortCriteriaList.Count != 0
                            ? GroupFilterHelper.Sort(grps, gf)
                            : grps.OrderBy(a => a.GroupName);
                        groups        = grps.Select(a => order[a]).ToList();
                        filter.groups = groups;
                    }
                }
            }

            filter.viewed = 0;
            filter.url    = APIHelper.ConstructFilterIdUrl(ctx, filter.id);

            return(filter);
        }
Ejemplo n.º 15
0
        internal static Filter GenerateFromGroupFilter(NancyContext ctx, SVR_GroupFilter gf, int uid, bool nocast, bool notag, int level,
                                                       bool all)
        {
            List <Group> groups = new List <Group>();
            Filter       filter = new Filter();

            filter.name = gf.GroupFilterName;
            filter.id   = gf.GroupFilterID;
            filter.size = 0;

            if (gf.GroupsIds.ContainsKey(uid))
            {
                HashSet <int> groupsh = gf.GroupsIds[uid];
                if (groupsh.Count != 0)
                {
                    filter.size = groupsh.Count;

                    int rand_art_iteration = 0;

                    // Populate Random Art
                    while (rand_art_iteration < 3)
                    {
                        int            index    = new Random().Next(groupsh.Count);
                        SVR_AnimeGroup randGrp  = Repositories.RepoFactory.AnimeGroup.GetByID(groupsh.ToList()[index]);
                        Video          contract = randGrp?.GetPlexContract(uid);
                        if (contract != null)
                        {
                            Random rand = new Random();
                            Contract_ImageDetails art = new Contract_ImageDetails();
                            // contract.Fanarts can be null even if contract isn't
                            if (contract.Fanarts != null && contract.Fanarts.Count > 0)
                            {
                                art = contract.Fanarts[rand.Next(contract.Fanarts.Count)];
                                filter.art.fanart.Add(new Art()
                                {
                                    url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                                    index = 0
                                });
                                rand_art_iteration = 3;

                                // we only want banner if we have fanart, other way will desync images
                                if (contract.Banners != null && contract.Banners.Count > 0)
                                {
                                    art = contract.Banners[rand.Next(contract.Banners.Count)];
                                    filter.art.banner.Add(new Art()
                                    {
                                        url   = APIHelper.ConstructImageLinkFromTypeAndId(ctx, art.ImageType, art.ImageID),
                                        index = 0
                                    });
                                    if (!string.IsNullOrEmpty(contract.Thumb))
                                    {
                                        filter.art.thumb.Add(new Art()
                                        {
                                            url   = APIHelper.ConstructImageLinkFromRest(ctx, contract.Thumb),
                                            index = 0
                                        });
                                    }
                                }
                            }
                        }
                        rand_art_iteration++;
                    }

                    Dictionary <CL_AnimeGroup_User, Group> order = new Dictionary <CL_AnimeGroup_User, Group>();
                    if (level > 0)
                    {
                        foreach (int gp in groupsh)
                        {
                            SVR_AnimeGroup ag = Repositories.RepoFactory.AnimeGroup.GetByID(gp);
                            if (ag == null)
                            {
                                continue;
                            }
                            Group group =
                                Group.GenerateFromAnimeGroup(ctx, ag, uid, nocast, notag, (level - 1), all,
                                                             filter.id);
                            groups.Add(group);
                            order.Add(ag.GetUserContract(uid), group);
                        }
                    }

                    if (groups.Count > 0)
                    {
                        // Proper Sorting!
                        IEnumerable <CL_AnimeGroup_User> grps = order.Keys;
                        grps = gf.SortCriteriaList.Count != 0
                            ? GroupFilterHelper.Sort(grps, gf)
                            : grps.OrderBy(a => a.GroupName);
                        groups        = grps.Select(a => order[a]).ToList();
                        filter.groups = groups;
                    }
                }
            }

            filter.viewed = 0;
            filter.url    = APIHelper.ConstructFilterIdUrl(ctx, filter.id);

            return(filter);
        }