Exemplo n.º 1
0
        private void CreateTheme(IReadOnlyCollection <string> keywordIntersection, ThemeArticle article)
        {
            var matchingArticles = _articles
                                   .Where(x => x.ContainsKeywords(keywordIntersection))
                                   .Append(article)
                                   .ToArray();

            Apply(new NewThemeCreated(Guid.NewGuid(), keywordIntersection, matchingArticles));
        }
Exemplo n.º 2
0
        public void Add(ThemeArticle article)
        {
            foreach (var existingArticle in _articles)
            {
                var keywordIntersection = existingArticle.ContainsKeywords(article);
                if (!keywordIntersection.Any())
                {
                    continue;
                }
                var matchingThemes = _themes.Where(theme => theme.Keywords.Intersect(keywordIntersection).Count() == theme.Keywords.Count).ToList();
                if (matchingThemes.Any())
                {
                    foreach (var matchingTheme in matchingThemes.Where(matchingTheme => !matchingTheme.Contains(article)))
                    {
                        Apply(new ArticleAddedToTheme(matchingTheme.Id, article));
                    }
                }
                if (matchingThemes.All(x => x.Keywords.Count != keywordIntersection.Count))
                {
                    CreateTheme(keywordIntersection, article);
                }
            }

            foreach (var theme in _themes.ToList())
            {
                var keywordIntersection = theme.ContainsKeywords(article);
                if (!keywordIntersection.Any())
                {
                    continue;
                }
                var existingTheme = _themes.FirstOrDefault(x => x.Keywords.SequenceEqual(keywordIntersection));
                if (existingTheme == null)
                {
                    Apply(new NewThemeCreated(Guid.NewGuid(), keywordIntersection, theme.Articles.Append(article).ToArray()));
                }
                else if (!existingTheme.Contains(article))
                {
                    Apply(new ArticleAddedToTheme(existingTheme.Id, article));
                }
            }

            _articles.Add(article);
        }
Exemplo n.º 3
0
 public IReadOnlyCollection <string> ContainsKeywords(ThemeArticle article)
 {
     return(Keywords.Intersect(article.Keywords).ToArray());
 }
Exemplo n.º 4
0
 public bool Contains(ThemeArticle article)
 {
     return(_articles.Contains(article));
 }
Exemplo n.º 5
0
 public void AddArticle(ThemeArticle article)
 {
     _articles.Add(article);
 }
 public ArticleAddedToTheme(Guid themeId, ThemeArticle article) : base(themeId, "theme")
 {
     Article = article;
 }