source: cprs/branches/GUI-config/BDK32/SharedBrokerDebugger/uRpcLogEntry.pas@ 881

Last change on this file since 881 was 476, checked in by Kevin Toppenberg, 16 years ago

New WorldVistA Config Utility

File size: 11.2 KB
RevLine 
[476]1unit uRpcLogEntry;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, TRpcb;
8
9type
10 TDisplayFormat = (dfFormatFullWithoutClientName,dfFormatFullWithClientName,
11 dfFormatForList);
12
13 TMyString = class(TObject)
14 private
15 FString: String;
16 public
17 Constructor Create(Str: String);
18 procedure Append(Str: String);
19 function ToString: String;
20 end;
21
22 TRpcLogEntry = class(TObject)
23 private
24 mUniqueClientId: Integer;
25 mClientName: String;
26 mConnectionIndex: Integer;
27 mContext: String;
28 mUniqueId: Integer; // unique rpc id
29 mRpcName: String;
30 mRpcParamsString: String;
31 mRpcResults: String;
32 mRpcEndDateTime: Double;
33 mRpcDuration: Integer;
34 mRpcParams: TParams;
35 protected
36 procedure SetParamsString(Value: String);
37 public
38 Constructor Create; overload;
39 Constructor Create(uniqueClientId: Integer; clientName: String;
40 connectionIndex: Integer; rpcUniqueId: Integer; rpcEndDateTime: Double;
41 rpcDuration: Integer; context, rpcName, rpcParams, rpcResults: String); overload;
42 property StrResults: String read mRpcResults write mRpcResults;
43 property EndDateTime: double read mRpcEndDateTime write mRpcEndDateTime;
44 property Duration: Integer read mRpcDuration write mRpcDuration;
45 property Params: TParams read mRpcParams;
46 property UniqueClientId: Integer read mUniqueClientId write mUniqueClientId;
47 property ClientName: String read mClientName write mClientName;
48 property ConnectionIndex: Integer read mConnectionIndex write mConnectionIndex;
49 property UniqueId: Integer read mUniqueId write mUniqueId;
50 property Context: String read mContext write mContext;
51 property Name: String read mRpcName write mRpcName;
52 property ParamsString: String read mRpcParamsString write SetParamsString;
53 function CreateDisplayString(format: TDisplayFormat): String;
54 function ToString: String;
55 function CreateClipboardString: String;
56 function CreateParamsDisplayString: String;
57 function CreateResultsDisplayString: String;
58 end;
59
60
61const
62 kHeaderStartTag: String = '________________________RPC START____________________';
63 kRpcTag: String = 'RPC>'#09#09#09;
64 kRpcDebugIdTag: String = 'RPC DEBUG ID>'#09;
65 kClientNameTag: String = 'CLIENT NAME>'#09#09;
66 kClientDebugIdTag: String = 'CLIENT DEBUG ID>'#09;
67 kContextTag: String = 'CONTEXT>'#09#09;
68 kDurationTag: String = 'DURATION>'#09#09;
69 // kTimeDateTag: String = 'END TIME>'#09#09;
70 kParamsTag: String = '________________________PARAMS_______________________';
71 kResultsTag: String = '________________________RESULTS______________________';
72 kHeaderEndTag: String = '________________________RPC END______________________';
73
74function PosNext(SubString: String; CurStart: Integer; S: String): Integer;
75
76implementation
77
78function PosNext(SubString: string; CurStart: Integer; S: String): Integer;
79var
80 Str1: String;
81begin
82 Str1 := Copy(S,CurStart,Length(S));
83 Result := CurStart + Pos(SubString,Str1)-1;
84end;
85
86function TMyString.ToString: string;
87begin
88 Result := FString;
89end;
90
91procedure TMyString.Append(Str: string);
92begin
93 FString := FString + Str;
94end;
95
96constructor TMyString.Create(Str: string);
97begin
98 FString := Str;
99end;
100
101
102procedure TRpcLogEntry.SetParamsString(Value: string);
103begin
104 mRpcParamsString := value;
105 // TODO:
106 // now break the string into a string array and
107 // shove it into the Params
108 // Just rebuild the mParams
109 if (mRpcParams <> nil) then
110 begin
111 mRpcParams.Free;
112 mRpcParams := nil;
113 end;
114
115 mRpcParams := TParams.Create(Application);
116// mRpcParams.
117end;
118
119 /// <summary>
120 /// Summary description for RpcLogEntry.
121 /// </summary>
122Constructor TRpcLogEntry.Create;
123begin
124 inherited;
125end;
126
127Constructor TRpcLogEntry.Create(uniqueClientId: Integer; clientName: String;
128 connectionIndex: Integer; rpcUniqueId: Integer; rpcEndDateTime: Double;
129 rpcDuration: Integer; context, rpcName, rpcParams, rpcResults: String);
130begin
131 mUniqueClientId := uniqueClientId;
132 mClientName := clientName;
133 if (context = '') then
134 mContext := ''
135 else
136 mContext := context;
137
138 mConnectionIndex := connectionIndex;
139
140 mUniqueId := rpcUniqueId;
141 if (rpcName = '') then
142 mrpcName := ''
143 else
144 mrpcName := rpcName;
145
146 if(rpcParams = '') then
147 mrpcParamsString := ''
148 else
149 mrpcParamsString := rpcParams;
150
151 if(rpcResults = '') then
152 mrpcResults := ''
153 else
154 mrpcResults := rpcResults;
155
156 mRpcEndDateTime := rpcEndDateTime;
157 mRpcDuration := rpcDuration;
158end;
159
160
161function TRpcLogEntry.ToString: String;
162begin
163 Result := CreateDisplayString(dfFormatForList);
164end;
165
166 /// <summary>
167 /// CreateDisplayString returns a string with the rpc params
168 /// formated based on the DisplayFormat format
169 /// </summary>
170 /// <param name:='format'></param>
171 /// <returns></returns>
172 ///
173const
174 kInitialStringBuilderSize: Integer = 1000;
175 kNamePad: Integer = 31;
176 krpcIdPad: Integer = 5;
177 kcIdpad: Integer = 7;
178 kDurationPad: Integer = 3;
179 kLiteral: String = 'literal';
180 kReference: String = 'reference';
181 kList: String = 'list';
182 kUndefined: String = 'undefined';
183
184
185function TRpcLogEntry.CreateDisplayString(format: TDisplayFormat): String;
186var
187 ResultVal: TMyString;
188begin
189
190 ResultVal := TMyString.Create('');
191
192 case (format) of
193 dfFormatFullWithClientName:
194 begin
195 ResultVal.Append(kHeaderStartTag);
196 ResultVal.Append(#13#10 + kRpcTag + Name);
197 ResultVal.Append(#13#10 + kRpcDebugIdTag + IntToStr(UniqueId));
198 ResultVal.Append(#13#10 + kClientNameTag + ClientName);
199 ResultVal.Append(#13#10 + kClientDebugIdTag + IntToStr(UniqueClientId));
200 ResultVal.Append(#13#10 + kContextTag + Context);
201 ResultVal.Append(#13#10 + kDurationTag + IntToStr(Duration) + 'ms');
202 //ResultVal.Append(#13#10 + kTimeDateTag + EndDateTime);
203 ResultVal.Append(#13#10 + kParamsTag + CreateParamsDisplayString);
204 ResultVal.Append(#13#10 + kResultsTag + CreateResultsDisplayString);
205 ResultVal.Append(#13#10 + kHeaderEndTag);
206 end;
207 dfFormatForList:
208 begin
209// ResultVal.Append(Name+#09rpcId:='+UniqueId+#09cId:='+UniqueClientId+' time:='+Duration+'ms '+ClientName);
210{ if(Duration < 1)
211 durationStr := '<1'
212 else
213 durationStr := Duration.ToString();
214
215 ResultVal.Append( Name.PadRight(kNamePad)+
216 ' cId:='+UniqueClientId.ToString().PadRight(kcIdpad)+
217 ' time:='+duration.PadLeft(kDurationPad)+'ms'+
218 ' rpcId:='+UniqueId.ToString().PadRight(krpcIdPad)+
219 ClientName);
220}
221 end;
222 else
223 begin
224 ResultVal.Append(kHeaderStartTag);
225 ResultVal.Append(#13#10 + kRpcTag + Name);
226 ResultVal.Append(#13#10 + kRpcDebugIdTag + IntToStr(UniqueId));
227 //ResultVal.Append(#13#10 + kClientNameTag + ClientName);
228 //ResultVal.Append(#13#10 + kClientDebugIdTag + UniqueClientId);
229 ResultVal.Append(#13#10 + kContextTag + Context);
230 ResultVal.Append(#13#10 + kDurationTag + IntToStr(Duration) + 'ms');
231 //ResultVal.Append(#13#10 + kTimeDateTag + EndDateTime);
232 ResultVal.Append(#13#10 + kParamsTag + CreateParamsDisplayString());
233 ResultVal.Append(#13#10 + kResultsTag + CreateResultsDisplayString());
234 ResultVal.Append(#13#10 + kHeaderEndTag);
235 // Default case is FormatFullWithoutClientName
236 end;
237 end;
238 Result := ResultVal.ToString();
239end;
240
241function TRpcLogEntry.CreateClipboardString: String;
242var
243 ResultVal: TMyString;
244begin
245 ResultVal := TMyString.Create('');
246 ResultVal.Append(kHeaderStartTag);
247 ResultVal.Append(#13#10#13#10+kRpcTag+Name);
248 ResultVal.Append(#13#10+kRpcDebugIdTag+ IntToStr(UniqueId));
249 ResultVal.Append(#13#10+kClientNameTag+ClientName);
250 ResultVal.Append(#13#10+kClientDebugIdTag+ IntToStr(UniqueClientId));
251 ResultVal.Append(#13#10+kContextTag+Context);
252 ResultVal.Append(#13#10+kDurationTag+ IntToStr(Duration));
253 ResultVal.Append(#13#10#13#10+kParamsTag+#13#10);
254 ResultVal.Append(CreateParamsDisplayString);
255 ResultVal.Append(#13#10#13#10+kResultsTag+#13#10);
256 ResultVal.Append(CreateResultsDisplayString);
257 ResultVal.Append(#13#10#13#10+kHeaderEndTag+#13#10#13#10);
258 Result := ResultVal.ToString();
259end;
260
261// const char kSEP_FS = (char)28;
262const kSEP_GS: String = #29;
263const kSEP_US: String = #30;
264const kSEP_RS: String = #31;
265
266function TRpcLogEntry.CreateParamsDisplayString: String;
267var
268 Str: String;
269 Chr: Char;
270 Chr1: String;
271 TypeStr{, x, y}: String;
272 ResultVal: TMyString;
273 i, {j,} CurrStart: Integer;
274 LengthOfRpcParams: Integer;
275 EndOfSegment: Integer;
276 ARef, AVal: String;
277 Str2: String;
278begin
279 ResultVal := TMyString.Create('');
280 LengthOfRpcParams := Length(mRpcParamsString);
281 if LengthOfRpcParams > 0 then
282 begin
283 Str := mRpcParamsString;
284 CurrStart := 1;
285 i := 1;
286// for i:=0 to Pred(Params.Count) do
287 while CurrStart < LengthOfRpcParams do
288 begin
289 Chr1 := Copy(Str,CurrStart,1);
290 Chr := PChar(Chr1)^;
291 case Chr of //
292 'L': typeStr := kLiteral;
293 'R': typeStr := kReference;
294 'M': typeStr := kList;
295 else typeStr := kUndefined ;
296 end; // case
297 if i <> 1 then
298 ResultVal.Append(#13#10);
299 ResultVal.Append(TypeStr+#9);
300 CurrStart := CurrStart + 2;
301 if TypeStr = kList then
302 begin
303 EndOfSegment := 0;
304 while Copy(Str,CurrStart,1) <> kSep_GS do
305 begin
306 EndOfSegment := PosNext(kSep_US,CurrStart,Str);
307 ARef := Copy(Str,CurrStart,EndOfSegment-CurrStart);
308 CurrStart := EndOfSegment + 1;
309 EndOfSegment := PosNext(kSep_RS,CurrStart,Str);
310 AVal := Copy(Str,CurrStart,EndOfSegment-CurrStart);
311 CurrStart := EndOfSegment + 1;
312 ResultVal.Append(#13#10#9+ARef+#9+AVal);
313 Str2 := #13#10#9+Aref+#9+Aval;
314 Aval := Str2;
315 end; // while
316 if EndOfSegment = 0 then
317 EndOfSegment := PosNext(kSep_GS,CurrStart,Str);
318 CurrStart := EndOfSegment + 1;
319 end
320 else
321 begin
322 EndOfSegment := PosNext(kSEP_GS,CurrStart,Str);
323 ResultVal.Append(Copy(Str,CurrStart,EndOfSegment-CurrStart));
324 CurrStart := EndOfSegment + 1;
325 end;
326 Inc(i);
327 end; // while
328 end;
329{
330 else
331 Assert(False);
332}
333{
334 if (i<>0) then
335 ResultVal.Append(#13#10);
336 ResultVal.Append(typeStr+#09+Params[i].Value);
337 if (Params[i].PType = List) then
338 begin
339 for j:=0 to Pred(Params[i].Mult.Count) do
340 begin
341 x := Params[i].Mult.Subscript(j);
342 y := Params[i].Mult[x];
343 ResultVal.Append(#13#10#09+'('+x+'):='+y);
344 end
345 end
346 end;
347}
348 Result := ResultVal.ToString;
349end;
350
351function TRpcLogEntry.CreateResultsDisplayString: String;
352begin
353 Result := StrResults;
354end;
355
356end.
Note: See TracBrowser for help on using the repository browser.