Exemple #1
0
        public async Task <WithPageChapter> FetchChapterAsync(IResourceFetchContext context)
        {
            var type = eng.GetComicSourceProviderType(context.Url);

            if (type is null)
            {
                return(null);
            }
            using (var scope = serviceScopeFactory.CreateScope())
            {
                var ser    = (IComicSourceProvider)scope.ServiceProvider.GetRequiredService(type.ProviderType);
                var entity = await ser.GetPagesAsync(context.Url);

                var now = DateTime.Now.Ticks;
                var ctx = context.Copy(context.EntityUrl);
                var ent = await context.Root.FetchEntityAsync(ctx);

                var chp = ent?.Chapters.FirstOrDefault(x => x.TargetUrl == context.Url);
                if (chp is null)
                {
                    return(null);
                }
                return(new WithPageChapter
                {
                    Pages = entity,
                    CreateTime = now,
                    UpdateTime = now,
                    TargetUrl = context.Url,
                    Title = chp.Title
                });
            }
        }
Exemple #2
0
        public void GetNothingMatch_MustReturnNull()
        {
            var eng = new ComicEngine();
            var val = eng.GetComicSourceProviderType("http://www.baidu.com");

            Assert.IsNull(val);
            eng.Add(new DataCondition {
                Descript = new EngineDescript(), EngineName = "test", Order = 1, ProviderType = typeof(void), ConditionFunc = _ => false
            });
            val = eng.GetComicSourceProviderType(new Uri("http://www.baidu.com"));
            Assert.IsNull(val);
        }
Exemple #3
0
        protected override async Task <string> OnFindInDbAsync(ComicImageIdentity identity)
        {
            using var scope = scopeFactory.CreateScope();
            var prov = comicEngine.GetComicSourceProviderType(identity.EntityUrl);

            if (prov is null)
            {
                return(string.Empty);
            }
            var provider = (IComicSourceProvider)scope.ServiceProvider.GetRequiredService(prov.ProviderType);
            var storeSer = scope.ServiceProvider.GetRequiredService <IStoreService>();
            var imgRes   = await storeSer.GetPathAsync(identity.Url);

            var exists = await storeSer.ExistsAsync(identity.Url);

            if (!exists)
            {
                try
                {
                    using (var img = await provider.GetImageStreamAsync(identity.Url))
                    {
                        await storeSer.SaveAsync(identity.Url, img);
                    }
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <ComicImageFinder>();
                    logger.LogError(ex, identity.Url);
                }
            }
            return(imgRes);
        }
Exemple #4
0
        public void GivenNotUri_MustReturnThrowException()
        {
            var eng = new ComicEngine();

            Assert.ThrowsException <UriFormatException>(() => eng.GetComicSourceProviderType("--not-uri--"));
        }
Exemple #5
0
        protected override WithImageStorableComicSourceInfo <TResource, TImage> CreateSourceInfo(ComicSnapshot snapshot, ComicSource source, ComicEngine engine)
        {
            var store = AppEngine.GetRequiredService <WithImageComicStoreService <TResource, TImage> >();
            var box   = store.GetStoreBox(source.TargetUrl);

            return(new WithImageStorableComicSourceInfo <TResource, TImage>(snapshot, source, engine.GetComicSourceProviderType(source.TargetUrl), box));
        }
Exemple #6
0
 protected override ComicSourceInfo CreateSourceInfo(ComicSnapshot snapshot, ComicSource source, ComicEngine engine)
 {
     return(new ComicSourceInfo(snapshot, source, engine.GetComicSourceProviderType(source.TargetUrl)));
 }