Ejemplo n.º 1
0
        public Task <YugiohCardCompletion> Publish(ArticleProcessed articleProcessed)
        {
            var yugiohCardCompletion = new YugiohCardCompletion();

            yugiohCardCompletion.Card    = articleProcessed.Card;
            yugiohCardCompletion.Article = articleProcessed.Article;

            try
            {
                var messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(articleProcessed.Card));

                var factory = new ConnectionFactory()
                {
                    HostName = _rabbitMqConfig.Value.Host, Port = _rabbitMqConfig.Value.Port
                };
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        var props = channel.CreateBasicProperties();
                        props.ContentType  = _rabbitMqConfig.Value.ContentType;
                        props.DeliveryMode = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersData].PersistentMode;

                        props.Headers = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersData].Headers.ToDictionary(k => k.Key, k => (object)k.Value);

                        channel.BasicPublish
                        (
                            RabbitMqExchangeConstants.YugiohHeadersData,
                            "",
                            props,
                            messageBodyBytes
                        );
                    }

                yugiohCardCompletion.IsSuccessful = true;
            }
            catch (System.Exception ex)
            {
                yugiohCardCompletion.Exception = new YugiohCardException {
                    Card = articleProcessed.Card, Exception = ex
                };
            }

            return(Task.FromResult(yugiohCardCompletion));
        }
Ejemplo n.º 2
0
        public async Task <ArticleProcessed> Process(Article article)
        {
            var response = new ArticleProcessed {
                Article = article
            };

            var articleDetailsList = await _wikiArticle.Details((int)article.Id);

            var(_, expandedArticle) = articleDetailsList.Items.First();

            var banlistArticleSummary = BanlistHelpers.ExtractBanlistArticleDetails(expandedArticle.Id, expandedArticle.Abstract);

            if (banlistArticleSummary != null)
            {
                const char beginChar = '「';
                const char endChar   = '」';

                var banlist = new YugiohBanlist
                {
                    ArticleId   = banlistArticleSummary.ArticleId,
                    Title       = expandedArticle.Title,
                    BanlistType = banlistArticleSummary.BanlistType,
                    StartDate   = banlistArticleSummary.StartDate
                };

                var banlistContentResult = await _wikiArticle.Simple(banlistArticleSummary.ArticleId);

                _logger.LogInformation($"{banlist.BanlistType.ToString()}, {banlist.Title}, {banlist.StartDate}");
                foreach (var section in banlistContentResult.Sections)
                {
                    // skip references section
                    if (section.Title.ToLower() == "references")
                    {
                        continue;
                    }

                    // new section
                    var ybls = new YugiohBanlistSection
                    {
                        Title   = StringHelpers.RemoveBetween(section.Title, beginChar, endChar).Trim(),
                        Content = ContentResultHelpers.GetSectionContentList(section).OrderBy(c => c).ToList()
                    };

                    // remove invalid characters
                    if (ybls.Content.Any())
                    {
                        ybls.Content = ybls.Content.Select(c => StringHelpers.RemoveBetween(c, beginChar, endChar)).ToList();
                    }

                    banlist.Sections.Add(ybls);
                }

                response.Banlist = banlist;

                var publishBanlistResult = await _banlistDataQueue.Publish(new ArticleProcessed { Article = article, Banlist = banlist });

                response.IsSuccessful = publishBanlistResult.IsSuccessful;
            }

            return(response);
        }