private void ProcessPost(string vkVideoId, responseComment comment, VkGroup group) { var savedComment = this.videoRepository.GetVideoCommentByVkGroupId(group.Id, comment.id); if (savedComment != null) { this.log.DebugFormat("Video comment with VkId={0} is already in database", comment.id); return; } if (this.processingStrategy.IsLimitedProcessingEnabled(group.Id, DataFeedType.VideoComments) && comment.date.FromUnixTimestamp().AddMonths(this.processingStrategy.GetMonthLimit()) < DateTime.UtcNow) { this.log.DebugFormat("Fetched video comment with VkId={0} is created more than {1} months ago. Skipping.", comment.id, this.processingStrategy.GetMonthLimit()); return; } savedComment = new VideoComment { VkId = comment.id, VkVideoId = vkVideoId, VkGroupId = group.Id, PostedDate = comment.date.FromUnixTimestamp(), CreatorId = long.Parse(comment.from_id) }; this.videoRepository.SaveComment(savedComment); this.log.DebugFormat("Topic comment with VkId={0} is not found in database. Saved with Id={1}", savedComment.VkId, savedComment.Id); }
private void ProcessPost(string vkPostId, responseComment comment, VkGroup group) { var savedComment = this.postRepository.GetPostComment(group.Id, comment.cid); if (savedComment != null) { this.log.DebugFormat("Post comment with VkId={0} is already in database", comment.cid); return; } if (this.processingStrategy.IsLimitedProcessingEnabled(group.Id, DataFeedType.WallPostComments) && comment.date.FromUnixTimestamp().AddMonths(this.processingStrategy.GetMonthLimit()) < DateTime.UtcNow) { this.log.DebugFormat("Fetched post comment with VkId={0} is created more than {1} months ago. Skipping.", comment.cid, this.processingStrategy.GetMonthLimit()); return; } savedComment = new PostComment { VkId = comment.cid, VkPostId = vkPostId, VkGroupId = group.Id, PostedDate = comment.date.FromUnixTimestamp(), CreatorId = long.Parse(comment.uid), ReplyToUserId = string.IsNullOrWhiteSpace(comment.reply_to_uid) ? null : (long?)long.Parse(comment.reply_to_uid), ReplyToVkId = string.IsNullOrWhiteSpace(comment.reply_to_cid) ? null : (int?)int.Parse(comment.reply_to_cid), }; this.postRepository.SaveComment(savedComment); this.log.DebugFormat("Post comment with VkId={0} is not found in database. Saved with Id={1}", savedComment.VkId, savedComment.Id); }
public IEnumerable <DataFeed> GetFeeds(IVkDataProvider dataProvider, VkGroup vkGroup) { DateTime? dateLimit = this.strategy.GetDateLimit(vkGroup.Id, this.ProvidedDataType); IList <Video> videos = this.videoRepository.GetVideosByVkGroupId(vkGroup.Id).Where(v => !dateLimit.HasValue || v.PostedDate > dateLimit).ToList(); foreach (var video in videos) { int offsetCounter = 0; while (true) { var videoComments = dataProvider.GetVideoComments(vkGroup.Id.ToString(), video.VkId, offsetCounter); this.log.DebugFormat("Video comments feed is received: {0}", videoComments.Feed); if (videoComments.comment == null || videoComments.comment.Length == 0) { break; } // if last comment in this pack is was created before dateLimit, we ignore the whole pack, but still trying to find the latest one responseComment lastCommentGroup = videoComments.comment[videoComments.comment.Length - 1]; if (dateLimit.HasValue && lastCommentGroup.date.FromUnixTimestamp() < dateLimit.Value) { continue; } DataFeed dataFeed = new DataFeed { ReceivedAt = this.dateTimeHelper.GetDateTimeNow(), Feed = videoComments.Feed, VkGroupId = vkGroup.Id, RelatedObjectId = video.VkId, Type = DataFeedType.VideoComments }; yield return(dataFeed); offsetCounter += videoComments.comment.Length; } } }