示例#1
0
        /// <summary>
        /// Returns a book object from the specified URI.
        /// This is a recursive function, because the JSON responses from the API are pointing to each other by URI-s.
        /// Gets all details of a book from the API, and for all the nested URI-s, it calls the right service.
        /// When it has constructed the full book object, returns it.
        /// </summary>
        public async Task <Book> GetBookAsyncFromFullUrl(Uri uri, int depth)
        {
            if (depth > 1)
            {
                return(null);
            }

            CharacterService characterService = CharacterService.Instance;
            var bookhelper = await GetAsync <BookHelper>(uri);

            var book = new Book()
            {
                url           = bookhelper.url,
                name          = bookhelper.name,
                isbn          = bookhelper.isbn,
                authors       = new ObservableCollection <string>(),
                numberOfPages = bookhelper.numberOfPages,
                publisher     = bookhelper.publisher,
                country       = bookhelper.country,
                mediaType     = bookhelper.mediaType,
                released      = bookhelper.released,
                characters    = new ObservableCollection <Character>(),
                povCharacters = new ObservableCollection <Character>()
            };

            foreach (var author in bookhelper.authors)
            {
                book.authors.Add(author);
            }
            start = 0;
            int end = start + charactersonpage;

            for (int i = start; i < end; ++i)
            {
                Character c = await characterService.GetCharacterAsyncFromFullUrl(new Uri(bookhelper.characters[i]), depth + 1);

                book.characters.Add(c);
            }
            foreach (var bookcharacter in bookhelper.povCharacters)
            {
                Character pc = await characterService.GetCharacterAsyncFromFullUrl(new Uri(bookcharacter), depth + 1);

                book.povCharacters.Add(pc);
            }

            return(book);
        }
        /// <summary>
        /// Returns a house object from the specified URI.
        /// This is a recursive function, because the JSON responses from the API are pointing to each other by URI-s.
        /// Gets all details of a house from the API, and for all the nested URI-s, it calls the right service.
        /// When it has constructed the full house object, returns it.
        /// </summary>
        public async Task <House> GetHouseAsyncFromFullUrl(Uri uri, int depth)
        {
            if (depth > 1)
            {
                return(null);
            }

            CharacterService characterService = CharacterService.Instance;
            var househelper = await GetAsync <HouseHelper>(uri);

            var house = new House()
            {
                url              = househelper.url,
                name             = househelper.name,
                region           = househelper.region,
                coatOfArms       = househelper.coatOfArms,
                words            = househelper.words,
                titles           = new ObservableCollection <string>(),
                seats            = new ObservableCollection <string>(),
                currentLord      = househelper.currentLord != "" ? await characterService.GetCharacterAsyncFromFullUrl(new Uri(househelper.currentLord), depth + 1) : null,
                heir             = househelper.heir != "" ? await characterService.GetCharacterAsyncFromFullUrl(new Uri(househelper.heir), depth + 1) : null,
                overlord         = househelper.overlord != "" ? await GetHouseAsyncFromFullUrl(new Uri(househelper.overlord), depth + 1) : null,
                founded          = househelper.founded,
                founder          = househelper.founder != "" ? await characterService.GetCharacterAsyncFromFullUrl(new Uri(househelper.founder), depth + 1) : null,
                diedOut          = househelper.diedOut,
                ancestralWeapons = new ObservableCollection <string>(),
                cadetBranches    = new ObservableCollection <House>(),
                swornMembers     = new ObservableCollection <Character>()
            };

            foreach (var title in househelper.titles)
            {
                house.titles.Add(title);
            }
            foreach (var seat in househelper.seats)
            {
                house.seats.Add(seat);
            }
            foreach (var wpn in househelper.ancestralWeapons)
            {
                house.ancestralWeapons.Add(wpn);
            }
            foreach (var cadetbranch in househelper.cadetBranches)
            {
                House h = await GetHouseAsyncFromFullUrl(new Uri(cadetbranch), depth + 1);

                house.cadetBranches.Add(h);
            }
            start = 0;
            int end = start + charactersonpage;

            if (end > househelper.swornMembers.Count())
            {
                end = househelper.swornMembers.Count();
            }
            for (int i = start; i < end; ++i)
            {
                Character c = await characterService.GetCharacterAsyncFromFullUrl(new Uri(househelper.swornMembers[i]), depth + 1);

                house.swornMembers.Add(c);
            }

            return(house);
        }