⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liveexporesults.cs

📁 Accessing microsoft live web services from windows mobile
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using LiveExpoService.LiveExpo;

namespace LiveExpoService
{
    /// <summary>
    /// LiveExpoCategories contains functionality to retrieve a list of items that are retrieved from the Windows Live Expo Service.
    /// All items found are maintained in a generics List object for later use to actually display or retrieve details
    /// for a specific item on the Expo Service.
    /// </summary>
    public class LiveExpoResults
    {
        private static LiveExpoResults theInstance;
        private static List<LiveExpoResult> results;

        private LiveExpoResults()
        {
        }

        /// <summary>
        /// Instance
        /// 
        /// LiveExpoResults is ipmlemented as a singleton, meaning there is at most one instance of the class available at any time.
        /// This method creates the instance or simply returns it when it was created earlier.
        /// </summary>
        /// <returns>LiveExpoResults - The one and only instance of this class.</returns>
        public static LiveExpoResults Instance()
        {
            if (theInstance == null)
            {
                theInstance = new LiveExpoResults();
            }
            return theInstance;
        }

        /// <summary>
        /// Indexer to retrieve a particular item.
        /// </summary>
        /// <param name="index">int - value between 0 and results.Count.</param>
        /// <returns>LiveExpoResult - The specified item.</returns>
        public LiveExpoResult this[int index]   // Indexer declaration
        {
            get
            {
                // Check the index limits.
                if (index < 0 || index >= results.Count || results == null)
                {
                    return null;
                }
                else
                {
                    return results[index];
                }
            }
        }

        /// <summary>
        /// SearchResults
        /// 
        /// Method to search for results in a specified location (set by LiveExpoHelper) for items in a particular category.
        /// A number of properties of the found item are stored in individual LiveExpoResult objects.
        /// </summary>
        /// <param name="categoryID">int - The id of a category to look for particular items</param>
        /// <param name="keyWord">string - The keyword to search for (at most 10 items containing the keyword in a particular category will be returned)</param>
        /// <returns></returns>
        /// <remarks>
        /// Categories into which to look for items can be retrieved by methods in the LivExpoCategories class.
        /// </remarks>
        public List<LiveExpoResult> SearchResults(int categoryID, string keyWord)
        {
            Classifieds_Listings cl = new Classifieds_Listings();
            string resp = cl.ListingsByCategoryKeywordLocation_V2(1,
                LiveExpoHelper.Credentials,
                1,
                10,
                "CreatedDate",
                true,
                categoryID,
                keyWord,
                LiveExpoHelper.SearchCity,
                LiveExpoHelper.SearchState,
                LiveExpoHelper.SearchZIP,
                LiveExpoHelper.SearchCountry,
                LiveExpoHelper.SearchDistance,
                "For Sale");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(resp);
            XmlNodeList foundItems = doc.GetElementsByTagName("item");

            results = new List<LiveExpoResult>();

            foreach (XmlNode item in foundItems)
            {
                XmlNodeList foundResults = item.ChildNodes;
                foreach (XmlNode x in foundResults)
                {
                    if (x.LocalName.CompareTo("title") == 0)
                    {
                        results.Add(new LiveExpoResult(x.InnerText));
                    }
                    else if (x.LocalName.CompareTo("link") == 0)
                    {
                        results[results.Count-1].ExpoLink = new Uri(x.InnerText);
                    }
                    else if (x.LocalName.CompareTo("description") == 0)
                    {
                        results[results.Count-1].Description = x.InnerText;
                    }
                    else if (x.LocalName.CompareTo("enclosure") == 0)
                    {
                        XmlAttribute a = x.Attributes["url"];
                        results[results.Count - 1].PictureLink = new Uri(a.Value);
                    }
                    else if (x.LocalName.CompareTo("location") == 0)
                    {
                        XmlNodeList foundLocationInfo = x.ChildNodes;

                        foreach (XmlNode n in foundLocationInfo)
                        {
                            if (n.LocalName.CompareTo("address") == 0)
                            {
                                results[results.Count - 1].Address = n.InnerText;
                            }
                            else if (n.LocalName.CompareTo("city") == 0)
                            {
                                results[results.Count - 1].City = n.InnerText;
                            }
                            else if (n.LocalName.CompareTo("state") == 0)
                            {
                                results[results.Count - 1].State = n.InnerText;
                            }
                            else if (n.LocalName.CompareTo("country") == 0)
                            {
                                results[results.Count - 1].Country = n.InnerText;
                            }
                            else if (n.LocalName.CompareTo("postcode") == 0)
                            {
                                results[results.Count - 1].ZipCode = n.InnerText;
                            }
                            else if (n.LocalName.CompareTo("latitude") == 0)
                            {
                                results[results.Count - 1].Latitude = Convert.ToSingle(n.InnerText);
                            }
                            else if (n.LocalName.CompareTo("longitude") == 0)
                            {
                                results[results.Count - 1].Longitude = Convert.ToSingle(n.InnerText);
                            }
                        }
                    }
                    else if (x.LocalName.CompareTo("details") == 0)
                    {
                        // number of child nodes in combination with CategoryAttributes (meaning etc.)
                    }
                }
            }

            return results;
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -