Logo Search packages:      
Sourcecode: f-spot version File versions  Download package

GroupSearchResults.cs

using System;
using System.Xml;
using System.Xml.XPath;

namespace FlickrNet
{
      /// <summary>
      /// Returned by <see cref="Flickr.GroupsSearch(string)"/> methods.
      /// </summary>
00010       public class GroupSearchResults
      {
            private int page;

            /// <summary>
            /// The current page that the group search results represents.
            /// </summary>
00017             public int Page { get { return page; } }

            private int pages;

            /// <summary>
            /// The total number of pages this search would return.
            /// </summary>
00024             public int Pages { get { return pages; } }

            private int perPage;

            /// <summary>
            /// The number of groups returned per photo.
            /// </summary>
00031             public int PerPage { get { return perPage; } }

            private int total;
            /// <summary>
            /// The total number of groups that where returned for the search.
            /// </summary>
00037             public int Total { get { return total; } }

            private GroupSearchResultCollection groups = new GroupSearchResultCollection();

            /// <summary>
            /// The collection of groups returned for this search.
            /// </summary>
            /// <example>
            /// The following code iterates through the list of groups returned:
            /// <code>
            /// GroupSearchResults results = flickr.GroupsSearch("test");
            /// foreach(GroupSearchResult result in results.Groups)
            /// {
            ///         Console.WriteLine(result.GroupName);
            /// }
            /// </code>
            /// </example>
00054             public GroupSearchResultCollection Groups { get { return groups; } }

            internal GroupSearchResults(XmlElement element)
            {
                  page = Convert.ToInt32(element.GetAttribute("page"));
                  pages = Convert.ToInt32(element.GetAttribute("pages"));
                  perPage = Convert.ToInt32(element.GetAttribute("perpage"));
                  total = Convert.ToInt32(element.GetAttribute("total"));

                  XmlNodeList gs = element.SelectNodes("group");
                  groups.Clear();
                  for(int i = 0; i < gs.Count; i++)
                  {
                        groups.Add(new GroupSearchResult(gs[i]));
                  }
            }
      }

      /// <summary>
      /// Collection containing list of GroupSearchResult instances
      /// </summary>
00075       public class GroupSearchResultCollection : System.Collections.CollectionBase
      {
            /// <summary>
            /// Method for adding a new <see cref="GroupSearchResult"/> to the collection.
            /// </summary>
            /// <param name="result"></param>
00081             public void Add(GroupSearchResult result)
            {
                  List.Add(result);
            }

            /// <summary>
            /// Method for adding a collection of <see cref="GroupSearchResult"/> objects (contained within a
            /// <see cref="GroupSearchResults"/> collection) to this collection.
            /// </summary>
            /// <param name="results"></param>
00091             public void AddRange(GroupSearchResultCollection results)
            {
                  foreach(GroupSearchResult result in results)
                        List.Add(result);
            }

            /// <summary>
            /// Return a particular <see cref="GroupSearchResult"/> based on the index.
            /// </summary>
            public GroupSearchResult this[int index]
00101             {
                  get { return (GroupSearchResult)List[index]; }
                  set { List[index] = value; }
            }

            /// <summary>
            /// Removes the selected result from the collection.
            /// </summary>
            /// <param name="result">The result to remove.</param>
00110             public void Remove(GroupSearchResult result)
            {
                  List.Remove(result);
            }

            /// <summary>
            /// Checks if the collection contains the result.
            /// </summary>
            /// <param name="result">The result to see if the collection contains.</param>
            /// <returns>Returns true if the collecton contains the result, otherwise false.</returns>
00120             public bool Contains(GroupSearchResult result)
            {
                  return List.Contains(result);
            }

            /// <summary>
            /// Copies the current collection to an array of <see cref="GroupSearchResult"/> objects.
            /// </summary>
            /// <param name="array"></param>
            /// <param name="index"></param>
00130             public void CopyTo(GroupSearchResult[] array, int index)
            {
                  List.CopyTo(array, index);
            }
      }

      /// <summary>
      /// A class which encapsulates a single group search result.
      /// </summary>
00139       public class GroupSearchResult
      {
            private string _groupId;
            private string _groupName;
            private bool _eighteen;

            /// <summary>
            /// The group id for the result.
            /// </summary>
00148             public string GroupId { get { return _groupId; } }
            /// <summary>
            /// The group name for the result.
            /// </summary>
00152             public string GroupName { get { return _groupName; } }
            /// <summary>
            /// True if the group is an over eighteen (adult) group only.
            /// </summary>
00156             public bool EighteenPlus { get { return _eighteen; } }

            internal GroupSearchResult(XmlNode node)
            {
                  _groupId = node.Attributes["nsid"].Value;
                  _groupName = node.Attributes["name"].Value;
                  _eighteen = Convert.ToInt32(node.Attributes["eighteenplus"].Value)==1;
            }
      }
}

Generated by  Doxygen 1.6.0   Back to index