internal static void ParseMangaChapters(Manga manga, JToken token) { JToken chapters = token["chapters"]; if (chapters != null) { manga.Chapters = chapters.Children().Select(c => ParseChapter(manga.Key, c)).OrderBy(c => c.Number); } }
public MangaSummaryViewModel(Manga manga) { // HACK: LocalData should be a singleton or something global this.localData = new LocalData(); Title = manga.Title; Description = manga.Description; AlternativeNames = manga.AlternativeNames; Popularity = manga.Popularity; Authors = manga.Authors; Categories = manga.Categories; Artists = manga.Artists; YearOfRelease = manga.YearOfRelease; Status = manga.Status; ReadingDirection = manga.ReadingDirection; SummaryImagePath = new Uri(Path.Combine(ApplicationData.Current.LocalFolder.Path, this.localData.GetSummaryImage(manga).Result)); LastChapter = manga.LastChapterUploaded; LastChapterDate = manga.LastChapterUploadedDate; }
public void GetMangaChapters(Manga manga) { try { // Check if we already have the chapter in memory if (manga.Chapters != null && manga.Chapters.Count() > 0) { return; } HttpClient client = new HttpClient(); var response = client.GetStringAsync(string.Format(Urls.GetMangaDetail, manga.Key)).Result; // Transform JSON into manga JsonHelper.ParseMangaChapters(manga, JObject.Parse(response)); } catch (Exception) { } }
internal static Manga ParseManga(JToken token) { Manga manga = new Manga(); manga.Key = token["_id"].Value<string>(); manga.Title = token["title"].Value<string>(); manga.Description = token["description"].Value<string>(); manga.AlternativeNamesDb = string.Join("#", token["alias"].Children().Values<string>()); int? popularity = JsonHelper.ParseInt(token["hits"]); manga.Popularity = (popularity.HasValue) ? popularity.Value : 0; manga.ProvidersDb = string.Join("#", token["providers"].Children().Values<string>()); manga.AuthorsDb = string.Join("#", token["authors"].Children().Values<string>()); manga.ArtistsDb = string.Join("#", token["artists"].Children().Values<string>()); manga.CategoriesDb = string.Join("#", token["categories"].Children().Values<string>()); manga.YearOfRelease = JsonHelper.ParseInt(token["released"]); manga.StatusDb = JsonHelper.ParseInt(token["status"]); manga.ReadingDirectionDb = JsonHelper.ParseInt(token["direction"]); manga.RemoteSummaryImagePath = token["image"].Value<string>(); manga.LastChapterUploaded = JsonHelper.ParseInt(token["chapters_len"]); manga.LastChapterUploadedDate = ParseDateTime(JsonHelper.ParseInt(token["last_chapter_date"])); manga.CurrentChapterReading = 1; manga.CurrentPageReading = 1; JToken chapters = token["chapters"]; if (chapters != null) { manga.Chapters = chapters.Children().Select(c => ParseChapter(manga.Key, c)).OrderBy(c => c.Number); } return manga; }
public IEnumerable<RemoteImage> GetBackgroundImages(Manga manga) { throw new NotImplementedException(); }
internal async Task<IEnumerable<RemoteImage>> GetSummaryImages(Manga manga) { try { HttpClient client = new HttpClient(); //var response = await client.GetStringAsync(Urls.GetMangaList).ConfigureAwait(false); // Transform JSON into objects //JObject json = JObject.Parse(response); // TODO: how are we going to send binary data? return Enumerable.Empty<RemoteImage>(); } catch (HttpRequestException) { return Enumerable.Empty<RemoteImage>(); } }
public string UpdateBackgroundImage(Manga manga) { throw new System.NotImplementedException(); }
// Working private static void CreateSummaryImageFromRemoteUrl(Manga manga) { try { HttpClient client = new HttpClient(); byte[] imageData = client.GetByteArrayAsync(manga.RemoteSummaryImagePath).Result; if (imageData != null && imageData.Length > 0) { string fileName = manga.Title + Path.GetExtension(manga.RemoteSummaryImagePath); var folder = FileSystemUtilities.GetFolder(ApplicationData.Current.LocalFolder, Constants.SummaryImagesFolderPath); var file = folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).AsTask().Result; using (var stream = file.OpenStreamForWriteAsync().Result) { stream.Write(imageData, 0, imageData.Length); } } } catch (Exception) { } }
/// <summary> /// Gets the path to a background image of a given manga. /// </summary> /// <param name="manga">The manga of which we want to obtain a background image.</param> /// <returns>The path of an image.</returns> public async Task<string> GetBackgroundImage(Manga manga) { string imagePath = string.Empty; var folder = FileSystemUtilities.GetFolder(ApplicationData.Current.LocalFolder, Constants.BackgroundImagesFolderPath); if (folder != null) { imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Title); if (string.IsNullOrEmpty(imagePath)) { imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Key); } } // We do not have the image locally, so we have to go to the server to get it if (string.IsNullOrEmpty(imagePath)) { await UpdateImageFolderFromServer(folder, manga.Title, () => this.webData.GetBackgroundImages(manga)); imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Title); } return imagePath; }
Task<string> ILocalData.GetBackgroundImage(Manga manga) { throw new NotImplementedException(); }
public Task<string> GetSummaryImage(Manga manga) { throw new NotImplementedException(); }
public string GetBackgroundImage(Manga manga) { return null; }
public void AddFavoriteManga(Manga manga) { }
public void UpdateManga(Manga manga) { throw new NotImplementedException(); }
public void UpdateFavoriteManga(Manga manga, int lastChapterRead) { }
public void GetMangaChapters(Manga manga) { manga = this.manga; }
public IEnumerable<Manga> GetRelatedMangas(Manga manga) { throw new NotImplementedException(); }
/// <summary> /// Gets the path to a summary image of a given manga. /// </summary> /// <param name="manga">The manga of which we want to obtain a background image.</param> /// <returns>The path of an image.</returns> public async Task<string> GetSummaryImage(Manga manga) { string imagePath = string.Empty; var folder = FileSystemUtilities.GetFolder(ApplicationData.Current.LocalFolder, Constants.SummaryImagesFolderPath); if (folder != null) { imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Title); if (string.IsNullOrEmpty(imagePath)) { imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Key); } } // We do not have the image locally, so we have to go to the server to get it if (string.IsNullOrEmpty(imagePath)) { await UpdateImageFolderFromServer(folder, manga.Title, () => this.webData.GetSummaryImages(manga)); imagePath = FileSystemUtilities.GetRandomPath(folder, manga.Title); } // The server didn't have any image, let's get a default image instead if (string.IsNullOrEmpty(imagePath)) { imagePath = FileSystemUtilities.GetRandomPath(folder, "default"); } // We do not have any default image locally, so we have to go to the server to get it if (string.IsNullOrEmpty(imagePath)) { await UpdateImageFolderFromServer(folder, Constants.DefaultImageName, () => this.webData.GetDefaultSummaryImages()); imagePath = FileSystemUtilities.GetRandomPath(folder, Constants.DefaultImageName); } return imagePath; }
/// <summary> /// Updates a manga information in the database. /// </summary> /// <param name="manga">The manga to update.</param> public void UpdateManga(Manga manga) { using (SQLiteConnection db = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, Constants.DbName))) { db.Update(manga); } }
public void RemoveFavoriteManga(Manga manga) { }