Ejemplo n.º 1
0
 public static IReadOnlyList <NicoVideoInfo> GetAll()
 {
     using (var db = new NicoVideoDbContext())
     {
         return(db.VideoInfos.ToList());
     }
 }
Ejemplo n.º 2
0
 public static NicoVideoInfo Get(string rawVideoId)
 {
     using (var db = new NicoVideoDbContext())
     {
         return(db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId));
     }
 }
Ejemplo n.º 3
0
        public static void AddOrUpdate(string rawVideoId, CommentResponse commentRes)
        {
            using (var db = new NicoVideoDbContext())
            {
                var comment = db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId);

                if (comment == null)
                {
                    comment = new NicoVideoComment()
                    {
                        ThreadId     = rawVideoId,
                        CommentCount = commentRes.GetCommentCount()
                    };

                    db.Comments.Add(comment);
                }
                else
                {
                    comment.CommentCount = commentRes.GetCommentCount();
                    comment.SetComments(commentRes.Chat);

                    db.Comments.Update(comment);
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
 public static UserInfo Get(string userId)
 {
     using (var db = new NicoVideoDbContext())
     {
         return(db.Users.SingleOrDefault(x => x.UserId == userId));
     }
 }
Ejemplo n.º 5
0
 public static NicoVideoComment Get(string rawVideoId)
 {
     using (var db = new NicoVideoDbContext())
     {
         return(db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId));
     }
 }
Ejemplo n.º 6
0
 public static async Task InitializeAsync()
 {
     using (var db = new NicoVideoDbContext())
     {
         await db.Database.EnsureCreatedAsync();
     }
 }
Ejemplo n.º 7
0
 public static async Task <NicoVideoInfo> GetAsync(string threadId)
 {
     using (var releaser = await _AsyncLock.LockAsync())
         using (var db = new NicoVideoDbContext())
         {
             return(await db.VideoInfos.SingleOrDefaultAsync(x => x.RawVideoId == threadId));
         }
 }
Ejemplo n.º 8
0
 public static void Remove(UserInfo info)
 {
     using (var db = new NicoVideoDbContext())
     {
         db.Users.Remove(info);
         db.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public static async Task <UserInfo> GetAsync(string userId)
 {
     using (var releaser = await _AsyncLock.LockAsync())
         using (var db = new NicoVideoDbContext())
         {
             return(await db.Users.SingleOrDefaultAsync(x => x.UserId == userId));
         }
 }
Ejemplo n.º 10
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();
         }
 }
Ejemplo n.º 11
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();
         }
 }
Ejemplo n.º 12
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();
                }
        }
Ejemplo n.º 13
0
 public static void Remove(string rawVideoId)
 {
     using (var db = new NicoVideoDbContext())
     {
         var comment = db.Comments.SingleOrDefault(x => x.ThreadId == rawVideoId);
         if (comment != null)
         {
             db.Comments.Remove(comment);
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 14
0
        public static void Deleted(string rawVideoId)
        {
            using (var db = new NicoVideoDbContext())
            {
                var info = db.VideoInfos.SingleOrDefault(x => x.RawVideoId == rawVideoId);

                if (info != null)
                {
                    info.IsDeleted = true;
                    db.VideoInfos.Update(info);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 15
0
        public static void Remove(string rawVideoId)
        {
            var nicoVideoInfo = Get(rawVideoId);

            if (nicoVideoInfo == null)
            {
                return;
            }

            using (var db = new NicoVideoDbContext())
            {
                db.VideoInfos.Remove(nicoVideoInfo);
                db.SaveChanges();
            }
        }
Ejemplo n.º 16
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();
                }
        }
Ejemplo n.º 17
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);
            }
        }