Beispiel #1
0
        public async Task ParseAsync()
        {
            if (_workInProgress)
            {
                return;
            }

            bool haveStrips = await _stripManager.CheckIfDataExistsAsync();

            if (!haveStrips)
            {
                _workInProgress = true;
                ChaptersDomain chapters = await _stripManager.ParseChaptersAsync();

                _workInProgress = !await _stripManager.ParseStripsAsync(chapters);
            }

            if (_workInProgress)
            {
                return;
            }

            bool haveRants = await _rantManager.CheckIfDataExistsAsync();

            if (!haveRants)
            {
                _workInProgress = true;
                _workInProgress = !await _rantManager.ParseRantsAsync();
            }

            await _feedManager.LoadAsync();

            if (_feedManager.Strips.Count > 0)
            {
                ChaptersDomain chapters = await _stripManager.ParseChaptersAsync();

                await _stripManager.ParseStripsAsync(chapters);
            }
            foreach (StripDomain strip in _feedManager.Strips)
            {
                await SendLocalisedStripNotificationsAsync(strip);
            }

            if (_feedManager.Rants.Count > 0)
            {
                await _rantManager.ParseRantsAsync(_feedManager.LastRantNumber);
            }
            foreach (RantDomain rant in _feedManager.Rants)
            {
                await SendLocalisedRantNotifications(rant);
            }
        }
Beispiel #2
0
        public async Task <ChaptersDomain> ParseChaptersAsync()
        {
            ChaptersDomain chapters = ChaptersParser.Parse(Url);
            IEnumerable <ChapterDomain> chaptersInDatabase = await _mediator.Send(new GetAllChaptersQuery());

            foreach (ChapterDomain chapter in chapters)
            {
                if (!chaptersInDatabase.Where(c => c.Number == chapter.Number).Any())
                {
                    ChapterDomain newChapter = new(chapter.Number, chapter.Title, chapter.Category);
                    await _mediator.Send(new CreateChapterCommand(newChapter));
                }
            }
            await _mediator.Send(new SaveChapterCommand());

            return(chapters);
        }
Beispiel #3
0
        public async Task <bool> ParseStripsAsync(ChaptersDomain chapters)
        {
            IEnumerable <StripDomain> stripsInDatabase = await _mediator.Send(new GetAllStripsQuery());

            List <StripDomain> strips = await StripsParser.ParseAsync(Url, chapters, stripsInDatabase);

            foreach (StripDomain strip in strips)
            {
                if (!stripsInDatabase.Where(s => s.Number == strip.Number).Any())
                {
                    ChapterDomain currentChapter = await _mediator.Send(new GetChapterQuery(strip.Category));

                    StripDomain newStrip = new(currentChapter.Category, strip.Number, strip.Title, strip.Url, strip.PublishDate);
                    await _mediator.Send(new CreateStripCommand(newStrip));
                }
            }
            await _mediator.Send(new SaveStripCommand());

            return(true);
        }
Beispiel #4
0
        public static async Task <List <StripDomain> > ParseAsync(Uri url, ChaptersDomain chapters, IEnumerable <StripDomain> stripsInDatabase)
        {
            List <StripDomain> strips  = new();
            HtmlWeb            web     = new();
            HtmlDocument       htmlDoc = web.Load(url);

            foreach (ChapterDomain chapter in chapters)
            {
                IEnumerable <HtmlNode> nodes = htmlDoc.DocumentNode.SelectNodes("//li/a").Where(w => w.ParentNode.ParentNode.ParentNode.ParentNode.SelectSingleNode(".//a").Id == chapter.Category);
                foreach (HtmlNode node in nodes)
                {
                    StripDomain strip = await ExtractStripAsync(node, chapter, stripsInDatabase);

                    if (strip != null)
                    {
                        strips.Add(strip);
                    }
                }
            }
            return(strips);
        }