Example #1
0
        public void Execute(MediaWiki wiki, string[] commandLine)
        {
            var retries = 5;

            for (var i = 0; i < retries; i++)
            {
                try
                {
                    var page        = wiki.GetPageInfo(DidYouKnow.NextIssueName);
                    var preparation = new NextIssuePreparation(page.Text);
                    if (CheckPreparation(preparation, wiki, commandLine.Contains("-onlyNew")))
                    {
                        wiki.Edit(DidYouKnow.NextIssueName, preparation.FullText, "Автоматическое обновление страницы.", revId: page.Id);
                    }
                    return;
                }
                catch (MediaWikiApiException ex)
                {
                    if (ex.Code == MediaWiki.ErrorCode.EditConflict)
                    {
                        continue;
                    }
                    throw;
                }
            }

            throw new Exception($"Edit conflict after {retries} retries");
        }
Example #2
0
        private bool CheckPreparation(NextIssuePreparation preparation, MediaWiki wiki, bool onlyNew)
        {
            var hasChanges = false;

            if (preparation.NewSections != null && preparation.NewSections.Count > 0)
            {
                preparation.Sections.InsertRange(0, preparation.NewSections);
                preparation.NewSections.Clear();
                hasChanges = true;
            }

            foreach (var article in preparation.Sections.SelectMany(s => s.Articles).ToArray())
            {
                if (onlyNew && article.Status != null)
                {
                    continue;
                }
                if (article.Status != null && article.Status.Extra != null)
                {
                    continue;
                }

                article.Status = CheckStatus(wiki, article.Title) ?? CheckValidness(wiki, article.Title);
                hasChanges     = true;
            }

            if (hasChanges)
            {
                preparation.Update();
            }

            return(hasChanges);
        }
Example #3
0
        public void RemoveMarkedFromNextIssue(DateTime issueDate)
        {
            var nip = new NextIssuePreparation(_wiki.GetPage(NextIssueName));

            foreach (var item in nip.Sections.Where(x => x.GetIssueDate() == issueDate).ToList())
            {
                nip.Sections.Remove(item);
            }
            nip.Update();
            _wiki.Edit(NextIssueName, nip.FullText, "Автоматическое удаление использованных анонсов.");
        }