public SpeciesPageBuilder(Species species, WikiPageTemplate template)
        {
            if (species is null)
            {
                throw new ArgumentNullException("species");
            }

            if (template is null)
            {
                throw new ArgumentNullException("template");
            }

            Species  = species;
            Template = template;
        }
        public SpeciesPageBuilder(ISpecies species, WikiPageTemplate template, SQLiteDatabase database)
        {
            if (species is null)
            {
                throw new ArgumentNullException(nameof(species));
            }

            if (template is null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            Species  = species;
            Template = template;

            this.database = database;
        }
Beispiel #3
0
        public async Task MainAsync(string[] args)
        {
            _log("loading configuration");

            Config config = JsonConvert.DeserializeObject <Config>(System.IO.File.ReadAllText("wikibot-config.json"));

            _log("initializing mediawiki client");

            MediaWikiClient client = new MediaWikiClient {
                Protocol  = config.Protocol,
                Server    = config.Server,
                ApiPath   = config.ApiPath,
                UserAgent = config.UserAgent
            };

            client.Log += _log;

            EditHistory history = new EditHistory();

            if (client.Login(config.Username, config.Password).Success)
            {
                _log("generating link dictionary");

                WikiLinkList LinkifyList = await _generateLinkifyListAsync();

                _log("synchronizing species");
                _log("getting species from database");

                Species[] speciesList = await SpeciesUtils.GetSpeciesAsync();

                _log(string.Format("got {0} results", speciesList.Count()));

                foreach (Species species in speciesList)
                {
                    _log(string.Format("synchronizing species {0}", species.ShortName));

                    // Create the page builder.

                    SpeciesPageBuilder pageBuilder = new SpeciesPageBuilder(species, WikiPageTemplate.Open(SpeciesTemplateFilePath))
                    {
                        AllSpecies = speciesList,
                        LinkList   = LinkifyList
                    };

                    // Attempt to upload the species' picture.

                    pageBuilder.PictureFilenames.Add(await UploadSpeciesPictureAsync(client, history, species));
                    pageBuilder.PictureFilenames.AddRange(await UploadSpeciesGalleryAsync(client, history, species));
                    pageBuilder.PictureFilenames.RemoveAll(x => string.IsNullOrWhiteSpace(x));

                    // Generate page content.

                    WikiPage wikiPage = await pageBuilder.BuildAsync();

                    string pageTitle      = wikiPage.Title;
                    bool   createRedirect = pageTitle != species.FullName;

                    // Upload page content.

                    await _editSpeciesPageAsync(client, history, species, pageTitle, wikiPage.Body);

                    // Attempt to create the redirect page for the species (if applicable).

                    if (createRedirect)
                    {
                        string redirect_page_title = species.FullName;

                        if (await _editPageAsync(client, history, redirect_page_title, string.Format("#REDIRECT [[{0}]]", pageTitle) + "\n" + BotFlag))
                        {
                            await history.AddRedirectRecordAsync(redirect_page_title, pageTitle);
                        }
                    }

                    _log(string.Format("finished synchronizing species {0}", species.ShortName));
                }
            }
            else
            {
                _log("mediawiki login failed");
            }

            _log("synchronizing complete");

            await Task.Delay(-1);
        }