-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSession.cs
80 lines (70 loc) · 2.42 KB
/
Session.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using RustyLogic.RedDotNet.Service.Rql;
using RustyLogic.RedDotNet.Service.Session;
using RustyLogic.RedDotNet.Service.Page;
using RustyLogic.RedDotNet.Service.Navigation;
namespace RustyLogic.RedDotNet
{
public static class Session
{
public enum Info { None, LoginGuid, SessionKey };
private static SessionService _sessionService = new SessionService();
private static RqlService _rqlService = new RqlService();
private static string _sessionKey;
private static Guid _loginGuid;
public static string LoginGuidString
{
get { return Session._loginGuid.ToString("N").ToUpper(); }
}
public static void UseExisting(string loginGuid, string sessionKey)
{
_loginGuid = new Guid(loginGuid);
_sessionKey = sessionKey;
}
public static bool Login(string username, string password)
{
_rqlService.Timeout = 60000 * 10;
_loginGuid = _sessionService.Login(username, password);
return _loginGuid != Guid.Empty;
}
public static void Logout()
{
_sessionService.Logout(_loginGuid);
_loginGuid = Guid.Empty;
}
internal static void SelectProject(Guid projectId)
{
_sessionKey = _sessionService.SelectProject(projectId, _loginGuid);
}
internal static string Execute(string rql)
{
return Execute(rql, Info.SessionKey);
}
internal static string Execute(string rql, Info type)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rql);
return Execute(xmlDoc, type);
}
internal static string Execute(XmlDocument xml)
{
return Execute(xml, Info.SessionKey);
}
internal static string Execute(XmlDocument xmlDoc, Info type)
{
if (type == Info.LoginGuid || type == Info.SessionKey)
{
XmlElement ioData = xmlDoc.DocumentElement;
ioData.SetAttribute("loginguid", LoginGuidString);
if (type == Info.SessionKey)
{
ioData.SetAttribute("sessionkey", _sessionKey);
}
}
return _rqlService.ExecuteString(xmlDoc.InnerXml);
}
}
}