-
Notifications
You must be signed in to change notification settings - Fork 0
/
caseGenerator_trace_mobile_account.pas
202 lines (174 loc) · 6.3 KB
/
caseGenerator_trace_mobile_account.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
unit caseGenerator_trace_mobile_account;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.DateTimeCtrls, FMX.Calendar, FMX.Edit, FMX.StdCtrls, FMX.Layouts,
FMX.ListBox, FMX.Controls.Presentation, caseGenerator_util;
type
TformTraceMobileAccount = class(TForm)
Label1: TLabel;
lbPhoneAccount: TListBox;
edMSISDN: TEdit;
btnClose: TButton;
btnAddPhoneAccount: TButton;
btnDeletePhoneAccount: TButton;
btnCancel: TButton;
btnModifyTrace: TButton;
Label2: TLabel;
procedure btnAddPhoneAccountClick(Sender: TObject);
procedure btnDeletePhoneAccountClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnModifyTraceClick(Sender: TObject);
procedure lbPhoneAccountChange(Sender: TObject);
private
FuuidCase: string;
FpathCase: String;
procedure SetuuidCase(const Value: string);
procedure SetpathCase(const Value: String);
property uuidCase: string read FuuidCase write SetuuidCase;
property pathCase: String read FpathCase write SetpathCase;
function prepareTrace(operation: String): String;
{ Private declarations }
public
procedure ShowWithParamater(pathCase: String; uuidCase: String);
{ Public declarations }
end;
var
formTraceMobileAccount: TformTraceMobileAccount;
implementation
{$R *.fmx}
uses StrUtils;
{ TForm1 }
procedure TformTraceMobileAccount.btnDeletePhoneAccountClick(Sender: TObject);
begin
lbPhoneAccount.Items.Delete(lbPhoneAccount.ItemIndex);
end;
procedure TformTraceMobileAccount.btnModifyTraceClick(Sender: TObject);
begin
if lbPhoneAccount.ItemIndex > - 1 then
lbPhoneAccount.Items[lbPhoneAccount.ItemIndex] := prepareTrace('modify');
end;
procedure TformTraceMobileAccount.lbPhoneAccountChange(Sender: TObject);
begin
if lbPhoneAccount.ItemIndex > - 1 then
edMSISDN.Text := ExtractField(lbPhoneAccount.Items[lbPhoneAccount.ItemIndex], '"MSISDN":"');
end;
function TformTraceMobileAccount.prepareTrace(operation: String): String;
var
line, recSep, indent, guidNoBraces: string;
Uid: TGUID;
idx: Integer;
begin
recSep := #30 + #30; // record separator, not printable
indent := ' ';
if (Trim(edMSISDN.Text) = '') then
ShowMessage('MSISDN number is missing!')
else
begin
line := '{';
if operation = 'add' then
begin
CreateGUID(Uid);
guidNoBraces := 'kb:' + Copy(GuidToString(Uid), 2, Length(GuidToString(Uid)) - 2);
end
else
guidNoBraces := ExtractField(lbPhoneAccount.Items[lbPhoneAccount.ItemIndex], '"@id":"');
line := line + indent + '"@id":"' + guidNoBraces + '", ' + recSep;
line := line + indent + '"@type":"Trace", ' + recSep;
line := line + indent + '"propertyBundle":[' + recSep;
line := line + indent + '{' + recSep;
line := line + RepeatString(indent, 2) + '"@id":"' + guidNoBraces + '-Account", ' + recSep;
line := line + RepeatString(indent, 2) + '"@type":"Account", ' + recSep;
line := line + RepeatString(indent, 2) + '"accountType":"PhoneAccount", ' + recSep;
line := line + RepeatString(indent, 2) + '"isActive":"true"' + recSep;
line := line + indent + '},' + recSep;
line := line + indent + '{' + recSep;
line := line + RepeatString(indent, 2) + '"@id":"' + guidNoBraces + '-MobileAccount", ' + recSep;
line := line + RepeatString(indent, 2) + '"@type":"MobileAccount", ' + recSep;
line := line + RepeatString(indent, 2) + '"MSISDN":"' + edMSISDN.Text + '"' + recSep;
line := line + indent + '}' + recSep;
line := line + ']}';
end;
Result := line;
end;
procedure TformTraceMobileAccount.btnCancelClick(Sender: TObject);
begin
formTraceMobileAccount.Close;
end;
procedure TformTraceMobileAccount.btnCloseClick(Sender: TObject);
var
fileJSON: TextFile;
line:string;
idx: integer;
begin
//dir := GetCurrentDir;
// create file JSON uuidCase-phone_account.json
AssignFile(fileJSON, FpathCase + FuuidCase + '-traceMOBILE_ACCOUNT.json');
if lbPhoneAccount.Items.Count > 0 then
begin
idx := 0;
Rewrite(fileJSON); // create new file
WriteLn(fileJSON, '{');
line := #9 + '"OBJECTS_MOBILE_ACCOUNT":[';
WriteLn(fileJSON, line);
for idx:= 0 to lbPhoneAccount.Items.Count - 2 do
WriteLn(fileJSON, #9#9 + lbPhoneAccount.Items[idx] + ',');
WriteLn(fileJSON, #9#9 + lbPhoneAccount.Items[idx]);
line := ' ]\}';
WriteLn(fileJSON, #9#9 + ']');
Write(fileJSON,'}');
CloseFile(fileJSON);
end
else
deleteFile(FpathCase + FuuidCase + '-traceMOBILE_ACCOUNT.json');
formTraceMobileAccount.Close;
end;
procedure TformTraceMobileAccount.btnAddPhoneAccountClick(Sender: TObject);
begin
lbPhoneAccount.Items.Add(prepareTrace('add'));
edMSISDN.Text := '';
end;
procedure TformTraceMobileAccount.SetpathCase(const Value: String);
begin
FpathCase := Value;
end;
procedure TformTraceMobileAccount.SetuuidCase(const Value: string);
begin
FuuidCase := Value;
end;
procedure TformTraceMobileAccount.ShowWithParamater(pathCase: String; uuidCase: String);
var
fileJSON: TextFile;
line, subLine:string;
begin
SetUuidCase(uuidCase);
SetPathCase(pathCase);
//dir := GetCurrentDir;
// read file JSON uuidCase-tracePHONE_ACCOUNT.json
if FileExists(FpathCase + FuuidCase + '-traceMOBILE_ACCOUNT.json') then
begin
AssignFile(fileJSON, FpathCase + FuuidCase + '-traceMOBILE_ACCOUNT.json');
Reset(fileJSON);
lbPhoneAccount.Items.Clear;
while not Eof(fileJSON) do
begin
ReadLn(fileJSON, line);
line := Trim(line);
if (line = '{') or (line = '}') or (line = ']') or (AnsiContainsStr(line, 'OBJECTS_')) then // first or last line or root element
else
begin
subLine := Copy(line, Length(line), 1); // rule out of comma
if subLine = ',' then
line := Copy(line, 1, Length(line) - 1);
lbPhoneAccount.Items.Add(line);
end;
end;
CloseFile(fileJSON);
end;
// else
// ShowMessage(dir + uuidCase + '-identity.json' + ' doesn''t exist');
formTraceMobileAccount.ShowModal;
end;
end.