Beispiel #1
0
        public override void Flush()
        {
            if (Posts.Any())
            {
                foreach (Post post in Posts)
                {
                    if (post.Xact == null)
                    {
                        throw new InvalidOperationException("no xact");
                    }
                    foreach (Post rPost in post.Xact.Posts)
                    {
                        PostXData xdata = rPost.XData;
                        if (!xdata.Handled && (!xdata.Received
                            ? !(rPost.Flags.HasFlag(SupportsFlagsEnum.ITEM_GENERATED) || rPost.Flags.HasFlag(SupportsFlagsEnum.POST_VIRTUAL))
                            : AlsoMatching))
                        {
                            xdata.Handled = true;
                            base.Handle(rPost);
                        }
                    }
                }
            }

            base.Flush();
        }
Beispiel #2
0
        public void Update()
        {
            Parent.updating_threads.Wait();

            Task.Factory.StartNew(delegate
            {
                string thread_url = EndpointProvider.GetThreadEndpoint(Parent.Name, ID);

                if (thread_url == "")
                {
                    Parent.updating_threads.Release();
                    return;
                }

                string raw = Utilities.Download(thread_url);

                if (raw == "-")
                {
                    Parent.updating_threads.Release();
                    Removal();
                    return;
                }

                JObject root = JObject.Parse(raw);

                JArray posts = root.Value <JArray>("posts");

                JsonSerializer serializer    = new JsonSerializer();
                serializer.NullValueHandling = NullValueHandling.Ignore;

                List <int> current_posts = new List <int>();

                foreach (JObject rawpost in posts)
                {
                    Post post   = serializer.Deserialize <Post>(new JTokenReader(rawpost));
                    post.Parent = this;

                    current_posts.Add(post.ID);

                    if (!Posts.Any(p => p.ID == post.ID))
                    {
                        Posts.Add(post);

                        if (NewPost != null)
                        {
                            NewPost(post);
                        }
                    }
                }

                Func <Post, bool> dead = (p => !current_posts.Contains(p.ID));

                Posts.Where(dead).ToList().ForEach(RemovePost);

                Parent.updating_threads.Release();
            });
        }
Beispiel #3
0
        /// <summary>
        /// Ported from void truncate_xacts::flush()
        /// </summary>
        public override void Flush()
        {
            if (!Posts.Any())
            {
                return;
            }

            int l = Posts.Select(p => p.Xact).Distinct().Count();

            Xact xact = Posts.First().Xact;

            int i = 0;

            foreach (Post post in Posts)
            {
                if (xact != post.Xact)
                {
                    xact = post.Xact;
                    i++;
                }

                bool print = false;
                if (HeadCount != 0)
                {
                    if (HeadCount > 0 && i < HeadCount)
                    {
                        print = true;
                    }
                    else if (HeadCount < 0 && i >= -HeadCount)
                    {
                        print = true;
                    }
                }

                if (!print && TailCount != 0)
                {
                    if (TailCount > 0 && l - i <= TailCount)
                    {
                        print = true;
                    }
                    else if (TailCount < 0 && l - i > -TailCount)
                    {
                        print = true;
                    }
                }

                if (print)
                {
                    base.Handle(post);
                }
            }
            Posts.Clear();

            base.Flush();
        }
 private void ExportModulePostNavs(MixModules.ImportViewModel item, MixCmsContext context, IDbContextTransaction transaction)
 {
     ModulePostNavs.AddRange(item.GetPostNavs(context, transaction)
                             .Where(m => !ModulePostNavs.Any(n => n.PostId == m.PostId && n.ModuleId == m.ModuleId)));
     foreach (var nav in ModulePostNavs)
     {
         if (!Posts.Any(m => m.Id == nav.Post.Id && m.Specificulture == Specificulture))
         {
             Posts.Add(nav.Post);
         }
     }
 }
