using System;
using System.Xml;
namespace FlickrNet
{
///
/// Contains details of a user
///
[System.Serializable]
public class FoundUser
{
private string _userId;
private string _username;
///
/// The ID of the found user.
///
public string UserId
{
get { return _userId; }
}
///
/// The username of the found user.
///
public string Username
{
get { return _username; }
}
internal FoundUser(string userId, string username)
{
_userId = userId;
_username = username;
}
internal FoundUser(XmlNode node)
{
if( node.Attributes["nsid"] != null )
_userId = node.Attributes["nsid"].Value;
if( node.Attributes["id"] != null )
_userId = node.Attributes["id"].Value;
if( node.Attributes["username"] != null )
_username = node.Attributes["username"].Value;
if( node.SelectSingleNode("username") != null )
_username = node.SelectSingleNode("username").InnerText;
}
}
///
/// The upload status of the user, as returned by .
///
[System.Serializable]
public class UserStatus
{
private bool _isPro;
private string _userId;
private string _username;
private long _bandwidthMax;
private long _bandwidthUsed;
private long _filesizeMax;
internal UserStatus(XmlNode node)
{
if( node == null )
throw new ArgumentNullException("node");
if( node.Attributes["id"] != null )
_userId = node.Attributes["id"].Value;
if( node.Attributes["nsid"] != null )
_userId = node.Attributes["nsid"].Value;
if( node.Attributes["ispro"] != null )
_isPro = node.Attributes["ispro"].Value=="1";
if( node.SelectSingleNode("username") != null )
_username = node.SelectSingleNode("username").InnerText;
XmlNode bandwidth = node.SelectSingleNode("bandwidth");
if( bandwidth != null )
{
_bandwidthMax = Convert.ToInt64(bandwidth.Attributes["max"].Value);
_bandwidthUsed = Convert.ToInt64(bandwidth.Attributes["used"].Value);
}
XmlNode filesize = node.SelectSingleNode("filesize");
if( filesize != null )
{
_filesizeMax = Convert.ToInt64(filesize.Attributes["max"].Value);
}
}
///
/// The id of the user object.
///
public string UserId
{
get { return _userId; }
}
///
/// The Username of the selected user.
///
public string UserName
{
get { return _username; }
}
///
/// Is the current user a Pro account.
///
public bool IsPro
{
get { return _isPro; }
}
///
/// The maximum bandwidth (in bytes) that the user can use each month.
///
public long BandwidthMax
{
get { return _bandwidthMax; }
}
///
/// The number of bytes of the current months bandwidth that the user has used.
///
public long BandwidthUsed
{
get { return _bandwidthUsed; }
}
///
/// The maximum filesize (in bytes) that the user is allowed to upload.
///
public long FilesizeMax
{
get { return _filesizeMax; }
}
///
/// representing the percentage bandwidth used so far. Will range from 0 to 1.
///
public Double PercentageUsed
{
get { return BandwidthUsed * 1.0 / BandwidthMax; }
}
}
}