コード例 #1
0
ファイル: JsonHelper.cs プロジェクト: molant/MangApp
 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);
     }
 }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: WebData.cs プロジェクト: molant/MangApp
        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)
            {
            }
        }
コード例 #4
0
ファイル: JsonHelper.cs プロジェクト: molant/MangApp
        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;
        }
コード例 #5
0
ファイル: MockService.cs プロジェクト: molant/MangApp
 public IEnumerable<RemoteImage> GetBackgroundImages(Manga manga)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
ファイル: WebData.cs プロジェクト: molant/MangApp
        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>();
            }
        }
コード例 #7
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public string UpdateBackgroundImage(Manga manga)
 {
     throw new System.NotImplementedException();
 }
コード例 #8
0
ファイル: LocalDataGenerator.cs プロジェクト: molant/MangApp
        // 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)
            {
            }
        }
コード例 #9
0
ファイル: LocalData.cs プロジェクト: molant/MangApp
        /// <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;
        }
コード例 #10
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 Task<string> ILocalData.GetBackgroundImage(Manga manga)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public Task<string> GetSummaryImage(Manga manga)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public string GetBackgroundImage(Manga manga)
 {
     return null;
 }
コード例 #13
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public void AddFavoriteManga(Manga manga)
 {
 }
コード例 #14
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public void UpdateManga(Manga manga)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public void UpdateFavoriteManga(Manga manga, int lastChapterRead)
 {
 }
コード例 #16
0
ファイル: MockService.cs プロジェクト: molant/MangApp
 public void GetMangaChapters(Manga manga)
 {
     manga = this.manga;
 }
コード例 #17
0
ファイル: MockService.cs プロジェクト: molant/MangApp
 public IEnumerable<Manga> GetRelatedMangas(Manga manga)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: LocalData.cs プロジェクト: molant/MangApp
        /// <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;
        }
コード例 #19
0
ファイル: LocalData.cs プロジェクト: molant/MangApp
 /// <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);
     }
 }
コード例 #20
0
ファイル: MockDatabase.cs プロジェクト: molant/MangApp
 public void RemoveFavoriteManga(Manga manga)
 {
 }