using System;
using System.IO;
using System.Xml.Serialization;
using System.Web.Script.Serialization;
namespace CPE.App.Web.Connect {
///
/// Holds the various parameters for connecting to the API including the hostname and session key.
///
[Serializable]
public class Session {
///
/// The host to access for connecting to the API.
///
/// https://admin.acrobat.com
public string Hostname { get; set; }
///
/// The unique encrypted key that identifies this login and session to Connect.
///
public string SessionKey { get; set; }
///
/// Specifies the hostname of the proxy to route all requests through.
///
public string Proxy { get; set; }
///
/// Initializes a new session.
///
public Session() { }
///
/// Checks whether the current session is working and valid.
///
public bool IsValid() {
// Only logged in users may view shortcuts
var request = new Request(this, "sco-shortcuts");
return (request.Execute() && request.Status == Status.OK);
}
///
/// Checks whether the current session's login has administrative permissions.
///
public bool IsAdministrator() {
// Call admin-only report-quotas action
var request = new Request(this, "report-quotas");
return (request.Execute() && request.Status == Status.OK);
}
private CommonInfo _commonInfo;
public CommonInfo CommonInfo
{
get
{
if (_commonInfo == null)
{
// Query common-info for user information
var request = new Request(this, "common-info");
if (request.Execute() && request.Status == Status.OK)
_commonInfo = new CommonInfo(request.XmlResults);
}
return _commonInfo;
}
}
///
/// Returns the user information tied to this session.
///
public CommonInfo.UserInfo UserInfo {
get {
var common = CommonInfo;
if (common != null)
return common.User;
return null;
}
}
private PrincipalInfo _principalInfo = null;
///
/// Returns the detailed principal information for the user tied to this session.
///
public PrincipalInfo PrincipalInfo {
get {
if (_principalInfo == null)
{
var request = new Request(this, "principal-info");
request.Parameters.Add("principal-id", UserInfo.UserId.ToString());
if (request.Execute() && request.Status == Status.OK)
{
_principalInfo = new PrincipalInfo(request.XmlResults);
}
}
return _principalInfo;
}
}
}
}