예제 #1
0
        public async Task CancelCacheRequest(NicoVideoQuality?quality = null)
        {
            if (quality.HasValue)
            {
                var divided = GetDividedQualityNicoVideo(quality.Value);
                await divided.DeleteCache();
            }
            else
            {
                foreach (var divided in GetAllQuality())
                {
                    await divided.DeleteCache();
                }
            }

            // 全てのキャッシュリクエストが取り消されていた場合
            // 動画情報とコメント情報をDBから削除する
            if (GetAllQuality().All(x => !x.IsCacheRequested))
            {
                var info = await VideoInfoDb.GetEnsureNicoVideoInfoAsync(RawVideoId);

                if (!info.IsDeleted)
                {
                    await VideoInfoDb.RemoveAsync(info);
                }

                CommentDb.Remove(RawVideoId);

                _NiconicoMediaManager.VideoCacheStateChanged -= _NiconicoMediaManager_VideoCacheStateChanged;
            }
        }
예제 #2
0
        /// <summary>
        /// Create a new comment in repository.
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public async Task <CommentDb> AddAsync(CommentDb comment)
        {
            _videoDbContext.Comments.Add(comment);
            await _videoDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(await Task.FromResult(comment));
        }
예제 #3
0
        /// <summary>
        /// Add new comment to video.
        /// </summary>
        /// <param name="video"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public Task <Result> AddComment(string videoId, string userId, string comment)
        {
            var videoDb   = _videoRepository.GetById(videoId);
            var commentDb = new CommentDb()
            {
                CommentId = Guid.NewGuid().ToString(),
                Date      = DateTime.Now,
                Text      = comment,
                VideoId   = videoDb
            };

            try
            {
                _videoRepository.AddComment(userId, commentDb);
                return(Task.FromResult(Result.Ok()));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Task.FromResult(Result.Fail($"Cannot add comment to video. {e.Message}")));
            }
            catch (DbUpdateException e)
            {
                return(Task.FromResult(Result.Fail($"Cannot add comment to video. Duplicate field. {e.Message}")));
            }
            catch (DbEntityValidationException e)
            {
                return(Task.FromResult(Result.Fail($"Invalid tag. {e.Message}")));
            }
        }
예제 #4
0
        public async Task <bool> AddCommentAsync(CommentDb commentDb)
        {
            await _applicationDb.Comments.AddAsync(commentDb);

            var created = await _applicationDb.SaveChangesAsync();

            return(created > 0);
        }
예제 #5
0
 /// <summary>
 /// Update comment in repository.
 /// </summary>
 /// <param name="comment"></param>
 /// <returns></returns>
 public void Update(CommentDb comment)
 {
     if (comment == null)
     {
         throw new ArgumentNullException("comment");
     }
     _videoDbContext.Entry(comment).State = EntityState.Modified;
     _videoDbContext.SaveChanges();
 }
예제 #6
0
 /// <summary>
 /// Remove comment in repository.
 /// </summary>
 /// <param name="comment"></param>
 /// <returns></returns>
 public async Task RemoveAsync(CommentDb comment)
 {
     if (comment == null)
     {
         throw new ArgumentNullException("comment");
     }
     _videoDbContext.Comments.Remove(comment);
     await _videoDbContext.SaveChangesAsync().ConfigureAwait(false);
 }
예제 #7
0
        // コメントのキャッシュまたはオンラインからの取得と更新
        public async Task <List <Chat> > GetComments()
        {
            if (CommentServerInfo == null)
            {
                return(new List <Chat>());
            }

            CommentResponse commentRes = null;

            try
            {
                commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                {
                    return(await this.HohoemaApp.NiconicoContext.Video
                           .GetCommentAsync(
                               (int)HohoemaApp.LoginUserId,
                               CommentServerInfo.ServerUrl,
                               CommentServerInfo.DefaultThreadId,
                               CommentServerInfo.ThreadKeyRequired
                               ));
                });
            }
            catch
            {
            }


            if (commentRes?.Chat.Count == 0)
            {
                try
                {
                    if (CommentServerInfo.CommunityThreadId.HasValue)
                    {
                        commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                        {
                            return(await this.HohoemaApp.NiconicoContext.Video
                                   .GetCommentAsync(
                                       (int)HohoemaApp.LoginUserId,
                                       CommentServerInfo.ServerUrl,
                                       CommentServerInfo.CommunityThreadId.Value,
                                       CommentServerInfo.ThreadKeyRequired
                                       ));
                        });
                    }
                }
                catch { }
            }

            if (commentRes != null)
            {
                CachedCommentResponse = commentRes;
                CommentDb.AddOrUpdate(RawVideoId, commentRes);
            }

            return(commentRes?.Chat);
        }
