private async Task SyncChapter(WdcInteractiveStory story, WdcInteractiveChapter chapter)
        {
            var ct = _ctSource.Token;

            ct.ThrowIfCancellationRequested();

            _log.Debug($"Syncing story '{story.ID}' chapter '{chapter.Path}'");

            // Update the story status
            // TODO

            // If the last synced value is minimum (always update) or chapter refreshing is enabled and this chapter needs a refresh
            if (
                chapter.LastSynced == DateTime.MinValue ||
                (GetSettings().UpdateKnownChapters&& chapter.LastSynced <= DateTime.Now + new TimeSpan(0, 0, GetSettings().SyncChapterIntervalSeconds, 0))
                )
            {
                var remoteChapter = await _wdcReader.GetInteractiveChaper(story.ID, chapter.Path, _wdcClient, ct);

                ct.ThrowIfCancellationRequested();

                // Bring over changes
                chapter.Author            = remoteChapter.Author;
                chapter.Choices           = remoteChapter.Choices;
                chapter.Content           = remoteChapter.Content;
                chapter.IsEnd             = remoteChapter.IsEnd;
                chapter.SourceChoiceTitle = remoteChapter.SourceChoiceTitle;
                chapter.Title             = remoteChapter.Title;

                chapter.LastSynced = DateTime.Now;
            }
        }
Exemplo n.º 2
0
        public async Task WdcReaderInteractiveChapterLoggedIn()
        {
            // Expected results
            var expectedChapter = new WdcInteractiveChapter();

            expectedChapter.Path              = "1211222";
            expectedChapter.Title             = "Caught and let go";
            expectedChapter.SourceChoiceTitle = string.Empty;
            expectedChapter.Content           = TestUtil.GetDataFile("expected_set_13_06_2019.WdcReaderInteractiveChapter1_Content.txt");
            expectedChapter.IsEnd             = false;
            expectedChapter.Author            = new WdcAuthor()
            {
                Name     = "The Nameless Hermit",
                Username = "******",
            };
            expectedChapter.Choices.Add(new WdcInteractiveChapterChoice()
            {
                PathLink = "11", Name = "Be Jace"
            });
            expectedChapter.Choices.Add(new WdcInteractiveChapterChoice()
            {
                PathLink = "12", Name = "Be Rhea"
            });
            expectedChapter.Choices.Add(new WdcInteractiveChapterChoice()
            {
                PathLink = "13", Name = "Be Marek"
            });
            expectedChapter.Choices.Add(new WdcInteractiveChapterChoice()
            {
                PathLink = "14", Name = "Be Tara"
            });

            WdcResponse payload = new WdcResponse();

            payload.WebResponse = TestUtil.GetDataFile("sample_set_13_06_2019.Looking for adventure - chapter 1211222 - logged in.html");
            payload.Address     = "https://www.writing.com/main/interact/item_id/209084-Looking-for-adventure/map/1211222";

            WdcInteractiveChapter testChapter = _reader.GetInteractiveChaper("TEST", expectedChapter.Path, payload);

            CompareInteractiveChapters(expectedChapter, testChapter);
        }