Example #1
0
        public static async Task <Manga.Chapter> CreateAndGetChapterAsync(Manga.Chapter chapter)
        {
            Debug.WriteLine("start: " + chapter.Number);
            await Task.Delay(5000);

            Debug.WriteLine("done: " + chapter.Number);
            return(chapter);
        }
Example #2
0
 /// <summary>
 /// If the Chapter doesn't exist it creates it.
 /// If the Chapter does exist it checks the HasViewed Property
 /// </summary>
 /// <param name="chapter">An already pre-filled Chapter object</param>
 /// <param name="mangaId">Id to Manga</param>
 /// <returns>Returns a modified Chapter that has an updated 'HasViewed' property</returns>
 public static Manga.Chapter CreateAndGetChapterLite(Manga.Chapter chapter, string mangaId)
 {
     if (chapter.Id != null && mangaId != null)
     {
         using (SqliteConnection db = new SqliteConnection(App.APP_DB_File))
         {
             db.Open();
             SqliteCommand readCommand = new SqliteCommand();
             readCommand.Connection  = db;
             readCommand.CommandText = "SELECT has_viewed FROM " + App.APP_MANGA_CHAPTER_TABLE + " WHERE chapter_id = @ID;";
             readCommand.Parameters.AddWithValue("@ID", chapter.Id);
             SqliteDataReader reader = null;
             try
             {
                 reader = readCommand.ExecuteReader();
             }
             catch (SqliteException e)
             {
                 Debug.WriteLine(e.TargetSite);
                 Debug.WriteLine(e.StackTrace);
             }
             if (reader != null)
             {
                 bool exists = false;
                 while (reader.Read())
                 {
                     exists = true;
                     chapter.setHasViewed(reader.GetString(0));
                 }
                 //Debug.WriteLine("chapter exists: " + exists);
                 if (!exists)
                 {
                     SqliteCommand insertCommand = new SqliteCommand();
                     insertCommand.Connection  = db;
                     insertCommand.CommandText = "INSERT INTO " + App.APP_MANGA_CHAPTER_TABLE + " (chapter_id, chapter_number, manga_id, date, chapter_title, has_viewed) VALUES (@ID, @NUM, @MANGA_ID, @DATE, @TITLE, @VIEWED);";
                     insertCommand.Parameters.AddWithValue("@ID", chapter.Id);
                     insertCommand.Parameters.AddWithValue("@MANGA_ID", mangaId);
                     insertCommand.Parameters.AddWithValue("@NUM", chapter.Number);
                     insertCommand.Parameters.AddWithValue("@DATE", chapter.Date);
                     insertCommand.Parameters.AddWithValue("@VIEWED", chapter.ViewedStatus.ToString());
                     if (chapter.Title != null)
                     {
                         insertCommand.Parameters.AddWithValue("@TITLE", chapter.Title);
                     }
                     else
                     {
                         insertCommand.Parameters.AddWithValue("@TITLE", DBNull.Value);
                     }
                     try
                     {
                         insertCommand.ExecuteReader();
                     }
                     catch (SqliteException e)
                     {
                         Debug.WriteLine(e.TargetSite);
                         Debug.WriteLine(e.StackTrace);
                     }
                 }
             }
             db.Close();
         }
     }
     return(chapter);
 }
        public static async Task GetManga(string id, Func <Manga.Manga, bool> callback)
        {
            Manga.Manga manga  = null;
            Uri         uri    = new Uri(MANGA_URL + "manga/" + id);
            HttpClient  client = new HttpClient();
            dynamic     json   = null;

            try
            {
                string jsonString = await client.GetStringAsync(uri);

                json = JsonConvert.DeserializeObject(jsonString);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.TargetSite);
                Debug.WriteLine(e.StackTrace);
            }
            if (json != null)
            {
                try
                {
                    manga = new Manga.Manga
                    {
                        Id          = id,
                        Title       = json.title,
                        ImageString = json.image,
                        Description = json.description,
                        Artist      = json.artist,
                        Author      = json.author,
                        Chapters    = new List <Manga.Chapter>(),
                        Categories  = new List <string>()
                    };
                    manga.SetStatus((int)json.status);
                    if (json.last_chapter_date != null)
                    {
                        manga.LastDate = (long)json.last_chapter_date;
                    }
                    if (manga.ImageString != null)
                    {
                        //Debug.WriteLine("valid image [ " + manga.ImageString + " ]");
                        //manga.Image = new BitmapImage(new Uri(IMAGE_URL + manga.ImageString));
                        manga.ImageString = IMAGE_URL + manga.ImageString;
                    }
                    else
                    {
                        manga.ImageString = IMAGE_URL;
                        //manga.Image = new BitmapImage();
                    }
                    for (int k = 0; k < json.categories.Count; k++)
                    {
                        string category = (string)json.categories[k];
                        //Debug.WriteLine("category [ " + category + " ]");
                        manga.Categories.Add(category);
                    }
                    for (int i = 0; i < json.chapters.Count; i++)
                    {
                        Manga.Chapter chapter = new Manga.Chapter
                        {
                            Id     = json.chapters[i][3],
                            Title  = json.chapters[i][2],
                            Number = (double)json.chapters[i][0]
                        };
                        if (json.chapters[i][1] != null)
                        {
                            chapter.Date = json.chapters[i][1];
                        }
                        manga.Chapters.Add(chapter);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.TargetSite);
                    Debug.WriteLine(e.StackTrace);
                }
            }
            callback.Invoke(manga);
        }