Beispiel #1
0
        public void Should_save_new_page()
        {
            var newPage = PageFactory.Page(_siteId, Guid.NewGuid(), "Name 3");

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                repository.Create(newPage);
            }

            using (var context = new WeapsyDbContext(_contextOptions))
            {
                var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper());
                var page       = repository.GetById(_siteId, newPage.Id);

                Assert.NotNull(page);
            }
        }
Beispiel #2
0
 static void CreateMangaDb(MangaScrapModel manga, string mediaPath)
 {
     if (manga != null)
     {
         Console.WriteLine("Start downloading and saving manga ");
         var   mangaGuid = Guid.NewGuid();
         Manga mangaDoc  = new Manga();
         mangaDoc.Id               = mangaGuid;
         mangaDoc.Name             = manga.Title;
         mangaDoc.Resume           = manga.Resume;
         mangaDoc.State            = manga.State;
         mangaDoc.Date             = manga.DateEdition;
         mangaDoc.CoverExteranlUrl = manga.CoverUrl;
         mangaDoc.CoverInternalUrl = ImageHelper.GetPagelocalPath(manga.CoverUrl, mediaPath, "Manga/" + mangaDoc.Name.Replace(" ", "_"), "cover." + manga.CoverUrl.Split(".").Last());
         mangaDoc.Tags             = string.Join(",", manga.Tags.ToArray());
         mangaRepository.Create(mangaDoc);
         Console.WriteLine("manga details downloaded and saved succefully ");
         foreach (var tag in manga.Tags)
         {
             if (tagRepository.Query(t => t.Label == tag.Trim()).Count == 0)
             {
                 var tagGuid = Guid.NewGuid();
                 tagRepository.Create(new Tag()
                 {
                     Id = tagGuid, Label = tag.Trim()
                 });
             }
         }
         foreach (var chapter in manga.Chapters)
         {
             var message     = string.Format("Chapter {0} downloaded and saved succefully", chapter.Number);
             var chapterGuid = Guid.NewGuid();
             var chapterDoc  = new Chapter()
             {
                 Id      = chapterGuid,
                 Title   = chapter.Title,
                 Url     = chapter.Url,
                 Number  = chapter.Number,
                 MangaId = mangaGuid,
             };
             chapterRepository.Create(chapterDoc);
             var process = Process.Start(config["BrowserPath"], chapter.Url);
             foreach (var page in chapter.Pages)
             {
                 string internalUrl = ImageHelper.GetPagelocalPath(page.Url, mediaPath, "Manga/" + mangaDoc.Name.Replace(" ", "_") + "/chapter" + chapter.Number, page.Number.ToString() + "." + page.Url.Split(".").Last());
                 for (int i = 0; i < 50; i++)
                 {
                     if (string.IsNullOrEmpty(internalUrl))
                     {
                         internalUrl = ImageHelper.GetPagelocalPath(page.Url, mediaPath, "Manga/" + mangaDoc.Name.Replace(" ", "_") + "/chapter" + chapter.Number, page.Number.ToString() + "." + page.Url.Split(".").Last());
                     }
                     else
                     {
                         i = 51;
                     }
                 }
                 var pageGuid = Guid.NewGuid();
                 var pageDoc  = new Page()
                 {
                     Id          = pageGuid,
                     Number      = page.Number,
                     ExternalUrl = page.Url,
                     InternalUrl = "Manga/" + mangaDoc.Name.Replace(" ", "_") + "/chapter" + chapter.Number + "/" + page.Number.ToString() + "." + page.Url.Split(".").Last(),
                     Pending     = string.IsNullOrEmpty(internalUrl),
                     ChapterId   = chapterGuid
                 };
                 pageRepository.Create(pageDoc);
             }
             process.CloseMainWindow();
             process.Close();
             if (chapter != manga.Chapters.First())
             {
                 for (int j = 0; j < message.Length; j++)
                 {
                     Console.Write("\b \b");
                 }
             }
             Console.Write(message);
         }
         Console.WriteLine("\nEnd downloading and saving manga ");
     }
 }