/// <summary> /// Create a list of table entries from a padoru collection /// </summary> /// <param name="pCollection">the padoru collection to create the list from</param> /// <returns>the table of contents data</returns> async Task <ToCData> CreateData(PadoruCollection pCollection) { //initialize jikan to resolve character names, shows, etc Jikan jikan = new Jikan(); //enumerate all padorus List <ToCEntry> tocCharacters = new List <ToCEntry>(); List <ToCCreator> tocCreators = new List <ToCCreator>(); List <ToCShow> tocShows = new List <ToCShow>(); foreach (PadoruEntry pEntry in pCollection.Entries) { //create entry with base values ToCEntry toc = new ToCEntry() { CharacterName = pEntry.Name, ContributorName = pEntry.ImageContributor, //CreatorName = pEntry.ImageCreator, SourceUrl = pEntry.ImageSource, ImageUrl = pEntry.ImageUrl }; //get character info from jikan if (pEntry.MALId.HasValue) { //get mal character Character charInfo = await jikan.GetCharacter(pEntry.MALId.Value); if (charInfo != null) { #region Get Character's shows List <ToCShow> cShows = new List <ToCShow>(); //get anime this character is in if (charInfo.Animeography.Count > 0) { foreach (MALImageSubItem anime in charInfo.Animeography) { //check if shows list already contains this anime ToCShow tocAnime = null; if (tocShows.HasAnyWhere((s) => s.MalId.Equals(anime.MalId))) { //show already exists, try to get it tocAnime = tocShows.Where((s) => s.MalId.Equals(anime.MalId)).FirstOrDefault(); } //create new toc show if still null (not in list or get from list failed) if (tocAnime == null) { tocAnime = new ToCShow() { Name = anime.Name, MalUrl = anime.Url, MalId = anime.MalId }; } //add current anime to list of shows cShows.Add(tocAnime); } } //get manga this character is in if (charInfo.Mangaography.Count > 0) { foreach (MALImageSubItem manga in charInfo.Mangaography) { //check if shows list already contains this anime ToCShow tocManga = null; if (tocShows.HasAnyWhere((s) => s.MalId.Equals(manga.MalId))) { //show already exists, try to get it tocManga = tocShows.Where((s) => s.MalId.Equals(manga.MalId)).FirstOrDefault(); } //create new toc show if still null (not in list or get from list failed) if (tocManga == null) { tocManga = new ToCShow() { Name = manga.Name, MalUrl = manga.Url, MalId = manga.MalId }; } //add current anime to list of shows cShows.Add(tocManga); } } //add current character to all shows foreach (ToCShow show in cShows) { show.Characters.Add(toc); } //set shows of character toc.CharacterShows = cShows; //add all shows to global list tocShows.AddRange(cShows); #endregion //override name and set mal id toc.CharacterName = charInfo.Name; toc.MalId = charInfo.MalId.ToString(); //set character nickname list if (charInfo.Nicknames.Count > 0) { toc.CharacterNicks = charInfo.Nicknames.ToArray(); } } } #region Set Creator Info //check if there is already a creator entry matching the current entrys creator name ToCCreator creator = null; if (tocCreators.HasAnyWhere((c) => c.Name.EqualsIgnoreCase(pEntry.ImageCreator))) { //already has a entry, try use that creator = tocCreators.Where((c) => c.Name.EqualsIgnoreCase(pEntry.ImageCreator)).FirstOrDefault(); } //create new creator entry if is still null (no creator found or get failed) if (creator == null) { //Create new creator creator = new ToCCreator() { Name = pEntry.ImageCreator }; //add it to the list of creators tocCreators.Add(creator); } //add this entry to the creator and this creator to the current entry creator.Entries.Add(toc); toc.Creator = creator; #endregion //add toc entry to list tocCharacters.Add(toc); } return(new ToCData() { Characters = tocCharacters, Creators = tocCreators, Shows = tocShows }); }
/// <summary> /// Create a Creator page for the given toc creator /// </summary> /// <param name="toc">the toc creator to create a creator page for</param> void CreateCreatorPage(ToCCreator toc, string savePath) { CreateCharactersIndexPage(toc.Entries, savePath, $"# Padorus by {toc.Name}"); }