Beispiel #1
0
 public static async Task RemoveRangeAsync(IEnumerable <NicoVideoInfo> removeTargets)
 {
     using (var releaser = await _AsyncLock.LockAsync())
         using (var db = new NicoVideoDbContext())
         {
             db.VideoInfos.RemoveRange(removeTargets);
             await db.SaveChangesAsync();
         }
 }
Beispiel #2
0
 public static async Task RemoveAsync(NicoVideoInfo nicoVideoInfo)
 {
     using (var releaser = await _AsyncLock.LockAsync())
         using (var db = new NicoVideoDbContext())
         {
             db.VideoInfos.Remove(nicoVideoInfo);
             await db.SaveChangesAsync();
         }
 }
Beispiel #3
0
        public static async Task UpdateAsync(NicoVideoInfo info)
        {
            using (var releaser = await _AsyncLock.LockAsync())
                using (var db = new NicoVideoDbContext())
                {
                    info.LastUpdated = DateTime.Now;

                    db.VideoInfos.Update(info);

                    await db.SaveChangesAsync();
                }
        }
Beispiel #4
0
        public static async Task AddOrReplaceAsync(string userId, string name, string iconUrl = null)
        {
            using (var releaser = await _AsyncLock.LockAsync())
                using (var db = new NicoVideoDbContext())
                {
                    bool isAlreadHasUser = db.Users.Any(x => x.UserId == userId);

                    if (isAlreadHasUser)
                    {
                        var info = await db.Users.SingleAsync(x => x.UserId == userId);

                        if (name != null)
                        {
                            info.Name = name;
                        }
                        if (iconUrl != null)
                        {
                            info.IconUri = iconUrl;
                        }

                        db.Users.Update(info);
                    }
                    else
                    {
                        var info = new UserInfo()
                        {
                            UserId  = userId,
                            Name    = name,
                            IconUri = iconUrl
                        };

                        db.Users.Add(info);
                    }


                    await db.SaveChangesAsync();
                }
        }
Beispiel #5
0
        public static async Task <NicoVideoInfo> GetEnsureNicoVideoInfoAsync(string rawVideoId)
        {
            using (var db = new NicoVideoDbContext())
            {
                var info = db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId);

                if (info == null)
                {
                    info = new NicoVideoInfo()
                    {
                        RawVideoId  = rawVideoId,
                        LastUpdated = DateTime.Now
                    };

                    using (var releaser = await _AsyncLock.LockAsync())
                    {
                        db.VideoInfos.Add(info);
                        await db.SaveChangesAsync();
                    }
                }

                return(info);
            }
        }