예제 #1
0
        /// <summary>
        /// Enumerate revisions from the page.
        /// </summary>
        /// <remarks>Redirect resolution is disabled in this operation.</remarks>
        public static IAsyncEnumerable <Revision> EnumRevisionsAsync(RevisionGenerator generator, PageQueryOptions options)
        {
            Debug.Assert(generator != null);
            Debug.Assert(generator.Page != null);
            Debug.Assert((options & PageQueryOptions.ResolveRedirects) != PageQueryOptions.ResolveRedirects);
            var site = generator.Site;
            var pa   = GetPageFetchingParams(options);

            foreach (var p in generator.GetGeneratorParams())
            {
                pa[p.Key] = p.Value;
            }
            var serializer = Utility.CreateWikiJsonSerializer();

            serializer.Converters.Add(new DelegateCreationConverter <Revision>(t => new Revision(generator.Page)));
            var resultCounter = 0;

            return(new PagedQueryAsyncEnumerable(site, pa)
                   .SelectMany(jresult =>
            {
                var jpage = jresult["pages"].Values().First();
                var revisions = (JArray)jpage?["revisions"];
                if (revisions != null)
                {
                    resultCounter += revisions.Count;
                    site.Logger?.Trace(site, $"Loaded {resultCounter} revisions of {generator.Page}.");
                    var result = revisions.ToObject <IList <Revision> >(serializer);
                    return result.ToAsyncEnumerable();
                }
                return AsyncEnumerable.Empty <Revision>();
            }));
        }
예제 #2
0
        /// <summary>
        /// Enumerates revisions of the page, descending in tim.
        /// </summary>
        /// <param name="pagingSize">Maximum items returned per request. <c>null</c> for maximum allowed count.</param>
        /// <param name="options">Options for revision listing. Note <see cref="PageQueryOptions.ResolveRedirects"/> will raise exception.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="pagingSize"/> is non-positive.</exception>
        /// <remarks>To gain full control of revision enumeration, you can use <see cref="RevisionGenerator" />.</remarks>
        public IAsyncEnumerable <Revision> EnumRevisionsAsync(int?pagingSize, PageQueryOptions options)
        {
            if (pagingSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pagingSize));
            }
            var gen = new RevisionGenerator(this)
            {
                PagingSize = pagingSize
            };

            return(gen.EnumRevisionsAsync(options));
        }
        public async Task WpTestEnumRevisionsTest3()
        {
            var site = await WpTest2SiteAsync;
            // 5,100 revisions in total
            var page = new WikiPage(site, "Page:Edit_page_for_chrome");
            var t1   = new DateTime(2014, 10, 20, 10, 0, 0, DateTimeKind.Utc);
            var t2   = new DateTime(2014, 10, 22, 10, 0, 0, DateTimeKind.Utc);
            var gen  = new RevisionGenerator(page)
            {
                TimeAscending = true,
                StartTime     = t1,
                EndTime       = t2,
            };
            var revisions = await gen.EnumRevisionsAsync().ToList();

            Assert.True(revisions.SequenceEqual(revisions.OrderBy(r => r.TimeStamp)));
            Assert.True(revisions.First().TimeStamp >= t1);
            Assert.True(revisions.Last().TimeStamp <= t2);
            // This holds on 2016-12-09
            Assert.Equal(32, revisions.Count);
            ShallowTrace(revisions);
        }