-
Notifications
You must be signed in to change notification settings - Fork 24
/
Cromis.MVC.Common.pas
361 lines (304 loc) · 9.8 KB
/
Cromis.MVC.Common.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
unit Cromis.MVC.Common;
interface
uses
SysUtils, Classes, IniFiles,
// cromis units
Cromis.AnyValue;
const
cMIME = 'MIME';
type
TDispatchResult = (drSuccess, drDoLogin, drRedirectToLogin, drForbiden, drFailed);
ISessionContent = Interface(IInterface)
['{0C2C2ADE-4B0D-4150-B2E0-51901492AECC}']
function GetData: TStream;
function GetEncoding: string;
function GetHTMLRoot: string;
function GetExitCode: Cardinal;
procedure SetHTMLRoot(const Value: string);
procedure SetEncoding(const Value: string);
procedure SetExitCode(const Value: Cardinal);
property ExitCode: Cardinal read GetExitCode write SetExitCode;
property HTMLRoot: string read GetHTMLRoot write SetHTMLRoot;
property Encoding: string read GetEncoding write SetEncoding;
property Data: TStream read GetData;
procedure Clear;
end;
ISessionData = Interface(IInterface)
['{9C3CC7B7-B853-4D50-BBC2-F36051335F12}']
function GetID: string;
function GetValues: IValueList;
function GetAuthenticated: Boolean;
function GetSessionContent: ISessionContent;
function GetDispatchResult: TDispatchResult;
procedure SetAuthenticated(const Value: Boolean);
procedure SetDispatchResult(const Value: TDispatchResult);
property DispatchResult: TDispatchResult read GetDispatchResult write SetDispatchResult;
property Authenticated: Boolean read GetAuthenticated write SetAuthenticated;
property SessionContent: ISessionContent read GetSessionContent;
property Values: IValueList read GetValues;
property ID: string read GetID;
end;
IMVCData = Interface(IInterface)
['{9C61B770-FC1B-4BDF-ACE1-F735D758B0FF}']
function GetValues: IValueList;
function GetActiveOnly: Boolean;
function GetParameters: IValueList;
function GetUpdateViews: Boolean;
procedure SetActiveOnly(const Value: Boolean);
procedure SetUpdateViews(const Value: Boolean);
property UpdateViews: Boolean read GetUpdateViews write SetUpdateViews;
property ActiveOnly: Boolean read GetActiveOnly write SetActiveOnly;
property Parameters: IValueList read GetParameters;
property Values: IValueList read GetValues;
end;
IMVCObserver = Interface(IInterface)
['{633D8A96-AC42-489C-8E10-A387113EBB29}']
procedure UpdateView(const Section, ID: string; const Data: IMVCData);
function IsActive: Boolean;
end;
IMimeTypes = Interface(IInterface)
['{43C821F4-4499-4698-A3F2-32AA83EFC4D1}']
function GetMime(const Ext: string): string;
procedure SetMime(const Ext: string; const Value: string);
property Mime[const Ext: string]: string read GetMime write SetMime;
end;
// acquire different datafunctions
function AcquireSessionData(const SessionID: string): ISessionData;
function AcquireMimeTypes: IMimeTypes;
function AcquireMVCData: IMVCData;
implementation
type
TSessionContent = class(TInterfacedObject, ISessionContent)
private
FEncoding: string;
FHTMLRoot: string;
FExitCode: Cardinal;
FData: TMemoryStream;
function GetData: TStream;
function GetEncoding: string;
function GetHTMLRoot: string;
function GetExitCode: Cardinal;
procedure SetHTMLRoot(const Value: string);
procedure SetEncoding(const Value: string);
procedure SetExitCode(const Value: Cardinal);
public
constructor Create;
destructor Destroy; override;
property ExitCode: Cardinal read GetExitCode write SetExitCode;
property HTMLRoot: string read GetHTMLRoot write SetHTMLRoot;
property Encoding: string read GetEncoding write SetEncoding;
property Data: TStream read GetData;
procedure Clear;
end;
TSessionData = class(TInterfacedObject, ISessionData)
private
FID: string;
FValues: IValueList;
FAuthenticated: Boolean;
FSessionContent: ISessionContent;
FDispatchResult: TDispatchResult;
function GetID: string;
function GetValues: IValueList;
function GetAuthenticated: Boolean;
function GetDispatchResult: TDispatchResult;
function GetSessionContent: ISessionContent;
procedure SetAuthenticated(const Value: Boolean);
procedure SetDispatchResult(const Value: TDispatchResult);
public
constructor Create(const ID: string);
property DispatchResult: TDispatchResult read GetDispatchResult write SetDispatchResult;
property Authenticated: Boolean read GetAuthenticated write SetAuthenticated;
property SessionContent: ISessionContent read GetSessionContent;
property Values: IValueList read GetValues;
property ID: string read GetID;
end;
TMVCData = class(TInterfacedObject, IMVCData)
private
FValues: IValueList;
FParameters: IValueList;
FActiveOnly: Boolean;
FUpdateViews: Boolean;
function GetValues: IValueList;
function GetActiveOnly: Boolean;
function GetParameters: IValueList;
function GetUpdateViews: Boolean;
procedure SetActiveOnly(const Value: Boolean);
procedure SetUpdateViews(const Value: Boolean);
public
constructor Create;
property Values: IValueList read GetValues;
property Parameters: IValueList read GetParameters;
property ActiveOnly: Boolean read GetActiveOnly write SetActiveOnly;
property UpdateViews: Boolean read GetUpdateViews write SetUpdateViews;
end;
TMimeTypes = class(TInterfacedObject, IMimeTypes)
private
FMimeTypes: TMemIniFile;
function GetMime(const Ext: string): string;
procedure SetMime(const Ext: string; const Value: string);
public
constructor Create;
destructor Destroy; override;
property Mime[const Ext: string]: string read GetMime write SetMime;
end;
var
MimeTypes: IMimeTypes;
function AcquireMVCData: IMVCData;
begin
Result := TMVCData.Create;
end;
function AcquireMimeTypes: IMimeTypes;
begin
if MimeTypes = nil then
MimeTypes := TMimeTypes.Create;
Result := MimeTypes;
end;
function AcquireSessionData(const SessionID: string): ISessionData;
begin
Result := TSessionData.Create(SessionID);
end;
{ TMVCData }
constructor TMVCData.Create;
begin
FParameters := AcquireValueList;
FValues := AcquireValueList;
FUpdateViews := True;
FActiveOnly := False;
end;
function TMVCData.GetUpdateViews: Boolean;
begin
Result := FUpdateViews;
end;
function TMVCData.GetValues: IValueList;
begin
Result := FValues;
end;
function TMVCData.GetActiveOnly: Boolean;
begin
Result := FActiveOnly;
end;
function TMVCData.GetParameters: IValueList;
begin
Result := FParameters;
end;
procedure TMVCData.SetUpdateViews(const Value: Boolean);
begin
FUpdateViews := Value;
end;
procedure TMVCData.SetActiveOnly(const Value: Boolean);
begin
FActiveOnly := Value;
end;
{ TSessionData }
constructor TSessionData.Create(const ID: string);
begin
FSessionContent := TSessionContent.Create;
FValues := AcquireValueList;
FID := ID;
end;
function TSessionData.GetValues: IValueList;
begin
Result := FValues;
end;
function TSessionData.GetAuthenticated: Boolean;
begin
Result := FAuthenticated;
end;
function TSessionData.GetDispatchResult: TDispatchResult;
begin
Result := FDispatchResult;
end;
procedure TSessionData.SetAuthenticated(const Value: Boolean);
begin
FAuthenticated := Value;
end;
procedure TSessionData.SetDispatchResult(const Value: TDispatchResult);
begin
FDispatchResult := Value;
end;
function TSessionData.GetID: string;
begin
Result := FID;
end;
function TSessionData.GetSessionContent: ISessionContent;
begin
Result := FSessionContent;
end;
{ TSessionContent }
procedure TSessionContent.Clear;
begin
FEncoding := '';
FData.Clear;
end;
constructor TSessionContent.Create;
begin
FData := TMemoryStream.Create;
end;
destructor TSessionContent.Destroy;
begin
FreeAndNil(FData);
inherited;
end;
function TSessionContent.GetData: TStream;
begin
Result := FData;
end;
function TSessionContent.GetEncoding: string;
begin
Result := FEncoding;
end;
function TSessionContent.GetExitCode: Cardinal;
begin
Result := FExitCode;
end;
function TSessionContent.GetHTMLRoot: string;
begin
Result := FHTMLRoot;
end;
procedure TSessionContent.SetEncoding(const Value: string);
begin
FEncoding := Value;
end;
procedure TSessionContent.SetExitCode(const Value: Cardinal);
begin
FExitCode := Value;
end;
procedure TSessionContent.SetHTMLRoot(const Value: string);
begin
FHTMLRoot := Value;
end;
{ TMimeTypes }
constructor TMimeTypes.Create;
begin
FMimeTypes := TMemIniFile.Create('');
FMimeTypes.WriteString(cMIME, 'TXT', 'text/plain');
FMimeTypes.WriteString(cMIME, 'HTM', 'text/html');
FMimeTypes.WriteString(cMIME, 'HTML', 'text/html');
FMimeTypes.WriteString(cMIME, 'BMP', 'image/x-ms-bmp');
FMimeTypes.WriteString(cMIME, 'JPG', 'image/jpeg');
FMimeTypes.WriteString(cMIME, 'JPEG', 'image/jpeg');
FMimeTypes.WriteString(cMIME, 'JPE', 'image/jpeg');
FMimeTypes.WriteString(cMIME, 'IEF', 'image/ief');
FMimeTypes.WriteString(cMIME, 'TIF', 'image/tiff');
FMimeTypes.WriteString(cMIME, 'TIFF', 'image/tiff');
FMimeTypes.WriteString(cMIME, 'PNG', 'image/x-png');
FMimeTypes.WriteString(cMIME, 'GIF', 'image/gif');
FMimeTypes.WriteString(cMIME, 'CSS', 'text/css');
FMimeTypes.WriteString(cMIME, 'JS', 'text/javascript');
FMimeTypes.WriteString(cMIME, 'LS', 'text/javascript');
FMimeTypes.WriteString(cMIME, 'MOCHA', 'text/javascript');
end;
destructor TMimeTypes.Destroy;
begin
FreeAndNil(FMimeTypes);
inherited;
end;
function TMimeTypes.GetMime(const Ext: string): string;
begin
Result := FMimeTypes.ReadString(cMIME, Ext, '');
end;
procedure TMimeTypes.SetMime(const Ext, Value: string);
begin
FMimeTypes.WriteString(cMIME, Ext, Value);
end;
end.