Beispiel #1
0
        public ActionResult FillDocument(int id)
        {
            var template = _templatesRepositoryHandler.FindById(id);

            template = new HtmlDocumentHandler(GetUserName()).ConvertView(template);

            ViewBag.FullName = GetUserName();
            return(View(DocumentTemplateController.ConvertToModel(template)));
        }
Beispiel #2
0
        static HtmlNodeCollection GetNodeListOfAllMoves()
        {
            var mainSite   = "https://bulbapedia.bulbagarden.net/wiki/List_of_moves";
            var mainDoc    = HtmlDocumentHandler.GetDocumentOrNullIfError(mainSite);
            var movesTable = mainDoc.DocumentNode.SelectSingleNode("//table//tr//td");
            var nodeListOfMoveNamesAndLinks = movesTable.SelectNodes(".//tr//td[2]//a");

            return(nodeListOfMoveNamesAndLinks);
        }
Beispiel #3
0
        public ActionResult ConvertView(DocumentTemplate template)
        {
            var userName = new MainController().GetUserName();

            var newTemplate =
                new HtmlDocumentHandler(userName)
                .ConvertView(DocumentTemplateController.ConvertToBlModel(template));

            return(View(DocumentTemplateController.ConvertToModel(newTemplate)));
        }
Beispiel #4
0
        public ActionResult ConvertView(DocumentTemplate template)
        {
            _documentRepositoryHandler =
                new HtmlDocumentHandler(GetUserName());
            DocumentTemplate newTemplate = null;

            if (template.Text != null)
            {
                newTemplate = ConvertToModel
                                  (_documentRepositoryHandler.ConvertView(ConvertToBlModel(template)));
            }

            return(View("Preview", newTemplate));
        }
Beispiel #5
0
        public void FillGameSystemData(Dictionary <string, string> checkedGamesData)
        {
            var doc = HtmlDocumentHandler.GetDocumentOrNullIfError(BaseUrl + UrlSuffix);

            if (doc == null)
            {
                throw new HtmlWebException("Could not load webpage.");
            }

            HtmlNode nameNode = doc.DocumentNode.SelectSingleNode("//*[@class='navpath']//b");

            if (nameNode != null)
            {
                var nameNodeString = nameNode.InnerText;
                Name = nameNodeString.Substring(0, nameNodeString.Length - 6).Trim();
            }

            HtmlNodeCollection gameDataTableRows = doc.DocumentNode.SelectNodes(
                "//*[@class='smalltable']//tr[position()>1]");

            if (gameDataTableRows is null)
            {
                Console.WriteLine($"Could not find data on games for the system '{Name}'.");
                return;
            }
            foreach (var tableRowNode in gameDataTableRows)
            {
                var linkNode = tableRowNode.SelectSingleNode(".//a");
                if (linkNode is null)
                {
                    continue;
                }
                var link = linkNode.Attributes["href"].Value;
                if (checkedGamesData.ContainsKey(link))
                {
                    GamesData[link] = checkedGamesData[link];
                }
                else
                {
                    var newGame = new Game(link);
                    newGame.SaveData();
                    GamesData[link]        = newGame.Name;
                    checkedGamesData[link] = newGame.Name;
                }
            }
        }
Beispiel #6
0
        static HashSet <string> GetSetOfPokemonToLearnMove(string movePageUrl, string moveName)
        {
            var movePageDoc = HtmlDocumentHandler.GetDocumentOrNullIfError(movePageUrl);

            /*
             * Select all of the sibling tables between the h2 tag with the span of id "Learnset" (i.e., the Learnset
             * section), but before the next h2 tag (i.e., whatever the next section is).
             * This ensures we only get tables in the Learnset section of the wiki page, which is where the only relevant
             * tables are.
             * This may included tables titled "by leveling up", "by HM", "by event", etc.
             */
            var tablesOfPokemonToLearnMove = movePageDoc.DocumentNode.SelectNodes("//h2[span[@id='Learnset']]/" +
                                                                                  "following-sibling::h2[1]/preceding-sibling::table[@class='roundy'][tr[1]/th[contains(., 'Pokémon')]]");

            var setOfPokemonToLearnMove = new HashSet <string>();

            if (tablesOfPokemonToLearnMove is null)
            {
                Console.WriteLine($"No learnset tables were found for the move '{moveName}'.");
            }
            else
            {
                foreach (var tableNode in tablesOfPokemonToLearnMove)
                {
                    GetDistinctPokemonFromTable(tableNode, setOfPokemonToLearnMove, moveName);
                }
            }
            //catch (NullReferenceException)
            //{
            //    Console.Error.WriteLine("Move data could not be found for the move at the following page:");
            //    Console.Error.WriteLine($"\t{movePageUrl}");
            //    Console.Error.WriteLine("If the move does not normally have any set pokemon that can learn it (Such " +
            //        "as Struggle or Breakneck Blitz) or is a Z-move (such as Catastropika), this is not an error, as " +
            //        "those moves are intentionally ignored. Otherwise, you may wish to take note of this.");
            //    Console.Error.WriteLine();
            //    Console.Error.WriteLine();
            //}

            return(setOfPokemonToLearnMove);
        }
