Beispiel #1
0
        /// <summary>
        /// Given the prefix of a page, asynchronously search for a list of titles for auto completion.
        /// </summary>
        /// <remarks>Do not modify the returned list.</remarks>
        public async Task <IList <OpenSearchResultEntry> > GetAutoCompletionItemsAsync(string expression,
                                                                                       int defaultNamespace = BuiltInNamespaces.Main)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            string normalizedExpression;

            try
            {
                normalizedExpression = WikiLink.NormalizeWikiLink(await GetSiteAsync(), expression);
            }
            catch (ArgumentException)
            {
                normalizedExpression = expression;
            }
            var tp     = Tuple.Create(normalizedExpression, defaultNamespace);
            var cached = _AutoCompletionItemsCache.TryGetValue(tp);

            if (cached != null && DateTime.Now - cached.Item2 < _CacheExpiry)
            {
                return(cached.Item1);
            }
            var site = await GetSiteAsync();

            var entries = await site.OpenSearchAsync(expression, 20, defaultNamespace, OpenSearchOptions.None);

            _AutoCompletionItemsCache[tp] = Tuple.Create(entries, DateTime.Now);
            return(entries);
        }
 public BoardHeader(WikiSite site, string boardTitle)
 {
     if (site == null)
     {
         throw new ArgumentNullException(nameof(site));
     }
     Site       = site;
     BoardTitle = WikiLink.NormalizeWikiLink(site, boardTitle);
 }
Beispiel #3
0
        public async Task <PageEditorViewModel> OpenPageEditorAsync(WikiSiteViewModel wikiSite, string pageTitle)
        {
            var site = await wikiSite.GetSiteAsync();

            var normalizedTitle = WikiLink.NormalizeWikiLink(site, pageTitle);
            var editor          = _ChildViewModelService.Documents
                                  .OfType <PageEditorViewModel>()
                                  .Where(vm => vm.SiteContext == wikiSite)
                                  .FirstOrDefault(vm => vm.WikiPage.Title == normalizedTitle);

            if (editor == null)
            {
                editor = CreatePageEditor(wikiSite);
                editor.SetWikiPageAsync(pageTitle).Forget();
                _ChildViewModelService.Documents.Add(editor);
            }
            editor.IsActive = true;
            return(editor);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes the generator from the site and category title.
 /// </summary>
 /// <param name="site">Site instance.</param>
 /// <param name="categoryTitle">Title of the category, with or without Category: prefix.</param>
 public CategoryMembersGenerator(WikiSite site, string categoryTitle) : base(site)
 {
     CategoryTitle = WikiLink.NormalizeWikiLink(site, categoryTitle, BuiltInNamespaces.Category);
 }
Beispiel #5
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());
        }