-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionManager.pas
74 lines (61 loc) · 1.68 KB
/
SessionManager.pas
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
unit SessionManager;
interface
uses
edbcomps;
type
TSessionManager = class
public
session : TEDBSession;
constructor Create(userId, password, hostName : String; hostPort : Integer);
destructor Destroy; override;
procedure Status(Sender: TObject; const StatusMessage: String);
procedure OnRemoteTimeout(Sender: TObject; var StayConnected : boolean);
end;
implementation
uses
SysUtils,
StrUtils,
ConsoleHelper;
{ TSessionManager }
constructor TSessionManager.Create(userId, password, hostName : String; hostPort : Integer);
begin
session := TEDBSession.Create(nil);
session.OnStatusMessage := Status;
session.OnLogMessage := Status;
session.AutoSessionName := true;
session.SessionType := stRemote;
session.LoginUser := userId;
session.LoginPassword := password;
session.CharacterSet := csAnsi;
if AnsiLeftStr(hostName, 2) = '\\' then
session.RemoteHost := AnsiRightStr(hostName, length(hostName) - 2) // '\\hostname'
else
session.RemoteAddress := hostName; //'127.0.0.1';
session.RemotePort := hostPort; //12010;
session.OnRemoteTimeout := OnRemoteTimeout;
end;
destructor TSessionManager.Destroy;
begin
FreeAndNil(session);
end;
procedure TSessionManager.OnRemoteTimeout(Sender: TObject;
var StayConnected: boolean);
var
c : Char;
begin
Write('This process is taking a long time... Continue (y/n)');
repeat
Read(c);
if c in ['y', 'Y'] then
StayConnected := True
else if c in ['n', 'N'] then
StayConnected := True
else
writeln('Try y or n');
until c in ['y', 'Y', 'n', 'N'];
end;
procedure TSessionManager.Status(Sender: TObject; const StatusMessage: String);
begin
VerboseWrite(StatusMessage);
end;
end.