3 using System.Xml.Serialization;
4 using System.Web.Script.Serialization;
6 namespace CPE.App.Web.Connect {
9 /// Holds the various parameters for connecting to the API including the hostname and session key.
12 public class Session {
15 /// The host to access for connecting to the API.
17 /// <example>https://admin.acrobat.com</example>
18 public string Hostname { get; set; }
21 /// The unique encrypted key that identifies this login and session to Connect.
23 public string SessionKey { get; set; }
26 /// Specifies the hostname of the proxy to route all requests through.
28 public string Proxy { get; set; }
31 /// Initializes a new session.
36 /// Checks whether the current session is working and valid.
38 public bool IsValid() {
40 // Only logged in users may view shortcuts
41 var request = new Request(this, "sco-shortcuts");
42 return (request.Execute() && request.Status == Status.OK);
46 /// Checks whether the current session's login has administrative permissions.
48 public bool IsAdministrator() {
50 // Call admin-only report-quotas action
51 var request = new Request(this, "report-quotas");
52 return (request.Execute() && request.Status == Status.OK);
56 private CommonInfo _commonInfo;
57 public CommonInfo CommonInfo
61 if (_commonInfo == null)
63 // Query common-info for user information
64 var request = new Request(this, "common-info");
66 if (request.Execute() && request.Status == Status.OK)
67 _commonInfo = new CommonInfo(request.XmlResults);
74 /// Returns the user information tied to this session.
76 public CommonInfo.UserInfo UserInfo {
79 var common = CommonInfo;
87 private PrincipalInfo _principalInfo = null;
89 /// Returns the detailed principal information for the user tied to this session.
91 public PrincipalInfo PrincipalInfo {
93 if (_principalInfo == null)
95 var request = new Request(this, "principal-info");
96 request.Parameters.Add("principal-id", UserInfo.UserId.ToString());
98 if (request.Execute() && request.Status == Status.OK)
100 _principalInfo = new PrincipalInfo(request.XmlResults);
104 return _principalInfo;