Exemplo n.º 1
0
        public bool Insert(IRedditPost redditPost)
        {
            long countDocuments = _context.MonitoredPosts.CountDocuments(p => p.FullName.Equals(redditPost.FullName));

            if (countDocuments > 0)
            {
                _logger.LogWarning("Post with FullName [{}] already watched, skipping", redditPost.FullName);
                return(false);
            }

            var document = _mapper.Map <RedditMonitoredPostDocument>(redditPost);

            document.IterationNumber = 1;
            document.Age             = DateTimeOffset.UtcNow - document.CreatedUTC;
            _context.MonitoredPosts.InsertOne(document);
            return(true);
        }
Exemplo n.º 2
0
        public void AddVersion(IRedditPost newVersion)
        {
            var newPostVersion = _mapper.Map <RedditMonitoredPostDocument>(newVersion);

            if (!(Get(newPostVersion.FullName) is RedditMonitoredPostDocument oldVersion))
            {
                throw new PostMonitorException($"Could not find original version for post id [{newVersion.Id}]");
            }

            newPostVersion.IterationNumber = oldVersion.IterationNumber + 1;
            newPostVersion.Age             = DateTimeOffset.UtcNow - oldVersion.CreatedUTC;

            newPostVersion.Id = oldVersion.Id;
            _context.MonitoredPosts.ReplaceOne(p => p.FullName == newPostVersion.FullName, newPostVersion);

            _context.MonitoredPostVersions.InsertOne(_mapper.Map <RedditMonitoredPostVersionDocument>(oldVersion));
        }
Exemplo n.º 3
0
        private void OnNext(IRedditPost post)
        {
            TimeSpan age = DateTimeOffset.UtcNow - post.CreatedUTC;

            if (age > _newPostMaxAge)
            {
                _logger.LogInformation("Post [{FullName}] is discarded because it's already too old", post.FullName);
                return;
            }
            if (!_monitoredPostRepository.Insert(post))
            {
                return;
            }
            _logger.LogInformation(@"Adding post [{FullName}] to watch list [{CurrentCount}]",
                                   post.FullName,
                                   _monitoredPostRepository.CountMonitoredPosts());
        }