Beispiel #5
0
        private void LoadSubPosts(MixPages.ImportViewModel item, MixCmsContext context, IDbContextTransaction transaction)
        {
            item.PostNavs = item.GetPostNavs(context, transaction);
            var navPostIds = item.PostNavs.Select(n => n.PostId);
            var postIds    = navPostIds.Where(n => !Posts.Any(m => m.Id == n));
            var getPosts   = MixPosts.ImportViewModel.Repository.GetModelListBy(m => postIds.Contains(m.Id), context, transaction);

            if (getPosts.IsSucceed)
            {
                Posts.AddRange(getPosts.Data);
            }
        }
Beispiel #6
0
        // URL: {domain}/tag/tag-id
        public async Task <IActionResult> OnGetAsync(string tagId)
        {
            Posts = await _posts.GetPostsByTagAsync(tagId);

            if (!Posts.Any())
            {
                return(NotFound());
            }

            TagName = tagId;

            return(Page());
        }
        public void Seed()
        {
            if (!Posts.Any())
            {
                Posts.AddRange(new List <Post> {
                    new Post {
                        Title = "Async", Description = "OData"
                    },
                    new Post {
                        Title = "Test", Description = "OData"
                    },
                    new Post {
                        Title = "Sample", Description = "OData"
                    }
                });
                SaveChanges();
            }

            if (!Tags.Any())
            {
                Tags.AddRange(new List <Tag> {
                    new Tag {
                        Title = "asp-core2.2"
                    },
                    new Tag {
                        Title = "odata4.0"
                    },
                    new Tag {
                        Title = "c#"
                    }
                });
                SaveChanges();
            }

            if (!PostTags.Any())
            {
                PostTags.AddRange(new List <PostTag> {
                    new PostTag {
                        PostId = 1, TagId = 1
                    },
                    new PostTag {
                        PostId = 1, TagId = 2
                    },
                    new PostTag {
                        PostId = 1, TagId = 3
                    }
                });
                SaveChanges();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Determines whether the author of the provided post has made a newer vote submission.
        /// </summary>
        /// <param name="post">The post being checked.</param>
        /// <returns>Returns true if the voter has a newer vote already submitted.</returns>
        public bool HasNewerVote(Post post)
        {
            if (post == null)
            {
                throw new ArgumentNullException(nameof(post));
            }

            if (!HasVoter(post.Origin.Author))
            {
                return(false);
            }

            return(Posts.Any(p =>
                             p.Processed &&
                             p.Origin.ID > post.Origin.ID &&
                             string.Equals(p.Origin.Author, post.Origin.Author, StringComparison.Ordinal)
                             ));
        }
Beispiel #9
0
 public void Initialize()
 {
     this.Database.EnsureCreated();
     if (Posts.Any() && Themes.Any() && Users.Any())
     {
         return;
     }
     Themes.Add(new Theme {
         Name = "Срочное"
     });
     Themes.Add(new Theme {
         Name = "Обычное"
     });
     SaveChanges();
     Users.Add(new User {
         UserName = "******"
     });
     SaveChanges();
     Posts.Add(new Post()
     {
         ThemeId        = Themes.FirstOrDefault().Id,
         UserId         = Users.FirstOrDefault().Id,
         Content        = "На этом месте 32 мая 1985 года ничего не произошло",
         Title          = "Срочно!",
         ContentPreview = "На этом месте...",
         Date           = DateTime.Today
     });
     Posts.Add(new Post()
     {
         ThemeId        = Themes.FirstOrDefault().Id,
         UserId         = Users.FirstOrDefault().Id,
         Content        = "Фантазии нет",
         Title          = "Не очень срочно",
         ContentPreview = "Фантаз...",
         Date           = DateTime.Today.AddDays(-1)
     });
     SaveChanges();
 }
 // etc...
 public bool CanDelete()
 {
     return(!Posts.Any() &&
            !Files.Any());    // &&
     // etc...
 }
Beispiel #11
0
 public ListViewModel(IRepository _mojaveRepository, int p)
 {
     Posts      = _mojaveRepository.Posts(p - 1, 10);
     TotalPosts = !Posts.Any() ? 0 : _mojaveRepository.TotalPosts();
 }
Beispiel #12
0
        public bool IsUnread(string userName)
        {
            var audit = Audits.LastOrDefault(x => x.UserName == userName);

            return(audit == null || Posts.Any(x => x.CreatedDate > audit.AuditDate));
        }