using System;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml;
namespace FlickrNet
{
///
/// Provides details of a particular group.
///
/// Used by and
/// .
[System.Serializable]
public class Group
{
///
/// The id of the group.
///
[XmlAttribute("nsid", Form=XmlSchemaForm.Unqualified)]
public string GroupId;
///
/// The name of the group
///
[XmlAttribute("name", Form=XmlSchemaForm.Unqualified)]
public string GroupName;
///
/// The number of memebers of the group.
///
[XmlAttribute("members", Form=XmlSchemaForm.Unqualified)]
public long Members;
}
///
/// Provides details of a particular group.
///
///
/// Used by the Url methods and method.
/// The reason for a and are due to xml serialization
/// incompatabilities.
///
[System.Serializable]
public class GroupFullInfo
{
internal GroupFullInfo()
{
}
internal GroupFullInfo(XmlNode node)
{
if( node.Attributes.GetNamedItem("id") != null )
GroupId = node.Attributes.GetNamedItem("id").Value;
if( node.SelectSingleNode("name") != null )
GroupName = node.SelectSingleNode("name").InnerText;
if( node.SelectSingleNode("description") != null )
Description = node.SelectSingleNode("description").InnerXml;
if( node.SelectSingleNode("members") != null )
Members = int.Parse(node.SelectSingleNode("members").InnerText);
if( node.SelectSingleNode("privacy") != null )
Privacy = (PoolPrivacy)int.Parse(node.SelectSingleNode("privacy").InnerText);
if( node.SelectSingleNode("throttle") != null )
{
XmlNode throttle = node.SelectSingleNode("throttle");
ThrottleInfo = new GroupThrottleInfo();
if( throttle.Attributes.GetNamedItem("count") != null )
ThrottleInfo.Count = int.Parse(throttle.Attributes.GetNamedItem("count").Value);
if( throttle.Attributes.GetNamedItem("mode") != null )
ThrottleInfo.setMode(throttle.Attributes.GetNamedItem("mode").Value);
if( throttle.Attributes.GetNamedItem("remaining") != null )
ThrottleInfo.Remaining = int.Parse(throttle.Attributes.GetNamedItem("remaining").Value);
}
}
///
public string GroupId;
///
public string GroupName;
///
public string Description;
///
public long Members;
///
public PoolPrivacy Privacy;
///
public GroupThrottleInfo ThrottleInfo;
///
/// Methods for automatically converting a object into
/// and instance of a object.
///
/// The incoming object.
/// The instance.
public static implicit operator Group( GroupFullInfo groupInfo )
{
Group g = new Group();
g.GroupId = groupInfo.GroupId;
g.GroupName = groupInfo.GroupName;
g.Members = groupInfo.Members;
return g;
}
///
/// Converts the current into an instance of the
/// class.
///
/// A instance.
public Group ToGroup()
{
return (Group)this;
}
}
///
/// Throttle information about a group (i.e. posting limit)
///
public class GroupThrottleInfo
{
///
/// The number of posts in each period allowed to this group.
///
public int Count;
///
/// The posting limit mode for a group.
///
public GroupThrottleMode Mode;
internal void setMode(string mode)
{
switch(mode)
{
case "day":
Mode = GroupThrottleMode.PerDay;
break;
case "week":
Mode = GroupThrottleMode.PerWeek;
break;
case "month":
Mode = GroupThrottleMode.PerMonth;
break;
case "ever":
Mode = GroupThrottleMode.Ever;
break;
case "none":
Mode = GroupThrottleMode.NoLimit;
break;
case "disabled":
Mode = GroupThrottleMode.Disabled;
break;
default:
throw new ArgumentException(string.Format("Unknown mode found {0}", mode), "mode");
}
}
///
/// The number of remainging posts allowed by this user. If unauthenticated then this will be zero.
///
public int Remaining;
}
///
/// The posting limit most for a group.
///
public enum GroupThrottleMode
{
///
/// Per day posting limit.
///
PerDay,
///
/// Per week posting limit.
///
PerWeek,
///
/// Per month posting limit.
///
PerMonth,
///
/// No posting limit.
///
NoLimit,
///
/// Posting limit is total number of photos in the group.
///
Ever,
///
/// Posting is disabled to this group.
///
Disabled
}
///
/// Information about a group the authenticated user is a member of.
///
public class MemberGroupInfo
{
internal static MemberGroupInfo[] GetMemberGroupInfo(XmlNode node)
{
XmlNodeList list = node.SelectNodes("//group");
MemberGroupInfo[] infos = new MemberGroupInfo[list.Count];
for(int i = 0; i < infos.Length; i++)
{
infos[i] = new MemberGroupInfo(list[i]);
}
return infos;
}
internal MemberGroupInfo(XmlNode node)
{
if( node.Attributes["nsid"] != null )
_groupId = node.Attributes["nsid"].Value;
if( node.Attributes["name"] != null )
_groupName = node.Attributes["name"].Value;
if( node.Attributes["admin"] != null )
_isAdmin = node.Attributes["admin"].Value=="1";
if( node.Attributes["privacy"] != null )
_privacy = (PoolPrivacy)Enum.Parse(typeof(PoolPrivacy),node.Attributes["privacy"].Value, true);
if( node.Attributes["photos"] != null )
_numberOfPhotos = Int32.Parse(node.Attributes["photos"].Value);
if( node.Attributes["iconserver"] != null )
_iconServer = node.Attributes["iconserver"].Value;
}
private string _groupId;
///
/// Property which returns the group id for the group.
///
public string GroupId
{
get { return _groupId; }
}
private string _groupName;
/// The group name.
public string GroupName
{
get { return _groupName; }
}
private bool _isAdmin;
///
/// True if the user is the admin for the group, false if they are not.
///
public bool IsAdmin
{
get { return _isAdmin; }
}
private long _numberOfPhotos;
///
/// The number of photos currently in the group pool.
///
public long NumberOfPhotos
{
get { return _numberOfPhotos; }
}
private PoolPrivacy _privacy;
///
/// The privacy of the pool (see ).
///
public PoolPrivacy Privacy
{
get { return _privacy; }
}
private string _iconServer;
///
/// The server number for the group icon.
///
public string IconServer
{
get { return _iconServer; }
}
///
/// The URL for the group icon.
///
public Uri GroupIconUrl
{
get { return new Uri(String.Format("http://static.flickr.com/{0}/buddyicons/{1}.jpg", IconServer, GroupId)); }
}
///
/// The URL for the group web page.
///
public Uri GroupUrl
{
get { return new Uri(String.Format("http://www.flickr.com/groups/{0}/", GroupId)); }
}
}
///
/// Information about public groups for a user.
///
[System.Serializable]
public class PublicGroupInfo
{
internal static PublicGroupInfo[] GetPublicGroupInfo(XmlNode node)
{
XmlNodeList list = node.SelectNodes("//group");
PublicGroupInfo[] infos = new PublicGroupInfo[list.Count];
for(int i = 0; i < infos.Length; i++)
{
infos[i] = new PublicGroupInfo(list[i]);
}
return infos;
}
internal PublicGroupInfo(XmlNode node)
{
if( node.Attributes["nsid"] != null )
_groupId = node.Attributes["nsid"].Value;
if( node.Attributes["name"] != null )
_groupName = node.Attributes["name"].Value;
if( node.Attributes["admin"] != null )
_isAdmin = node.Attributes["admin"].Value=="1";
if( node.Attributes["eighteenplus"] != null )
_isEighteenPlus = node.Attributes["eighteenplus"].Value=="1";
}
private string _groupId;
///
/// Property which returns the group id for the group.
///
public string GroupId
{
get { return _groupId; }
}
private string _groupName;
/// The group name.
public string GroupName
{
get { return _groupName; }
}
private bool _isAdmin;
///
/// True if the user is the admin for the group, false if they are not.
///
public bool IsAdmin
{
get { return _isAdmin; }
}
private bool _isEighteenPlus;
///
/// Will contain 1 if the group is restricted to people who are 18 years old or over, 0 if it is not.
///
public bool EighteenPlus
{
get { return _isEighteenPlus; }
}
///
/// The URL for the group web page.
///
public Uri GroupUrl
{
get { return new Uri(String.Format("http://www.flickr.com/groups/{0}/", GroupId)); }
}
}
///
/// The various pricay settings for a group.
///
[System.Serializable]
public enum PoolPrivacy
{
///
/// No privacy setting specified.
///
[XmlEnum("0")]
None = 0,
///
/// The group is a private group. You cannot view pictures or posts until you are a
/// member. The group is also invite only.
///
[XmlEnum("1")]
Private = 1,
///
/// A public group where you can see posts and photos in the group. The group is however invite only.
///
[XmlEnum("2")]
InviteOnlyPublic = 2,
///
/// A public group.
///
[XmlEnum("3")]
OpenPublic = 3
}
}