/// <summary> /// To be called by MangaPage which gets a full copy of a manga /// </summary> /// <param name="manga"></param> /// <returns></returns> public static async Task CreateMangaAsync(Manga.Manga manga) { if (manga.Id != null && manga.Title != null) { using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { } } }
public static async Task <bool> CreateMangaAsyncLite(Manga.Manga manga) { bool flag = true; if (manga.Id != null && manga.Title != null) { using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { //Debug.WriteLine("mark 1"); await db.OpenAsync(); //Debug.WriteLine("mark 2"); // Insert Command SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; insertCommand.CommandText = "INSERT OR IGNORE INTO " + App.APP_MANGA_TABLE + " (manga_id, manga_title, image_url, status) VALUES (@ID, @TITLE, @URL, @STATUS);"; insertCommand.Parameters.AddWithValue("@ID", manga.Id); insertCommand.Parameters.AddWithValue("@TITLE", manga.Title); insertCommand.Parameters.AddWithValue("@URL", manga.ImageString); insertCommand.Parameters.AddWithValue("@STATUS", manga.Status.ToString()); //Debug.WriteLine("ID: " + manga.Id + '\n' + "Title: " + manga.Title + '\n' + "Status: " + manga.Status.ToString()); try { await insertCommand.ExecuteReaderAsync(); } catch (SqliteException e) { flag = false; Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); //Debug.WriteLine("Bad Insert"); } db.Close(); //Debug.WriteLine("mark 3"); } return(flag); } else { return(false); } }
public static async Task <List <Manga.Manga> > GetMangasFromCategoryAsync(string category) { List <Manga.Manga> mangas = new List <Manga.Manga>(); if (category != null && Sanitize.SanitizeString(category) != null) { using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { await db.OpenAsync(); SqliteCommand sqliteCommand = new SqliteCommand(); sqliteCommand.Connection = db; sqliteCommand.CommandText = "SELECT " + App.APP_MANGA_TABLE + ".manga_id, manga_title, image_url FROM " + App.APP_MANGA_TABLE + " INNER JOIN " + App.APP_MANGA_CATEGORY_TABLE + " ON " + App.APP_MANGA_TABLE + ".manga_id = " + App.APP_MANGA_CATEGORY_TABLE + ".manga_id WHERE category = @CATEGORY ORDER BY hits DESC;"; sqliteCommand.Parameters.AddWithValue("@CATEGORY", category); SqliteDataReader reader = null; try { reader = await sqliteCommand.ExecuteReaderAsync(); } catch (SqliteException e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } if (reader != null) { while (await reader.ReadAsync()) { Manga.Manga manga = new Manga.Manga(); manga.Id = reader.GetString(0); manga.Title = reader.GetString(1); manga.ImageString = reader.GetString(2); mangas.Add(manga); } } db.Close(); } } return(mangas); }
public static async Task <List <Manga.Manga> > GetMangasFromTitleAsync(string title) { List <Manga.Manga> mangas = new List <Manga.Manga>(); if (title != null && Sanitize.SanitizeString(title) != null) { using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { await db.OpenAsync(); SqliteCommand sqliteCommand = new SqliteCommand(); sqliteCommand.Connection = db; sqliteCommand.CommandText = "SELECT manga_id, manga_title, image_url FROM " + App.APP_MANGA_TABLE + " WHERE manga_title LIKE '%" + title + "%' COLLATE NOCASE ORDER BY hits DESC;"; //sqliteCommand.Parameters.AddWithValue("@TITLE", title); SqliteDataReader reader = null; try { reader = await sqliteCommand.ExecuteReaderAsync(); } catch (SqliteException e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } if (reader != null) { while (await reader.ReadAsync()) { //Debug.WriteLine("read"); Manga.Manga manga = new Manga.Manga(); manga.Id = reader.GetString(0); manga.Title = reader.GetString(1); manga.ImageString = reader.GetString(2); mangas.Add(manga); } } db.Close(); } } return(mangas); }
/// <summary> /// Gets List of Mangas that are favorited. /// Only gets the id and title. /// </summary> /// <returns></returns> public static async Task <List <Manga.Manga> > GetFavoriteMangasAsyncLite() { List <Manga.Manga> mangas = new List <Manga.Manga>(); using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { await db.OpenAsync(); SqliteCommand readCommand = new SqliteCommand(); readCommand.Connection = db; readCommand.CommandText = "SELECT " + App.APP_MANGA_TABLE + ".manga_id, manga_title FROM " + App.APP_MANGA_TABLE + " INNER JOIN " + App.APP_MANGA_FAVORITE_TABLE + " ON " + App.APP_MANGA_TABLE + ".manga_id = " + App.APP_MANGA_FAVORITE_TABLE + ".manga_id;"; SqliteDataReader reader = null; try { reader = await readCommand.ExecuteReaderAsync(); } catch (SqliteException e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } if (reader != null) { while (await reader.ReadAsync()) { Manga.Manga manga = new Manga.Manga(); manga.Id = reader.GetString(0); manga.Title = reader.GetString(1); mangas.Add(manga); } } db.Close(); } return(mangas); }
/// <summary> /// Used for the Home Page, Gets All Manga Titles. /// </summary> /// <returns>List of minimally filled Manga Objects (Id, Title, ImageString, Hits, LastDate)</returns> public static async Task GetIndividualMangaTitlesAsync(Func <Manga.Manga, bool> callback) { //List<Manga.Manga> mangas = new List<Manga.Manga>(); Uri uri = new Uri(MANGA_URL + "list/0/"); 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) { for (int i = 0; i < json.manga.Count; i++) { try { Manga.Manga manga = new Manga.Manga { Id = json.manga[i].i, Title = json.manga[i].t, ImageString = json.manga[i].im, Hits = json.manga[i].h, Categories = new List <string>() }; manga.SetStatus((int)json.manga[i].s); 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(); } if (json.manga[i].ld != null) { manga.LastDate = (long)json.manga[i].ld; } for (int k = 0; k < json.manga[i].c.Count; k++) { string category = json.manga[i].c[k]; //Debug.WriteLine("category [ " + category + " ]"); manga.Categories.Add(category); } //mangas.Add(manga); if (!callback.Invoke(manga)) { break; } } catch (Exception e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } } } Debug.WriteLine("Done Getting Manga 1"); //callback.Invoke(mangas); }
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); }
/// <summary> /// To be called after updating DB with all titles /// </summary> /// <param name="manga"></param> /// <returns></returns> public static async Task UpdateMangaAsync(Manga.Manga manga) { if (manga.Id != null && manga.Title != null) { //Debug.WriteLine("Update Manga: " + manga.Id + " - " + manga.Title); using (SqliteConnection db = new SqliteConnection(App.APP_DB_File)) { bool flag = true; await db.OpenAsync(); SqliteCommand updateCommand = new SqliteCommand(); updateCommand.Connection = db; updateCommand.CommandText = "UPDATE " + App.APP_MANGA_TABLE + " SET manga_title = @TITLE, image_url = @URL, " + "author = @AUTHOR, artist = @ARTIST, hits = @HITS, description = @DESCRIPTION, last_date = @DATE, " + "status = @STATUS WHERE manga_id = @ID;"; //updateCommand.CommandText = "UPDATE " + App.APP_MANGA_TABLE + " SET manga_title = @TITLE, last_date = @DATE, status = @STATUS, hits = @HITS, image_url = @URL, author = @AUTHOR, artist = @ARTIST WHERE manga_id = @ID;"; //Debug.WriteLine("Params start"); updateCommand.Parameters.AddWithValue("@ID", manga.Id); updateCommand.Parameters.AddWithValue("@TITLE", manga.Title); updateCommand.Parameters.AddWithValue("@DATE", manga.LastDate); updateCommand.Parameters.AddWithValue("@STATUS", manga.Status.ToString()); updateCommand.Parameters.AddWithValue("@HITS", manga.Hits); //Debug.WriteLine("Params mid"); if (manga.ImageString != null) { updateCommand.Parameters.AddWithValue("@URL", manga.ImageString); } else { updateCommand.Parameters.AddWithValue("@URL", DBNull.Value); } if (manga.Author != null) { updateCommand.Parameters.AddWithValue("@AUTHOR", manga.Author); } else { updateCommand.Parameters.AddWithValue("@AUTHOR", DBNull.Value); } if (manga.Artist != null) { updateCommand.Parameters.AddWithValue("@ARTIST", manga.Artist); } else { updateCommand.Parameters.AddWithValue("@ARTIST", DBNull.Value); } if (manga.Description != null) { updateCommand.Parameters.AddWithValue("@DESCRIPTION", manga.Description); } else { updateCommand.Parameters.AddWithValue("@DESCRIPTION", DBNull.Value); } //Debug.WriteLine("Params end"); try { await updateCommand.ExecuteReaderAsync(); } catch (SqliteException e) { //Debug.WriteLine("Manga: " + manga.Id + " - " + manga.Title); flag = false; Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } updateCommand.Dispose(); if (manga.Categories != null && flag) { foreach (string category in manga.Categories) { //Debug.WriteLine("category: " + category); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; insertCommand.CommandText = "INSERT OR IGNORE INTO " + App.APP_MANGA_CATEGORY_TABLE + " (manga_id, category) VALUES (@ID, @CATEGORY);"; insertCommand.Parameters.AddWithValue("@ID", manga.Id); insertCommand.Parameters.AddWithValue("@CATEGORY", category); //insertCommand.CommandText = "INSERT OR INGNORE INTO " + App.APP_MANGA_CATEGORY_TABLE + " (manga_id, category) VALUES (" + manga.Id + ", " + category + ");"; try { await insertCommand.ExecuteReaderAsync(); } catch (SqliteException e) { //Debug.WriteLine("Manga: " + manga.Id + " - " + manga.Title); Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } insertCommand.Dispose(); } } db.Close(); } } }