/// <summary>
        /// Returns the results of the query as a lazy collection.
        /// </summary>
        internal IEnumerable <TResult> ExecuteList <TResult>(
            PageQueryParameters parameters, Func <PageData, TResult> selector,
            Dictionary <string, QueryTypeProperties> pageProperties)
        {
            HttpQueryParameter primaryQueryContinue = null;

            var revisions = parameters.PropQueryParametersCollection.SingleOrDefault(p => p.PropName == "revisions");

            int limit           = (revisions == null || revisions.OnlyFirst) ? -1 : 1;
            var pagesCollection = parameters.PagesCollection;

            do
            {
                var currentParameters   = pagesCollection.GetNextPage(limit).ToArray();
                var processedParameters = ProcessParameters(
                    parameters.PropQueryParametersCollection, currentParameters, pageProperties);
                var generatorParameter = (HttpQueryParameter)currentParameters.SingleOrDefault(p => p.Name == "generator");
                var generator          = generatorParameter == null ? null : generatorParameter.Value;

                var downloaded = QueryProcessor.Download(m_wiki, processedParameters, primaryQueryContinue);

                var queryContinues = QueryProcessor.GetQueryContinues(downloaded);

                HttpQueryParameter newPrimaryQueryContinue = null;

                if (generator != null)
                {
                    queryContinues.TryGetValue(generator, out newPrimaryQueryContinue);

                    queryContinues.Remove(generator);
                }

                var pagingManager = new PagingManager(
                    m_wiki, generator, parameters.PropQueryParametersCollection, currentParameters, pageProperties,
                    primaryQueryContinue, queryContinues);

                var queryElement = downloaded.Element("query");

                if (queryElement != null)
                {
                    var partPageData = queryElement.Element("pages").Elements("page")
                                       .Select(e => new PageData(m_wiki, e, pageProperties, pagingManager)).ToArray();

                    pagingManager.SetPages(partPageData);

                    var part = partPageData.Select(selector);

                    foreach (var item in part)
                    {
                        yield return(item);
                    }
                }

                primaryQueryContinue = newPrimaryQueryContinue;
            } while (pagesCollection.HasMorePages(primaryQueryContinue));
        }
Esempio n. 2
0
        public PageData(
            WikiInfo wiki, XElement element, Dictionary <string, QueryTypeProperties> pageProperties,
            PagingManager pagingManager)
        {
            m_wiki           = wiki;
            m_pageProperties = pageProperties;
            m_pagingManager  = pagingManager;

            GetOrCreateDataList("info").Add(m_pageProperties["info"].Parser(element, wiki));

            var pageIdAttribute = element.Attribute("pageid");

            if (pageIdAttribute != null)
            {
                PageId = ValueParser.ParseInt64(pageIdAttribute.Value);

                AddData(element);
            }
        }