Esempio n. 1
0
        private void UpdateExistingPost(responsePost post, Post savedPost)
        {
            this.log.DebugFormat("Post with VkId={0} is already in database", post.id);
            int newLikesCount    = int.Parse(post.likes[0].count);
            int newCommentsCount = int.Parse(post.comments[0].count);

            if (savedPost.LikesCount != newLikesCount || savedPost.CommentsCount != newCommentsCount)
            {
                savedPost.LikesCount    = newLikesCount;
                savedPost.CommentsCount = newCommentsCount;
                this.postRepository.UpdatePost(savedPost);
                this.log.DebugFormat("Post with VkId={0} comments or likes changed. Updating the post", post.id);
            }
        }
Esempio n. 2
0
        private void SaveNewPost(responsePost post, VkGroup group)
        {
            Post savedPost = new Post
            {
                VkGroupId     = group.Id,
                PostedDate    = post.date.FromUnixTimestamp(),
                CreatorId     = long.Parse(post.from_id),
                LikesCount    = int.Parse(post.likes[0].count),
                CommentsCount = int.Parse(post.comments[0].count),
                Text          = post.text,
                VkId          = post.id
            };

            this.postRepository.Save(savedPost);
            this.log.DebugFormat("Post with VkId={0} is not found in database. Saved with Id={1}", savedPost.VkId, savedPost.Id);
        }
Esempio n. 3
0
        private void ProcessPost(responsePost post, VkGroup group)
        {
            var savedPost = this.postRepository.GetPost(group.Id, post.id);

            if (savedPost == null &&
                this.processingStrategy.IsLimitedProcessingEnabled(group.Id, DataFeedType.WallPosts) &&
                post.date.FromUnixTimestamp().AddMonths(this.processingStrategy.GetMonthLimit()) < DateTime.UtcNow)
            {
                this.log.DebugFormat("Fetched post with VkId={0} is created more than {1} months ago. Skipping.", post.id, this.processingStrategy.GetMonthLimit());
                return;
            }

            if (savedPost != null)
            {
                this.UpdateExistingPost(post, savedPost);
            }
            else
            {
                this.SaveNewPost(post, group);
            }
        }