Exemple #1
0
 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;
        }
Exemple #3
0
        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)
            {
            }
        }
Exemple #4
0
        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;
        }
Exemple #5
0
 public IEnumerable<RemoteImage> GetBackgroundImages(Manga manga)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
        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>();
            }
        }
Exemple #7
0
 public string UpdateBackgroundImage(Manga manga)
 {
     throw new System.NotImplementedException();
 }
Exemple #8
0
        // 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)
            {
            }
        }
Exemple #9
0
        /// <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;
        }
Exemple #10
0
 Task<string> ILocalData.GetBackgroundImage(Manga manga)
 {
     throw new NotImplementedException();
 }
Exemple #11
0
 public Task<string> GetSummaryImage(Manga manga)
 {
     throw new NotImplementedException();
 }
Exemple #12
0
 public string GetBackgroundImage(Manga manga)
 {
     return null;
 }
Exemple #13
0
 public void AddFavoriteManga(Manga manga)
 {
 }
Exemple #14
0
 public void UpdateManga(Manga manga)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
 public void UpdateFavoriteManga(Manga manga, int lastChapterRead)
 {
 }
Exemple #16
0
 public void GetMangaChapters(Manga manga)
 {
     manga = this.manga;
 }
Exemple #17
0
 public IEnumerable<Manga> GetRelatedMangas(Manga manga)
 {
     throw new NotImplementedException();
 }
Exemple #18
0
        /// <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;
        }
Exemple #19
0
 /// <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);
     }
 }
Exemple #20
0
 public void RemoveFavoriteManga(Manga manga)
 {
 }