Example #1
0
 public static Beatmap FilterByIdentity(MapIdentity identity)
 {
     using (var context = new BeatmapDbContext())
     {
         return(context.Beatmaps.Where(k => k != null).FirstOrDefault(k => k.FolderName == identity.FolderName && k.Version == identity.Version));
     }
 }
Example #2
0
 public static IEnumerable <Beatmap> GetRecentListFromDb()
 {
     using (var context = new BeatmapDbContext())
     {
         throw new NotImplementedException();
     }
 }
Example #3
0
 public static List <Beatmap> FilterByFolder(string folder)
 {
     using (var context = new BeatmapDbContext())
     {
         return(context.Beatmaps.Where(k => k.FolderName == folder).ToList());
     }
 }
Example #4
0
 public static List <Beatmap> FilterByIdentities(IEnumerable <MapIdentity> identities)
 {
     using (var context = new BeatmapDbContext())
     {
         return(identities.Select(id => context.Beatmaps.FirstOrDefault(k => k.FolderName == id.FolderName && k.Version == id.Version)).ToList()); //todo: need optimize
     }
 }
Example #5
0
        public static async Task SyncMapsFromHoLLyAsync(IEnumerable <BeatmapEntry> entry, bool addOnly)
        {
            using (var context = new BeatmapDbContext())
            {
                if (addOnly)
                {
                    var dbMaps  = context.Beatmaps.Where(k => !k.InOwnFolder);
                    var newList = entry.Select(Beatmap.ParseFromHolly);
                    var except  = newList.Except(dbMaps, new Beatmap.Comparer(true));

                    context.Beatmaps.AddRange(except);
                    await context.SaveChangesAsync();
                }
                else
                {
                    var dbMaps = context.Beatmaps.Where(k => !k.InOwnFolder);
                    context.Beatmaps.RemoveRange(dbMaps);

                    var osuMaps = entry.Select(Beatmap.ParseFromHolly);
                    context.Beatmaps.AddRange(osuMaps);

                    await context.SaveChangesAsync();
                }
            }
        }
Example #6
0
 public static async Task RemoveLocalAllAsync()
 {
     using (var context = new BeatmapDbContext())
     {
         var locals = context.Beatmaps.Where(k => k.InOwnFolder);
         context.Beatmaps.RemoveRange(locals);
         await context.SaveChangesAsync();
     }
 }
Example #7
0
 public static async Task <List <Beatmap> > GetWholeListFromDbAsync()
 {
     return(await Task.Run(() =>
     {
         using (var context = new BeatmapDbContext())
         {
             return context.Beatmaps.ToList();
         }
     }));
 }
Example #8
0
 public static List <Beatmap> FilterByTitleArtist(string title, string artist)
 {
     using (var context = new BeatmapDbContext())
     {
         var result = context.Beatmaps
                      .Where(k => k.Title != null && k.Title == title ||
                             k.TitleUnicode != null && k.TitleUnicode == title)
                      .Where(k => k.Artist != null && k.Artist == artist ||
                             k.ArtistUnicode != null && k.ArtistUnicode == artist).ToList();
         StoreCache(result);
         return(result);
     }
 }
Example #9
0
        public static List <Beatmap> FilterByKeyword(string keywordStr)
        {
            using (var context = new BeatmapDbContext())
            {
                if (string.IsNullOrWhiteSpace(keywordStr))
                {
                    return(context.Beatmaps.ToList());
                }
                string[] keywords = keywordStr.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                return(keywords.Aggregate <string, IEnumerable <Beatmap> >(context.Beatmaps,
                                                                           (current, keyword) => current.Where(k =>
                                                                                                               k.Title?.Contains(keyword, true) == true ||
                                                                                                               k.TitleUnicode?.Contains(keyword, true) == true ||
                                                                                                               k.Artist?.Contains(keyword, true) == true ||
                                                                                                               k.ArtistUnicode?.Contains(keyword, true) == true ||
                                                                                                               k.SongTags?.Contains(keyword, true) == true ||
                                                                                                               k.SongSource?.Contains(keyword, true) == true ||
                                                                                                               k.Creator?.Contains(keyword, true) == true ||
                                                                                                               k.Version?.Contains(keyword, true) == true
                                                                                                               )).ToList());
            }
        }
Example #10
0
 public BeatmapDbOperator()
 {
     _beatmapDbContext = new BeatmapDbContext();
 }