Ejemplo n.º 1
0
        public DownloadedChapterInfo GetDownloadInfo(IChapterRecord chapterRecord, bool prefetch)
        {
            if (chapterRecord == null)
            {
                throw new ArgumentNullException("chapterRecord");
            }

            if (String.IsNullOrEmpty(chapterRecord.ChapterId))
            {
                throw new ArgumentException("Invalid chapter record, chapter id must not be null or empty.", "chapterRecord");
            }

            if (!prefetch)
            {
                return(GetDownloadInfo(chapterRecord));
            }

            // this not very nice way is used to workaround this issue: http://system.data.sqlite.org/index.html/tktview/393d954be0

            if (chapterRecord.MangaRecord == null)
            {
                throw new ArgumentException("MangaRecord must not be null", "chapterRecord");
            }

            var mangaKey = new Tuple <Guid, string>(chapterRecord.MangaRecord.Scraper, chapterRecord.MangaRecord.MangaId);
            var chapters = DownloadInfoRecordsCache[mangaKey];

            if (chapters == null)
            {
                chapters = _storage.GetChaptersInfo(chapterRecord.MangaRecord).ToDictionary(dci => dci.ChapterRecord.ChapterId);

                DownloadInfoRecordsCache[mangaKey] = chapters;
            }

            DownloadedChapterInfo downloadInfo;

            chapters.TryGetValue(chapterRecord.ChapterId, out downloadInfo);

            return(downloadInfo);
        }