Beispiel #1
0
 public PageInfoTeste(EntityConexao entityConexao)
 {
     dbContext           = entityConexao.DataBaseConfiguration();
     userEntityFramework = new PageInfoRepositorio(dbContext);
     this.builder        = new PageInfoBuilder();
     transaction         = dbContext.Database.BeginTransaction();
 }
Beispiel #2
0
        /// <summary>
        /// Given the summary of a page asynchronously.
        /// </summary>
        /// <exception cref="ArgumentNullException">title is null.</exception>
        /// <exception cref="ArgumentException">title is invalid.</exception>
        /// <remarks>Do not modify the returned objects.</remarks>
        public async Task <IList <PageInfo> > GetPageSummaryAsync(IEnumerable <string> titles)
        {
            if (titles == null)
            {
                throw new ArgumentNullException(nameof(titles));
            }
            var site = await GetSiteAsync();

            var titleList            = titles.Select(t => WikiLink.NormalizeWikiLink(site, t)).ToArray();
            var pagesToCheck         = new List <Page>();
            var pagesToFetch         = new List <Page>();
            var pagesToCheckRedirect = new List <Tuple <Page, PageInfo> >();
            var parser = new Lazy <WikitextParser>();

            // First, check whether we need to contact the server for each of the page title.
            foreach (var title in titleList)
            {
                var cached = _PageSummaryCache.TryGetValue(title);
                if (cached != null && DateTime.Now - cached.Item2 < _CacheExpiry)
                {
                    continue;
                }
                pagesToCheck.Add(new Page(site, title));
            }
            await pagesToCheck.RefreshAsync();

            foreach (var page in pagesToCheck)
            {
                var cached = _PageSummaryCache.TryGetValue(page.Title);
                // Check if the cache is obsolete.
                if (cached != null && page.LastRevisionId == cached.Item1.LastRevisionId)
                {
                    _PageSummaryCache[page.Title] = Tuple.Create(cached.Item1, DateTime.Now);
                    continue;
                }
                // We need to fetch the whole page.
                pagesToFetch.Add(page);
            }
            // Fetch information & content.
            await pagesToFetch.RefreshAsync(PageQueryOptions.FetchContent);

            foreach (var page in pagesToFetch)
            {
                var info = PageInfoBuilder.BuildBasicInfo(page, parser.Value);
                _PageSummaryCache[page.Title] = Tuple.Create(info, DateTime.Now);
                if (page.IsRedirect)
                {
                    pagesToCheckRedirect.Add(Tuple.Create(page, info));
                }
            }
            // Fetch redirects.
            await pagesToCheckRedirect.Select(t => t.Item1).RefreshAsync(PageQueryOptions.ResolveRedirects);

            foreach (var tp in pagesToCheckRedirect)
            {
                var path = tp.Item1.RedirectPath.ToList();
                // Add & complete redirect path
                path.Add(tp.Item1.Title);
                tp.Item2.RedirectPath = path;
            }
            return(titleList.Select(t => _PageSummaryCache[t].Item1).ToArray());
        }