protected override void OnStartSearch()
        {
            string webQuery = this.GetWebQuery(this.SearchQuery);

            try
            {
                //parser code to parse through RSS results
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(webQuery);
                var root = xmlDocument.DocumentElement;

                //each item/entry is a unique result
                var entries = root.GetElementsByTagName("item");
                if (entries.Count == 0)
                    entries = root.GetElementsByTagName("entry");

                for (int i = 0; i < Math.Min(10, entries.Count); i++)
                {
                    var entry = entries[i] as XmlElement;

                    if (entry != null)
                    {
                        string title = null;
                        string url = null;

                        //title tag provides result title
                        var titleNodes = entry.GetElementsByTagName("title");
                        if (titleNodes.Count > 0)
                        {
                            title = titleNodes[0].InnerText;
                        }

                        //link / url / id tag provides the URL linking the result string to its page
                        var linkNodes = entry.GetElementsByTagName("link");
                        if (linkNodes.Count == 0)
                            linkNodes = entry.GetElementsByTagName("url");
                        if (linkNodes.Count == 0)
                            linkNodes = entry.GetElementsByTagName("id");

                        if (linkNodes.Count > 0)
                        {
                            url = linkNodes[0].InnerText;
                        }

                        if (title != null && url != null)
                        {
                            var result = new VSSearchResult(title, url, this.provider);

                            this.SearchCallback.ReportResult(this, result);
                        }
                    }
                }

                this.SearchCallback.ReportComplete(this, (uint)entries.Count);
            }
            catch (Exception)
            {
                this.SearchCallback.ReportComplete(this, 0);
            }
        }
示例#2
0
        protected override void OnStartSearch()
        {
            string webQuery = this.GetWebQuery(this.SearchQuery);

            try
            {
                //parser code to parse through RSS results
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(webQuery);
                var root = xmlDocument.DocumentElement;

                //each item/entry is a unique result
                var entries = root.GetElementsByTagName("item");
                if (entries.Count == 0)
                {
                    entries = root.GetElementsByTagName("entry");
                }

                for (int i = 0; i < Math.Min(10, entries.Count); i++)
                {
                    var entry = entries[i] as XmlElement;

                    if (entry != null)
                    {
                        string title = null;
                        string url   = null;

                        //title tag provides result title
                        var titleNodes = entry.GetElementsByTagName("title");
                        if (titleNodes.Count > 0)
                        {
                            title = titleNodes[0].InnerText;
                        }

                        //link / url / id tag provides the URL linking the result string to its page
                        var linkNodes = entry.GetElementsByTagName("link");
                        if (linkNodes.Count == 0)
                        {
                            linkNodes = entry.GetElementsByTagName("url");
                        }
                        if (linkNodes.Count == 0)
                        {
                            linkNodes = entry.GetElementsByTagName("id");
                        }

                        if (linkNodes.Count > 0)
                        {
                            url = linkNodes[0].InnerText;
                        }

                        if (title != null && url != null)
                        {
                            var result = new VSSearchResult(title, url, this.provider);

                            this.SearchCallback.ReportResult(this, result);
                        }
                    }
                }

                this.SearchCallback.ReportComplete(this, (uint)entries.Count);
            }
            catch (Exception)
            {
                this.SearchCallback.ReportComplete(this, 0);
            }
        }