コード例 #1
0
        /// <summary>
        /// 获取满足当前条件的歌曲
        /// </summary>
        /// <param name="ratingList"></param>
        /// <param name="ratingClass"></param>
        /// <returns></returns>
        public List <PluginArcaeaSong> GetSatisfiedSong(List <string> ratingList = null, PluginArcaeaSong.RatingClass ratingClass = PluginArcaeaSong.RatingClass.Random)
        {
            if (_kouContext.Set <PluginArcaeaSong>().IsNullOrEmptySet())
            {
                return(null);
            }
            //处理限定难度信息
            if (ratingList.IsNullOrEmptySet())
            {
                MultiSelectionHelper.TryGetMultiSelections(Rating, out ratingList, @"^(11|10|[1-9])\+?$");
            }
            //处理限定难度类型信息
            Regex regex = new Regex("(,|,)?(ftr|pst|prs|byd|byn|future|past|present|beyond|all)(,|,)?", RegexOptions.IgnoreCase | RegexOptions.RightToLeft);

            if (!SongName.IsNullOrEmpty() && regex.IsMatch(SongName)) //若是歌名上包含难度信息则取出来
            {
                RatingClass = SongName.Match("(ftr|pst|prs|byd|byn|future|past|present|beyond|all)", RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
                SongName    = regex.Replace(SongName, "", 1).Trim();
            }
            if (!RatingClass.IsNullOrEmpty())//RatingClass属性优先级比该函数中的ratingClss优先级大
            {
                if (!Enum.TryParse(RatingClass, out ratingClass))
                {
                    if (PluginArcaeaSong.RatingClassNameList.ContainsKey(RatingClass.ToLower()))
                    {
                        ratingClass = PluginArcaeaSong.RatingClassNameList[RatingClass.ToLower()];
                    }
                }
            }
            //设定难度类型默认值为FTR
            if (ratingList.IsNullOrEmptySet() && RatingClass.IsNullOrWhiteSpace() && NotesCount.IsNullOrWhiteSpace() && ChartConstant.IsNullOrWhiteSpace() && Rating.IsNullOrWhiteSpace()) //不指定难度类型则默认是future难度,后面是不默认ftr
            {
                ratingClass = PluginArcaeaSong.RatingClass.Future;
            }
            //处理歌名信息
            if (!SongName.IsNullOrWhiteSpace())
            {
                SongName = SongName.Trim().ToLower();
                string songEnID = _kouContext.Set <PluginArcaeaSongAnotherName>().FirstOrDefault(s => s.AnotherName == SongName)?.SongEnId;
                if (songEnID != null)
                {
                    SongEnID = songEnID;
                    SongName = null;
                }
            }


            //将需要用到的过滤器放到过滤容器里
            FilterContainer <PluginArcaeaSong> filterContainer = new FilterContainer <PluginArcaeaSong>();

            //使用默认ModelFilter
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongTitle), SongName, FilterType.Default, SortType.Ascending);//增加Song_title字段的默认filter
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongEnId), SongEnID, FilterType.Exact);
            if (ratingClass != PluginArcaeaSong.RatingClass.Random)
            {
                filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartRatingClass), ratingClass, FilterType.SupportValueDefault);
            }
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongArtist), SongArtist, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartDesigner), ChartDesigner, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.JacketDesigner), JacketDesigner, FilterType.Default, SortType.Ascending);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartAllNotes), NotesCount, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.ChartConstant), ChartConstant, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongLength), SongLength, FilterType.Default, SortType.StringAuto);
            filterContainer.AddAutoModelFilter(nameof(PluginArcaeaSong.SongBpm), SongBPM, FilterType.Interval, SortType.StringAuto);
            filterContainer.ActivateAutoModelFilter();
            //加入自定义的filter
            if (!ratingList.IsNullOrEmptySet())
            {
                filterContainer.Add(FilterContainer <PluginArcaeaSong> .Convert(PluginArcaeaSong.RatingNumFilter), ratingList);
            }


            //开始筛选
            var selectedList = _kouContext.Set <PluginArcaeaSong>().ToList();

            selectedList = selectedList.Where(song => filterContainer.StartFilter(song)).ToList();
            var sorter = filterContainer.GetModelSorter();//若有sorter则排序

            if (sorter != null)
            {
                selectedList.Sort(sorter);
            }
            return(selectedList);
        }
コード例 #2
0
 public string getFileName()
 {
     return(Singer.Trim() + "-" + SongName.Trim() + ".mp3");
 }