using System.Xml;
namespace CPE.App.Web.Connect {
///
/// Represents a common-info object returned from Connect.
///
public class CommonInfo {
///
/// The hostname of the Connect service.
///
public string Host { get; private set; }
///
/// The AccountID of the host of the Connect service.
///
public int AccountId { get; private set; }
///
/// The session cookie value for the current request.
///
public string Cookie { get; private set; }
///
/// Returns whether the request is logged in and authenticated with Connect.
///
public bool IsAuthenticated { get { return User.UserId.HasValue; } }
///
/// Contains the user account information if a user is logged into Connect.
///
public UserInfo User { get; private set; }
///
/// Initializes the object by parsing the values from the XmlDocument.
///
/// The XmlDocument returned from Connect for this object.
public CommonInfo(XmlNode document) {
// Find main node
XmlNode common = document.SelectSingleNode("/results/common");
// Parse values
Host = common["host"].InnerText;
AccountId = int.Parse(common["account"].Attributes["account-id"].Value);
Cookie = common["cookie"].InnerText;
// Blank user
User = new UserInfo();
if(common["user"] != null) {
User.UserId = int.Parse(common["user"].Attributes["user-id"].Value);
User.Name = common["user"].SelectSingleNode("name").InnerText;
User.Login = common["user"].SelectSingleNode("login").InnerText;
}
}
///
/// Contains the current user information if logged into the service.
///
public class UserInfo {
///
/// The UserID of the user.
///
public int? UserId { get; internal set; }
///
/// The full name of the user.
///
public string Name { get; internal set; }
///
/// The login of the user.
///
public string Login { get; internal set; }
}
}
}