Esempio n. 1
0
        /// <summary>
        /// Method call to grab manga list via the online api
        /// Status: 0 = suspended, 1 = ongoing, 2 = completed.
        /// Last date: unix epoch time.
        /// </summary>
        /// <param name="index">Index to start list at. Use -1 to get entire list.</param>
        /// <param name="listSize">Size of the list to get. Use -1 to get entire list.</param>
        /// <param name="callback">Callback method to executed afterwards (Ideally on UI). Recieves a List of DAO.Manga as a parameter.</param>
        public async static void HttpGetMangaListAsync(int index, int listSize, Func <List <DAO.Manga>, bool> callback)
        {
            List <DAO.Manga> mangas = new List <DAO.Manga>();
            Uri        uri          = new Uri(API_STRING + "list/0/?p=" + index + "&l=" + listSize);
            HttpClient client       = new HttpClient();
            String     response     = null;

            if (index < 0 || listSize < 0)
            {
                uri = new Uri(API_STRING + "list/0/");
            }
            try
            {
                response = await client.GetStringAsync(uri);

                //Debug.WriteLine(response);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
            finally
            {
                if (response != null)
                {
                    dynamic jsonMangas = JsonConvert.DeserializeObject(response);
                    for (int i = 0; i < jsonMangas.manga.Count; i++)
                    {
                        //Debug.WriteLine("json: i: " + i);
                        DAO.Manga manga = new DAO.Manga
                        {
                            Id          = jsonMangas.manga[i].i,
                            Title       = jsonMangas.manga[i].t,
                            Alias       = jsonMangas.manga[i].a,
                            ImageString = jsonMangas.manga[i].im,
                            Hits        = jsonMangas.manga[i].h,
                        };
                        manga.SetLastDate("" + jsonMangas.manga[i].ld);
                        manga.SetStatus((int)jsonMangas.manga[i].s);
                        if (manga.ImageString != null)
                        {
                            manga.ImageString = API_IMG_STRING + manga.ImageString;
                        }
                        for (int k = 0; k < jsonMangas.manga[i].c.Count; k++)
                        {
                            manga.Categories.Add((string)jsonMangas.manga[i].c[k]);
                        }
                        mangas.Add(manga);
                    }
                }
            }
            //Debug.WriteLine("mangasSize: " + mangas.Count);
            callback.Invoke(mangas);
        }
Esempio n. 2
0
        /// <summary>
        /// Depricated test method
        /// Use: HttpGetMangaListAsync( ... )
        /// </summary>
        /// <param name="index"></param>
        /// <param name="number"></param>
        /// <param name="anonFunc"></param>
        public async static void HttpGetMangaTitleList(int index, int number, Func <List <DAO.Manga>, bool> anonFunc)
        {
            List <DAO.Manga> mangas = new List <DAO.Manga>();
            Uri        uri          = new Uri(API_STRING + "list/0/?p=" + index + "&l=" + number);
            HttpClient client       = new HttpClient();
            string     response     = null;

            try
            {
                response = await client.GetStringAsync(uri);
            } catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
            if (response != null)
            {
                //Debug.WriteLine("got JSON");
                // TODO Parse JSON
                dynamic   dynMangas = JsonConvert.DeserializeObject(response);
                DAO.Manga title     = new DAO.Manga();
            }
            anonFunc.Invoke(mangas);
        }