コード例 #1
0
        /// <summary>
        /// Method call to get all the images from a manga chapter
        /// </summary>
        /// <param name="mangaChapter"></param>
        /// <param name="callback"></param>
        public async static void HttpGetMangaChapterAsync(String mangaChapterId, Func <DAO.MangaChapter, bool> callback)
        {
            DAO.MangaChapter mangaChapter = null;
            if (mangaChapterId == null)
            {
                callback.Invoke(null);
                return;
            }
            //Debug.WriteLine("URL: " + (API_STRING + "chapter/" + mangaChapterId));
            Uri        uri      = new Uri(API_STRING + "chapter/" + mangaChapterId);
            HttpClient client   = new HttpClient();
            String     response = null;

            try
            {
                response = await client.GetStringAsync(uri);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
            finally
            {
                if (response != null)
                {
                    /*
                     *  0 - index
                     *  1 - image string
                     */
                    dynamic jsonChapter = JsonConvert.DeserializeObject(response);
                    mangaChapter = new DAO.MangaChapter
                    {
                        ChapterId = mangaChapterId
                    };
                    for (int i = jsonChapter.images.Count - 1; i >= 0; i--)                      // should put it in correct order
                    {
                        BitmapImage image       = null;
                        string      imageString = jsonChapter.images[i][1];
                        if (imageString != null)
                        {
                            //Debug.WriteLine("full image");
                            image = new BitmapImage(new Uri(API_IMG_STRING + imageString));
                        }
                        else
                        {
                            //Debug.WriteLine("empty image");
                            image = new BitmapImage();
                        }
                        mangaChapter.Images.Add(image);
                    }
                }
            }
            callback.Invoke(mangaChapter);
        }
コード例 #2
0
        /// <summary>
        /// Method call to get a single manga
        /// </summary>
        /// <param name="mangaId"></param>
        /// <param name="callback"></param>
        public async static void HttpGetMangaAsync(string mangaId, Func <DAO.MangaStorage, bool> callback)
        {
            //Debug.WriteLine("Get Manga Async");
            DAO.MangaStorage manga = null;
            Uri        uri         = new Uri(API_STRING + "manga/" + mangaId);
            HttpClient client      = new HttpClient();
            String     response    = null;

            try
            {
                response = await client.GetStringAsync(uri);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
            finally
            {
                if (response != null)
                {
                    dynamic jsonManga = JsonConvert.DeserializeObject(response);
                    manga = new DAO.MangaStorage
                    {
                        Id          = mangaId,
                        Title       = jsonManga.title,
                        Alias       = jsonManga.alias,
                        Author      = jsonManga.author,
                        Description = jsonManga.description
                    };
                    manga.Description = manga.Description.Replace("&#039;", "'").Replace("&quot;", "\"").Replace("&#333;", "ō");
                    //string text = "Early D: " + jsonManga.description;
                    //Debug.WriteLine(text);
                    manga.SetLastDate("" + jsonManga.last_chapter_date);
                    //text = "chapter count: " + jsonManga.chapters.Count;
                    //Debug.WriteLine(text);
                    manga.SetStatus((int)jsonManga.status);
                    if (jsonManga.image != null)
                    {
                        manga.ImageString = API_IMG_STRING + jsonManga.image;
                    }
                    for (int i = 0; i < jsonManga.categories.Count; i++)
                    {
                        manga.Categories.Add((string)jsonManga.categories[i]);
                    }
                    for (int i = 0; i < jsonManga.chapters.Count; i++)
                    {
                        /*
                         *  0 - chapter # (double)
                         *  1 - upload date
                         *  2 - title (string or null)
                         *  3 - id (string)
                         */
                        DAO.MangaChapter chapter = new DAO.MangaChapter
                        {
                            ChapterId     = jsonManga.chapters[i][3],
                            ChapterNumber = jsonManga.chapters[i][0],
                            Date          = "" + jsonManga.chapters[i][1],
                            ChapterTitle  = jsonManga.chapters[i][2]                                            // May be null
                        };
                        if (chapter.ChapterTitle == null)
                        {
                            chapter.ChapterTitle = manga.Title + " : Chapter " + chapter.ChapterNumber;
                        }
                        manga.Chapters.Add(chapter);
                    }
                    if (manga.ImageString != null)
                    {
                        manga.ImageBuffer = await client.GetBufferAsync(new Uri(manga.ImageString));
                    }
                }
                else
                {
                    Debug.WriteLine("mission failed, we'll get em next time");
                }
            }
            callback.Invoke(manga);
        }