using System;
using System.Xml;
using System.Xml.XPath;
namespace FlickrNet
{
///
/// Returned by methods.
///
public class GroupSearchResults
{
private int page;
///
/// The current page that the group search results represents.
///
public int Page { get { return page; } }
private int pages;
///
/// The total number of pages this search would return.
///
public int Pages { get { return pages; } }
private int perPage;
///
/// The number of groups returned per photo.
///
public int PerPage { get { return perPage; } }
private int total;
///
/// The total number of groups that where returned for the search.
///
public int Total { get { return total; } }
private GroupSearchResultCollection groups = new GroupSearchResultCollection();
///
/// The collection of groups returned for this search.
///
///
/// The following code iterates through the list of groups returned:
///
/// GroupSearchResults results = flickr.GroupsSearch("test");
/// foreach(GroupSearchResult result in results.Groups)
/// {
/// Console.WriteLine(result.GroupName);
/// }
///
///
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]));
}
}
}
///
/// Collection containing list of GroupSearchResult instances
///
public class GroupSearchResultCollection : System.Collections.CollectionBase
{
///
/// Method for adding a new to the collection.
///
///
public void Add(GroupSearchResult result)
{
List.Add(result);
}
///
/// Method for adding a collection of objects (contained within a
/// collection) to this collection.
///
///
public void AddRange(GroupSearchResultCollection results)
{
foreach(GroupSearchResult result in results)
List.Add(result);
}
///
/// Return a particular based on the index.
///
public GroupSearchResult this[int index]
{
get { return (GroupSearchResult)List[index]; }
set { List[index] = value; }
}
///
/// Removes the selected result from the collection.
///
/// The result to remove.
public void Remove(GroupSearchResult result)
{
List.Remove(result);
}
///
/// Checks if the collection contains the result.
///
/// The result to see if the collection contains.
/// Returns true if the collecton contains the result, otherwise false.
public bool Contains(GroupSearchResult result)
{
return List.Contains(result);
}
///
/// Copies the current collection to an array of objects.
///
///
///
public void CopyTo(GroupSearchResult[] array, int index)
{
List.CopyTo(array, index);
}
}
///
/// A class which encapsulates a single group search result.
///
public class GroupSearchResult
{
private string _groupId;
private string _groupName;
private bool _eighteen;
///
/// The group id for the result.
///
public string GroupId { get { return _groupId; } }
///
/// The group name for the result.
///
public string GroupName { get { return _groupName; } }
///
/// True if the group is an over eighteen (adult) group only.
///
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;
}
}
}