Beispiel #7
0
        static HashSet <string> GetSetOfGenderlessPokemon()
        {
            var setOfGenderlessPokemon = new HashSet <string>();
            var genderlessDoc          = HtmlDocumentHandler.GetDocumentOrNullIfError("https://bulbapedia.bulbagarden.net/wiki/" +
                                                                                      "Gender_unknown_(Egg_Group)");

            // The h2 tag with the span containing the text "Pokémon" is the "Pokémon" section of the wiki page
            // Select all nested tables within/after this section that have a header containing the text "Pokémon" in
            // its first row
            var tablesOfGenderlessPokemon = genderlessDoc.DocumentNode.SelectNodes("//h2[span" +
                                                                                   "[text()='Pokémon']]/following-sibling::table//table[tr[1]/th[contains(., 'Pokémon')]]");

            foreach (var table in tablesOfGenderlessPokemon)
            {
                var pokemonInTable = table.SelectNodes(".//tr/td[3]");
                foreach (var pokemon in pokemonInTable)
                {
                    setOfGenderlessPokemon.Add(pokemon.InnerText.Trim());
                }
            }
            return(setOfGenderlessPokemon);
        }
Beispiel #8
0
        public static Dictionary <string, HashSet <string> > GetDictOfGeneralTMsAndIncompatiblePokemon()
        {
            var setOfPokemonThatCannotLearnGeneralTMs = new HashSet <string>();
            var dictOfTMsAndPokemonExceptions         = new Dictionary <string, HashSet <string> >();

            var tmDoc = HtmlDocumentHandler.GetDocumentOrNullIfError("https://bulbapedia.bulbagarden.net/wiki/TM");

            // The h2 tag with the span of id "Incompatible_Pok..." is the "Incompatible Pokémon" section of the wiki
            // page
            // Select the first nested table within this section
            var tableOfPokemonThatCannotLearnGeneralTMs = tmDoc.DocumentNode.SelectSingleNode("//h2[span" +
                                                                                              "[starts-with(@id, 'Incompatible_Pok')]]/following-sibling::table//table");

            FillSetOfPokemonAndDictOfExceptions(dictOfTMsAndPokemonExceptions, setOfPokemonThatCannotLearnGeneralTMs,
                                                tableOfPokemonThatCannotLearnGeneralTMs);

            var tableOfGeneralTMs = tmDoc.DocumentNode.SelectSingleNode("//h2[span" +
                                                                        "[@id='Near-universal_TMs']]/following-sibling::table//table");

            var dictOfGeneralTMsAndIncompatiblePokemon = new Dictionary <string, HashSet <string> >();

            FillDictOfGeneralTMsAndIncompatiblePokemon(dictOfGeneralTMsAndIncompatiblePokemon,
                                                       setOfPokemonThatCannotLearnGeneralTMs, tableOfGeneralTMs);

            foreach (var move in dictOfTMsAndPokemonExceptions.Keys)
            {
                if (!dictOfGeneralTMsAndIncompatiblePokemon.ContainsKey(move))
                {
                    continue;
                }
                dictOfGeneralTMsAndIncompatiblePokemon[move] = dictOfGeneralTMsAndIncompatiblePokemon[move].Except(
                    dictOfTMsAndPokemonExceptions[move]).ToHashSet();
            }

            return(dictOfGeneralTMsAndIncompatiblePokemon);
        }
 public AdminController()
 {
     DocumentHandler = new HtmlDocumentHandler(AccountController.FullName);
 }