-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuxtStore.pas
241 lines (189 loc) · 6.14 KB
/
uxtStore.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
unit uxtStore;
interface
uses system.SysUtils, system.Classes, xtCommonTypes, xtConnection,
uxtCommonComponent, xtServiceAddress;
type
TxtStore = class(TxtBaseComponent)
const
seconLevDomain = 'xtumble.store';
private
FwebAlias: String;
FonWebAliasChange: TNotifyEvent;
Fhttp_port: Integer;
function getStoreUrl: String;
procedure SetwebAlias(const Value: String);
procedure SetonWebAliasChange(const Value: TNotifyEvent);
procedure Sethttp_port(const Value: Integer);
function getWebTemplate: String;
procedure setWebTemplate(const Value: String);
protected
procedure doBeforeActivate; override;
function getWebAlias : String;
public
constructor Create(AOwner: TComponent); override;
published
property xtConnection;
property http_port : Integer read Fhttp_port write Sethttp_port;
property webAlias : String read FwebAlias write SetwebAlias;
property webTemplate : String read getWebTemplate write setWebTemplate;
property StoreUrl : String read getStoreUrl;
property onWebAliasChange : TNotifyEvent read FonWebAliasChange write SetonWebAliasChange;
function addNonPrimaryWebAlias(NewWebAlias: String) : String;
function deleteWebAlias(WebAlias: String): String;
end;
procedure Register;
implementation
{ TxtStore }
uses System.Net.URLClient, System.Net.HttpClient,
System.Net.HttpClientComponent, system.IOUtils,
System.Net.Mime;
procedure Register;
begin
RegisterComponents('xTumble', [TxtStore]);
end;
function TxtStore.addNonPrimaryWebAlias(NewWebAlias: String) : String;
var
respo: IHTTPResponse;
begin
if xtConnection = nil then exit;
respo := HTTPprov.doGet(xtConnection.ConnectionParams,TxtServices.setWebalias,'web_alias=' + NewWebAlias.ToLower + '&additional_domain=Y');
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
Result := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getWebAlias error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
// if assigned(FonWebAliasChange) then
// FonWebAliasChange(Self);
end;
constructor TxtStore.Create(AOwner: TComponent);
begin
inherited;
FWebAlias := '';
FonwebaliasChange := nil;
Fhttp_port := 443;
end;
function TxtStore.deleteWebAlias(WebAlias: String): String;
var
respo: IHTTPResponse;
begin
if xtConnection = nil then exit;
respo := HTTPprov.doDelete(xtConnection.ConnectionParams,TxtServices.setWebalias,'web_alias=' + WebAlias.ToLower + '&additional_domain=Y');
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
Result := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getWebAlias error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
end;
procedure TxtStore.doBeforeActivate;
begin
inherited;
FwebAlias := getWebAlias;
if assigned(FonWebAliasChange) then
FonWebAliasChange(Self);
end;
function TxtStore.getStoreUrl: String;
begin
{ TODO : Inserire la chiamata ad una nuova servlet per gestire l'impostazione relativa ai domini personalizzati }
if FwebAlias <> '' then
Begin
if Fhttp_port = 443 then
result := 'https://' + FwebAlias + '.xtumble.store'
Else
result := 'http://' + FwebAlias + '.xtumble.store';
End
else
result := 'https://xtumble.store';
if (Fhttp_port <> 443)AND(Fhttp_port <> 0)AND(Fhttp_port <> 80) then
result := result + ':' + http_port.ToString;
end;
function TxtStore.getWebAlias: String;
var
respo: IHTTPResponse;
begin
result := '';
if xtConnection = nil then exit;
if not xtConnection.Connected then exit;
respo := HTTPprov.doGet(xtConnection.ConnectionParams,TxtServices.getWebAlias,'');
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
result := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getWebAlias error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
end;
function TxtStore.getWebTemplate: String;
var
respo: IHTTPResponse;
begin
result := '';
if xtConnection = nil then exit;
if not xtConnection.Connected then exit;
respo := HTTPprov.doGet(xtConnection.ConnectionParams,TxtServices.getwebtemplate,'');
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
result := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getwebtemplate error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
end;
procedure TxtStore.Sethttp_port(const Value: Integer);
begin
Fhttp_port := Value;
end;
procedure TxtStore.SetonWebAliasChange(const Value: TNotifyEvent);
begin
FonWebAliasChange := Value;
end;
procedure TxtStore.SetwebAlias(const Value: String);
var
respo: IHTTPResponse;
begin
if xtConnection = nil then exit;
if not xtConnection.Connected then exit;
if not active then exit;
if FwebAlias <> Value then
Begin
respo := HTTPprov.doGet(xtConnection.ConnectionParams,TxtServices.setWebalias,'web_alias=' + Value.ToLower);
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
FwebAlias := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getWebAlias error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
if assigned(FonWebAliasChange) then
FonWebAliasChange(Self);
End;
end;
procedure TxtStore.setWebTemplate(const Value: String);
var
respo: IHTTPResponse;
begin
if xtConnection = nil then exit;
if FwebAlias <> Value then
Begin
respo := HTTPprov.doGet(xtConnection.ConnectionParams,TxtServices.setwebtemplate,'template_name=' + Value.ToLower);
if (respo.StatusCode > 199)and(respo.StatusCode < 300) then
Begin
FwebAlias := respo.ContentAsString();
End
Else
Begin
raise Exception.Create('getWebAlias error [' + respo.StatusCode.ToString + ']: ' + respo.ContentAsString());
End;
if assigned(FonWebAliasChange) then
FonWebAliasChange(Self);
End;
end;
end.