-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuPrincipal.pas
More file actions
96 lines (80 loc) · 2.49 KB
/
uPrincipal.pas
File metadata and controls
96 lines (80 loc) · 2.49 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit uPrincipal;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdHTTP, IdURI, IdSSLOpenSSL, superobject, Generics.Collections,
Vcl.ExtCtrls, iniFiles, uUploadThread,uReportThread;
type
TForm2 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
private
tUpload : UploadThread;
tReport : TreportThread;
closeApp : boolean;
statusCodes : TDictionary<integer, string>;
{ Private declarations }
function getCodeDescription(code : integer) : String;
function getURL(url : String; params : TStringList) : String;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Memo1.Lines.Add('Terminando ejecucion de hilos');
tUpload.Terminate;
tReport.Terminate;
sleep(2000);
end;
function TForm2.getCodeDescription(code: integer): String;
begin
if (statusCodes.ContainsKey(code)) then begin
Result := statusCodes.Items[code];
end else begin
Result := 'Error desconocido: '+IntToStr(code);
end;
end;
function TForm2.getURL(url: String; params: TStringList): String;
var
i: Integer;
begin
Result := url + '?';
for i := 0 to params.Count - 1 do begin
Result := Result + params[i];
end;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
var
appPath : String;
apiKey : String;
url : String;
layoutId : String;
iniFile : TIniFile;
sleepTime: Integer;
begin
Timer1.Enabled := false;
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'api_config.ini');
try
apiKey := iniFile.ReadString('API', 'apikey', '');
layoutId := iniFile.ReadString('API', 'layout', 'default');
url := iniFile.ReadString('API', 'url', 'https://agencia.gestii.com');
sleepTime := iniFile.ReadInteger('API', 'sleepTime', 1000);
iniFile.WriteString('API', 'apikey', apiKey);
iniFile.WriteString('API', 'layout', layoutId);
iniFile.WriteString('API', 'url', url);
iniFile.WriteInteger('API', 'sleepTime', sleepTime);
finally
iniFile.Free;
end;
tUpload := UploadThread.Create(Memo1,ExtractFilePath(Application.ExeName),apiKey, url );
tUpload.iniciar(layoutId,sleepTime);
tReport := TReportThread.Create(Memo1,ExtractFilePath(Application.ExeName),apiKey, url);
tReport.iniciar();
end;
end.