Esempio n. 1
0
        /// <summary>
        /// Main function that retrieves the list from API, including paging
        /// </summary>
        /// <param name="url">URL of API request</param>
        /// <param name="haveSoFar">Number of pages already retrieved, for upper limit control</param>
        /// <returns>List of pages</returns>
        public List <Article> ApiMakeList(string url, int haveSoFar)
        {// TODO: error handling
            List <Article> list    = new List <Article>();
            string         postfix = "";

            string newUrl = url;

            if (Hack1_12)
            {
                newUrl = RemoveCmcategory.Replace(newUrl, "");
            }

            while (list.Count + haveSoFar < Limit)
            {
                string text = Tools.GetHTML(newUrl + postfix);
                if (text.Contains("code=\"cmtitleandcategory\""))
                {
                    if (Hack1_12)
                    {
                        throw new ListProviderException("cmtitleandcategory persists.");
                    }

                    Hack1_12 = true;
                    newUrl   = RemoveCmcategory.Replace(url, "");
                    text     = Tools.GetHTML(newUrl + postfix);
                }

                XmlTextReader xml = new XmlTextReader(new StringReader(text));
                xml.MoveToContent();
                postfix = "";

                while (xml.Read())
                {
                    if (xml.Name == "query-continue")
                    {
                        XmlReader r = xml.ReadSubtree();

                        r.Read();

                        while (r.Read())
                        {
                            if (!r.IsStartElement())
                            {
                                continue;
                            }
                            if (!r.MoveToFirstAttribute())
                            {
                                throw new FormatException("Malformed element '" + r.Name + "' in <query-continue>");
                            }
                            postfix += "&" + r.Name + "=" + HttpUtility.UrlEncode(r.Value);
                        }
                    }
                    else if (PageElements.Contains(xml.Name) && xml.IsStartElement())
                    {
                        //int ns = -1;
                        //int.TryParse(xml.GetAttribute("ns"), out ns);
                        string name = xml.GetAttribute("title");

                        if (string.IsNullOrEmpty(name))
                        {
                            System.Windows.Forms.MessageBox.Show(xml.ReadInnerXml());
                            break;
                        }

                        // HACK: commented out until we make AWB always load namespaces from the wiki,
                        // to avoid problems with unknown namespace
                        //if (ns >= 0) list.Add(new Article(name, ns));
                        //else
                        list.Add(new Article(name));
                    }
                }
                if (string.IsNullOrEmpty(postfix))
                {
                    break;
                }
            }

            return(list);
        }
Esempio n. 2
0
        /// <summary>
        /// Main function that retrieves the list from API, including paging
        /// </summary>
        /// <param name="url">URL of API request</param>
        /// <param name="haveSoFar">Number of pages already retrieved, for upper limit control</param>
        /// <returns>List of pages</returns>
        public List <Article> ApiMakeList(string url, int haveSoFar)
        {
            // TODO: error handling
            List <Article> list    = new List <Article>();
            string         postfix = "";

            string newUrl = url;

            ApiEdit editor = Variables.MainForm.TheSession.Editor.SynchronousEditor;

            while (list.Count + haveSoFar < Limit)
            {
                string text = editor.QueryApi(newUrl + postfix); //Hacky hack hack

                XmlTextReader xml = new XmlTextReader(new StringReader(text));
                xml.MoveToContent();
                postfix = "";

                while (xml.Read())
                {
                    if (xml.Name == "query-continue")
                    {
                        XmlReader r = xml.ReadSubtree();

                        r.Read();

                        while (r.Read())
                        {
                            if (!r.IsStartElement())
                            {
                                continue;
                            }
                            if (!r.MoveToFirstAttribute())
                            {
                                throw new FormatException("Malformed element '" + r.Name + "' in <query-continue>");
                            }
                            postfix += "&" + r.Name + "=" + HttpUtility.UrlEncode(r.Value);
                        }
                    }
                    else if (PageElements.Contains(xml.Name) && xml.IsStartElement())
                    {
                        if (!EvaluateXmlElement(xml))
                        {
                            continue;
                        }

                        int ns;
                        int.TryParse(xml.GetAttribute("ns"), out ns);
                        string name = xml.GetAttribute("title");

                        if (string.IsNullOrEmpty(name))
                        {
                            System.Windows.Forms.MessageBox.Show(xml.ReadInnerXml());
                            break;
                        }

                        list.Add(ns >= 0 ? new Article(name, ns) : new Article(name));
                    }
                }
                if (string.IsNullOrEmpty(postfix))
                {
                    break;
                }
            }

            return(list);
        }