예제 #8
0
        /// <summary>
        /// Update comment in repository.
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public async Task <CommentDb> UpdateAsync(CommentDb comment)
        {
            if (comment == null)
            {
                throw new ArgumentNullException("comment");
            }
            _videoDbContext.Entry(comment).State = EntityState.Modified;
            await _videoDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(await Task.FromResult(comment));
        }
예제 #9
0
        /// <summary>
        /// Add comment to video by user Id in repository.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="commentDb"></param>
        /// <returns></returns>
        public async Task <CommentDb> AddComment(string userId, CommentDb commentDb)
        {
            var user = _videoDbContext.Users.FirstOrDefault(c => c.UserId.Equals(userId));

            commentDb.UserId = user;
            _videoDbContext.Comments.Add(commentDb);
            await _videoDbContext.SaveChangesAsync().ConfigureAwait(false);

            var result = await Task.FromResult(commentDb);

            return(result);
        }
예제 #10
0
        public void InitMock()
        {
            _commentsDb = new List <CommentDb>()
            {
                new CommentDb()
                {
                    CommentId = "id1", Date = DateTime.Now, Text = "AAAAA"
                },
                new CommentDb()
                {
                    CommentId = "id2", Date = DateTime.Now, Text = "BBBBB"
                },
                new CommentDb()
                {
                    CommentId = "id3", Date = DateTime.Now, Text = "CCCCC"
                },
            }.AsQueryable();

            _oneCommentDb = new CommentDb()
            {
                CommentId = "id4", Date = DateTime.Now, Text = "DDDDD"
            };

            _commentsInfo = new List <CommentInfo>()
            {
                new CommentInfo()
                {
                    Date = DateTime.Now, Text = "AAAAA", UpdateDate = DateTime.Now
                },
                new CommentInfo()
                {
                    Date = DateTime.Now, Text = "BBBBB", UpdateDate = DateTime.Now
                },
                new CommentInfo()
                {
                    Date = DateTime.Now, Text = "CCCCC", UpdateDate = DateTime.Now
                }
            }.AsQueryable();

            _oneCommentInfo = new CommentInfo()
            {
                Date = DateTime.Now, Text = "DDDDD", UpdateDate = DateTime.Now
            };

            _mockSet = new Mock <DbSet <CommentDb> >();
            _mockSet.As <IQueryable <CommentDb> >().Setup(m => m.Expression).Returns(_commentsDb.Expression);
            _mockSet.As <IQueryable <CommentDb> >().Setup(m => m.ElementType).Returns(_commentsDb.ElementType);
            _mockSet.As <IQueryable <CommentDb> >().Setup(m => m.GetEnumerator()).Returns(_commentsDb.GetEnumerator());
            _mockContext = new Mock <VideoDbContext>();
            _mockMapper  = new Mock <IMapper>();
        }
예제 #11
0
        public async Task <IActionResult> AddComment([FromBody] CreateCommentRequest commentRequest)
        {
            var newCommentDb = new CommentDb
            {
                Comment = commentRequest.Comment,
                PostId  = commentRequest.PostId,
                Created = DateTime.Now,
                UserId  = HttpContext.GetUserId(),
            };

            var result = await _commentService.AddCommentAsync(newCommentDb);

            if (!result)
            {
                return(BadRequest("Unable to create Comment"));
            }

            return(Ok());
        }
예제 #12
0
        public List <CommentLogic> CommentId(int id)
        {
            CommentDb connection = new CommentDb();

            DataTable dataTable = connection.CommentId(id);

            List <CommentLogic> list = new List <CommentLogic>();

            foreach (DataRow dr in dataTable.Rows)
            {
                CommentLogic comment = new CommentLogic();
                comment.id     = Convert.ToInt32(dr["Id"]);
                comment.sender = dr["Sender"].ToString();
                comment.text   = dr["Text"].ToString();
                comment.date   = Convert.ToDateTime(dr["Date"]);

                list.Add(comment);
            }
            return(list);
        }
예제 #13
0
        public void CommentAdd(int id, string sender, string text, DateTime date)
        {
            CommentDb connection = new CommentDb();

            connection.Add(id, sender, text, date);
        }
예제 #14
0
        public List <Chat> GetCommentsFromLocal()
        {
            var j = CommentDb.Get(RawVideoId);

            return(j?.GetComments());
        }
예제 #15
0
 /// <summary>
 /// Remove comment in repository.
 /// </summary>
 /// <param name="comment"></param>
 /// <returns></returns>
 public void Remove(CommentDb comment)
 {
     _videoDbContext.Comments.Remove(comment);
     _videoDbContext.SaveChanges();
 }
예제 #16
0
 /// <summary>
 /// Create a new comment in repository.
 /// </summary>
 /// <param name="comment"></param>
 /// <returns></returns>
 public void Add(CommentDb comment)
 {
     _videoDbContext.Comments.Add(comment);
     _videoDbContext.SaveChanges();
 }