Beispiel #1
0
        protected override IEnumerable <Post> PreSave(IEnumerable <Post> items, RedditEntities db)
        {
            documentRemover.RemoveDocuments(items.ToList <IDocument>());

            // No need to filter posts.
            return(items);
        }
Beispiel #2
0
        public virtual void Save(IEnumerable <T> items)
        {
            if (items.Any())
            {
                try
                {
                    using (var db = new RedditEntities(Connection))
                    {
                        var filtered = PreSave(items, db);

                        GetDbSet(db).AddRange(filtered);

                        db.SaveChanges();
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    var list = string.Join(",", items);
                    Log.Error($"Error validating item of type {itemType}: {list}", ex);
                    var errors =
                        ex.EntityValidationErrors.Select(
                            e => string.Join(Environment.NewLine,
                                             e.ValidationErrors.Select(v => $"{v.PropertyName} - {v.ErrorMessage}")) +
                            "   Entity: " + e.Entry.Entity);

                    foreach (var error in errors)
                    {
                        Log.Error($"----Validation error: {error}");
                    }
                }
            }
 protected override DbSet <PostCommentCount> GetDbSet(RedditEntities db)
 {
     return(db.PostCommentCounts);
 }
        protected override IEnumerable <PostCommentCount> PreSave(IEnumerable <PostCommentCount> items, RedditEntities db)
        {
            var ids           = items.Select(x => x.PostId);
            var existingItems = (from postCommentCount in db.PostCommentCounts
                                 where ids.Contains(postCommentCount.PostId)
                                 select postCommentCount).ToList();

            db.PostCommentCounts.RemoveRange(existingItems);
            db.SaveChanges();

            return(items);
        }
Beispiel #5
0
 protected override DbSet <UserDefinedEntityDefinition> GetDbSet(RedditEntities db)
 {
     return(db.UserDefinedEntityDefinitions);
 }
 protected override DbSet <EmbeddedUrl> GetDbSet(RedditEntities db)
 {
     return(db.EmbeddedUrls);
 }
Beispiel #7
0
 /// <summary>
 /// Pre-save hook.  Allows user to filter items before the actual write.
 /// </summary>
 /// <param name="items"></param>
 /// <param name="db"></param>
 /// <returns>Items that will be written to the database</returns>
 protected virtual IEnumerable <T> PreSave(IEnumerable <T> items, RedditEntities db)
 {
     return(items);
 }
        protected override IEnumerable <Comment> PreSave(IEnumerable <Comment> items, RedditEntities db)
        {
            // Delete all comments.  Even the invalid comments.
            // A comment may be made on Reddit, ingested by us, then deleted.
            // On the next poll this comment will be seen as an InvalidComment.  We want
            // to remove it from the DB along with all the other comments.
            this.documentRemover.RemoveDocuments(items.ToList <IDocument>());

            // Do not write the invalid comments.
            return(items.Where(x => !(x is InvalidComment)));
        }