예제 #1
0
        public void parse_DownloadICSearchResultsCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            ICSearchResults.Clear();
            IList<HtmlNode> hnc = e.Document.DocumentNode.DescendantNodes().ToList();

            foreach (HtmlNode htmlNode in hnc)
            {
                if (htmlNode.Name.ToLower() == "div")
                {
                    for (int att = htmlNode.Attributes.Count - 1; att >= 0; att--)
                    {
                        if (htmlNode.Attributes[att].Name.ToLower() == "id" && htmlNode.Attributes[att].Value == "bodyContent")
                        {
                            IList<HtmlNode> rs = htmlNode.DescendantNodes().ToList();
                            String category = "";
                            foreach (HtmlNode j in rs)
                            {
                                if (j.Name.ToLower() == "h2")
                                {
                                    category = j.InnerText;
                                }
                                if (j.Name.ToLower() == "ol")
                                {

                                    IList<HtmlNode> li = j.DescendantNodes().ToList();
                                    foreach (HtmlNode k in li)
                                    {
                                        IronChariotsSearchViewModel sr = new IronChariotsSearchViewModel();
                                        if (k.Name.ToLower() == "li")
                                        {
                                            IList<HtmlNode> innerNode = k.DescendantNodes().ToList();
                                            foreach (HtmlNode rsk in innerNode)
                                            {
                                                if (rsk.Name.ToLower() == "a")
                                                {
                                                    foreach (HtmlAttribute at in rsk.Attributes.ToList())
                                                    {
                                                        if (at.Name.ToLower() == "href")
                                                        {
                                                            sr.Href = at.Value;
                                                        }
                                                        else if (at.Name.ToLower() == "title")
                                                        {
                                                            sr.Title = at.Value;
                                                        }
                                                    }
                                                }
                                                if (rsk.Name.ToLower() == "small")
                                                {
                                                    String str = rsk.InnerText.Trim();
                                                    str = str.Replace("&quot;", "\"");
                                                    str = str.Replace("[", "");
                                                    str = str.Replace("]", "");
                                                    sr.Description += str;
                                                    sr.Description += " ";
                                                }
                                            }
                                            sr.Category = category;
                                            ICSearchResults.Add(sr);
                                        }

                                    }
                                }
                            }
                        }
                    }
                }
            }
            NotifyPropertyChanged("ICSearchRetrived");
        }
예제 #2
0
        public void parseIronChariotsSearch(Object sender, OpenReadCompletedEventArgs e)
        {
            XElement resultXml;
            ICSearchResults.Clear();
            if (e.Error != null)
            {
                IronChariotsSearchViewModel ics = new IronChariotsSearchViewModel();
                ics.Title = "Error";
                ics.Description = "An error occured trying to retrieve search results, please try again.";
                ics.Href = "Error";
                ICSearchResults.Add(ics);
                NotifyPropertyChanged("ICSearchRetrived");
                return;
            }
            else
            {

                XNamespace web = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web";
                try
                {
                    resultXml = XElement.Load(e.Result);
                    // Search for the WebResult node and create a SearchResults object for each one.

                    foreach (XElement result in resultXml.Descendants(web + "WebResult"))
                    {
                        IronChariotsSearchViewModel ics = new IronChariotsSearchViewModel();
                        ics.Title = result.Element(web + "Title").Value.Trim();
                        if (ics.Title.Contains("Image:") || ics.Title.Contains("Talk:") || ics.Title.Contains("Template:") )
                        {
                            continue;
                        }
                        ics.Description = result.Element(web + "Description").Value.Trim();
                        ics.Href = result.Element(web + "Url").Value;
                        ICSearchResults.Add(ics);
                    }
                }
                catch (System.Xml.XmlException ex)
                {

                }
                NotifyPropertyChanged("ICSearchRetrived");
            }
        }