-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyperAreaBase.cs
631 lines (593 loc) · 21.6 KB
/
HyperAreaBase.cs
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
using Gurock.SmartInspect;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text.Json;
namespace SmartLogger
{
public class HyperArea : HyperAreaBase
{
public HyperArea(SmartInspect parent, Area area) : base(parent, area)
{
}
}
public class HyperAreaBase
{
Session _session;
bool _traceable;
public HyperAreaBase(SmartInspect parent, Area area)
{
_session = new Session(parent, area.Name);
UpdateFromArea(area);
}
public void UpdateFromArea(Area area)
{
_session.Color = ColorStringToColor(area.AreaColor);
}
public HyperAreaBase(Session session)
{
_session = session;
}
public string Name { get { return _session.Name; } }
public Session SiSession { get { return _session; } }
public bool IsInfoEnabled { get { return _session.IsOn(Gurock.SmartInspect.Level.Message); } }
public void SetSessionLevel(Level loggerLevel, Level detailLevel)
{
Bootstrap.Log.LogColored(Color.PaleGreen, $"! Session [{_session.Name}] Log: {loggerLevel.ToString()} Detail: {detailLevel.ToString()}");
_session.Active = true; // IsEnabled(loggerLevel) || IsEnabled(detailLevel);
_session.Level = Gurock.SmartInspect.Level.Debug; // XlatLevel(loggerLevel);
//_traceable = IsTraceable(loggerLevel) || IsTraceable(detailLevel);
//if (IsEnabled(detailLevel) && !_session.IsOn(XlatLevel(detailLevel)))
//{
// _session.Level = XlatLevel(detailLevel);
//}
Bootstrap.Log.LogColored(Color.LightCyan, $"! Session [{_session.Name}] Active: {_session.Active.ToString()} Level: {_session.Level.ToString()}");
}
public static Color ColorStringToColor(string colorString)
{
try
{
#if NETFRAMEWORK
return ColorTranslator.FromHtml(colorString);
#else
return Color.FromName(colorString);
#endif
}
catch
{
return Color.Black; // indicates unknown color designation
}
}
public static Gurock.SmartInspect.Level XlatLevel(Level level)
{
switch (level)
{
case Level.Trace:
{ return Gurock.SmartInspect.Level.Debug; }
case Level.Debug:
{ return Gurock.SmartInspect.Level.Debug; }
case Level.Verbose:
{ return Gurock.SmartInspect.Level.Verbose; }
case Level.Info:
{ return Gurock.SmartInspect.Level.Message; }
case Level.Message:
{ return Gurock.SmartInspect.Level.Message; }
case Level.Warning:
{ return Gurock.SmartInspect.Level.Warning; }
case Level.Warn:
{ return Gurock.SmartInspect.Level.Warning; }
case Level.Error:
{ return Gurock.SmartInspect.Level.Error; }
case Level.Fatal:
{ return Gurock.SmartInspect.Level.Fatal; }
case Level.Control:
{ return Gurock.SmartInspect.Level.Control; }
case Level.Off:
{ return Gurock.SmartInspect.Level.Debug; }
case Level.Standby:
{ return Gurock.SmartInspect.Level.Debug; }
}
return Gurock.SmartInspect.Level.Debug;
}
private static bool IsEnabled(Level level)
{
return !((level == Level.Off) || (level == Level.Standby));
}
private static bool IsTraceable(Level level)
{
return (level == Level.Trace);
}
public void ClearAll()
{
_session.ClearAll();
}
public void Log(string label, string value, Level level = Level.Debug)
{
_session.LogString(XlatLevel(level), label, value);
}
public void LogString(string label, string value, Level level = Level.Debug)
{
_session.LogString(XlatLevel(level), label, value);
}
public void Log(string label, int value, Level level = Level.Debug)
{
_session.LogInt(XlatLevel(level), label, value);
}
public void LogInt(string label, int value, Level level = Level.Debug)
{
_session.LogInt(XlatLevel(level), label, value);
}
public void Log(string label, bool value, Level level = Level.Debug)
{
_session.LogBool(XlatLevel(level), label, value);
}
public void LogBool(string label, bool value, Level level = Level.Debug)
{
_session.LogBool(XlatLevel(level), label, value);
}
public void Log(string label, byte value, Level level = Level.Debug)
{
_session.LogByte(XlatLevel(level), label, value);
}
public void LogByte(string label, byte value, Level level = Level.Debug)
{
_session.LogByte(XlatLevel(level), label, value);
}
public void Log(string label, long value, Level level = Level.Debug)
{
_session.LogLong(XlatLevel(level), label, value);
}
public void LogLong(string label, long value, Level level = Level.Debug)
{
_session.LogLong(XlatLevel(level), label, value);
}
public void Log(string label, DateTime value, Level level = Level.Debug)
{
_session.LogDateTime(XlatLevel(level), label, value);
}
public void LogDateTime(string label, DateTime value, Level level = Level.Debug)
{
_session.LogDateTime(XlatLevel(level), label, value);
}
public void Log(string label, char value, Level level = Level.Debug)
{
_session.LogChar(XlatLevel(level), label, value);
}
public void LogChar(string label, char value, Level level = Level.Debug)
{
_session.LogChar(XlatLevel(level), label, value);
}
public void Log(string label, float value, Level level = Level.Debug)
{
_session.LogFloat(XlatLevel(level), label, value);
}
public void LogFloat(string label, float value, Level level = Level.Debug)
{
_session.LogFloat(XlatLevel(level), label, value);
}
public void Log(string label, double value, Level level = Level.Debug)
{
_session.LogDouble(XlatLevel(level), label, value);
}
public void LogDouble(string label, double value, Level level = Level.Debug)
{
_session.LogDouble(XlatLevel(level), label, value);
}
public void Log(string label, short value, Level level = Level.Debug)
{
_session.LogShort(XlatLevel(level), label, value);
}
public void LogShort(string label, short value, Level level = Level.Debug)
{
_session.LogShort(XlatLevel(level), label, value);
}
public void LogDebug(string msg)
{
_session.LogDebug(msg);
}
public void Debug(string msg)
{
Bootstrap.Log.LogColored(Color.LightCyan, $"! {msg}");
_session.LogDebug(msg);
}
public void Verbose(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Verbose, color, msg);
}
public void Verbose(string msg)
{
_session.LogVerbose(msg);
}
public void Debug(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Debug, color, msg);
}
public void DebugEx(string msg, Color color, SmartLogger.Level level= SmartLogger.Level.Debug)
{
_session.LogColored(XlatLevel(level), color, msg);
}
public void Trace(string msg)
{
if (_traceable)
{
_session.LogDebug(msg);
}
}
public void LogTrace(string msg)
{
if (_traceable)
{
_session.LogDebug(msg);
}
}
public void Error(string msg)
{
_session.LogError(msg);
}
public void LogError(string msg)
{
_session.LogError(msg);
}
public void Error(Exception e, string msg = "")
{
if (_session.IsOn(Gurock.SmartInspect.Level.Error))
{
_session.LogException(msg, e);
}
}
public void SoftException(Exception e, string msg = "", Level level = Level.Debug)
{
if (_session.IsOn(XlatLevel(level)))
{
_session.LogException(msg, e);
}
}
public void Warn(Exception e, string msg = "")
{
if (_session.IsOn(Gurock.SmartInspect.Level.Warning))
{
_session.LogException(msg, e);
}
}
public void Info(Exception e, string msg = "")
{
if (_session.IsOn(Gurock.SmartInspect.Level.Message))
{
_session.LogException(msg, e);
}
}
//public void Info(string format, string key, string value)
//{
// string s;
// s = format.Replace("{key}", "{0}");
// s = s.Replace("{value}", "{1}");
// try
// {
// _session.LogMessage(string.Format(s, key, value));
// }
// catch (Exception ex)
// {
// _session.LogError($"{format} is not a supported format string, but this is your Key: {key}, Value: {value} pairing.");
// }
//}
//public void Info(string format, string key, object value)
//{
// Info(format, key, value.ToString());
//}
public void Warn(string msg)
{
_session.LogWarning(msg);
}
public void Warning(string msg)
{
_session.LogWarning(msg);
}
public void LogWarning(string msg)
{
_session.LogWarning(msg);
}
public void Message(string msg)
{
_session.LogMessage(msg);
}
public void Info(string msg)
{
_session.LogMessage(msg);
}
public void Fatal(string msg)
{
_session.LogFatal(msg);
}
public void Fatal(Exception e, string msg = "")
{
_session.LogException(msg, e);
}
public void Exception(Exception e, string msg = "")
{
_session.LogException(msg, e);
}
public void Trace(string msg, Color color)
{
if (_traceable)
{
_session.LogColored(Gurock.SmartInspect.Level.Debug, color, msg);
}
}
public void Message(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Message, color, msg);
}
public void Info(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Message, color, msg);
}
public void Warn(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Warning, color, msg);
}
public void Warning(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Warning, color, msg);
}
public void Error(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Error, color, msg);
}
public void Fatal(string msg, Color color)
{
_session.LogColored(Gurock.SmartInspect.Level.Fatal, color, msg);
}
public void LogSource(string msg, string source, ViewerId id, Level level = Level.Debug)
{
_session.LogCustomText(XlatLevel(level), msg, source, LogEntryType.Source, id);
}
public void Python(string msg, string source, Level level = Level.Debug)
{
LogSource(msg, source, ViewerId.PythonSource, level);
}
public void XML(string msg, string source, Level level = Level.Debug)
{
LogSource(msg, source, ViewerId.XmlSource, level);
}
public void Text(string msg, string source, Level level = Level.Debug)
{
_session.LogText(XlatLevel(level), msg, source);
}
public void Binary(string msg, byte[] source, Level level = Level.Debug)
{
_session.LogBinary(XlatLevel(level), msg, source);
}
public void DataTable(string msg, DataTable source, Level level = Level.Debug)
{
_session.LogDataTable(XlatLevel(level), msg, source);
}
public void JSON(string msg, string source, Level level = Level.Debug)
{
if (_session.IsOn(XlatLevel(level)))
{
// Parse and then re-serialize with indentation using System.Text.Json
var options = new JsonSerializerOptions
{
WriteIndented = true
};
var parsedJson = JsonSerializer.Deserialize<JsonElement>(source);
var beautified = JsonSerializer.Serialize(parsedJson, options);
_session.LogSource(XlatLevel(level), msg, beautified, SourceId.JavaScript);
}
}
public void Strings(string msg, IEnumerable<string> list, Level level = Level.Debug)
{
if (_session.IsOn(XlatLevel(level)))
{
var count = 0;
ListViewerContext ctx = new ListViewerContext();
try
{
foreach (string s in list)
{
count++;
ctx.AppendLine(s);
}
_session.LogCustomContext(XlatLevel(level), $"{msg}({count})", LogEntryType.Text, ctx);
}
finally
{
ctx.Dispose();
}
}
}
public void Separator(Level level = Level.Debug)
{
if (_session.IsOn(XlatLevel(level)))
{
_session.LogSeparator();
}
}
private string FancyFormat(string format, params object[] args)
{
string[] chunks = format.Split('{');
//Bootstrap.Log.LogString("Format String", format);
//Bootstrap.Log.LogInt("Word count", chunks.Length);
string result = "";
string property;
string remainder;
string working;
int counter = 0;
int argCounter = 0;
int index;
if (chunks.Length > 0)
{
foreach (string chunk in chunks)
{
if (counter == 0)
{
result = chunks[counter];
}
else
{
//Bootstrap.Log.LogDebug($"Argument {counter}:{args[counter - 1].ToString()}");
if (args[argCounter] != null)
{
result += args[argCounter].ToString();
}
else
{
result += "null";
}
argCounter++;
working = chunks[counter];
//Bootstrap.Log.LogDebug($"Working {counter}:{working}");
index = working.IndexOf('}');
//Bootstrap.Log.LogInt("Index", index);
//Bootstrap.Log.LogInt("Length", working.Length);
property = working.Substring(0, index - 1);
if (index < working.Length - 1)
{
index++;
remainder = working.Substring(index, working.Length - index);
//Bootstrap.Log.LogDebug($"{property}:{remainder}");
result += remainder;
}
}
//Bootstrap.Log.LogDebug($"{counter}:{result}");
counter++;
}
}
while (argCounter < args.Length)
{
result += ": ";
if (args[argCounter] != null)
{
result += args[argCounter].ToString();
}
else
{
result += "null";
}
argCounter++;
}
return result;
}
public void Debug(string format, params object[] args)
{
_session.LogMessage(FancyFormat(format, args));
}
public void Info(string format, params object[] args)
{
_session.LogMessage(FancyFormat(format, args));
}
public void Warn(string format, params object[] args)
{
_session.LogMessage(FancyFormat(format, args));
}
public void Error(string format, params object[] args)
{
_session.LogMessage(FancyFormat(format, args));
}
public void Error(Exception e, string format, params object[] args)
{
_session.LogException(FancyFormat(format, args), e);
}
public void Watch(string label, string value, Level level = Level.Debug)
{
_session.WatchString(XlatLevel(level), label, value);
}
public void WatchString(string label, string value, Level level = Level.Debug)
{
_session.WatchString(XlatLevel(level), label, value);
}
public void Watch(string label, int value, Level level = Level.Debug)
{
_session.WatchInt(XlatLevel(level), label, value);
}
public void WatchInt(string label, int value, Level level = Level.Debug)
{
_session.WatchInt(XlatLevel(level), label, value);
}
public void Watch(string label, bool value, Level level = Level.Debug)
{
_session.WatchBool(XlatLevel(level), label, value);
}
public void WatchBool(string label, bool value, Level level = Level.Debug)
{
_session.WatchBool(XlatLevel(level), label, value);
}
public void Watch(string label, byte value, Level level = Level.Debug)
{
_session.WatchByte(XlatLevel(level), label, value);
}
public void WatchByte(string label, byte value, Level level = Level.Debug)
{
_session.WatchByte(XlatLevel(level), label, value);
}
public void Watch(string label, long value, Level level = Level.Debug)
{
_session.WatchLong(XlatLevel(level), label, value);
}
public void WatchLong(string label, long value, Level level = Level.Debug)
{
_session.WatchLong(XlatLevel(level), label, value);
}
public void Watch(string label, DateTime value, Level level = Level.Debug)
{
_session.WatchDateTime(XlatLevel(level), label, value);
}
public void WatchDateTime(string label, DateTime value, Level level = Level.Debug)
{
_session.WatchDateTime(XlatLevel(level), label, value);
}
public void Watch(string label, char value, Level level = Level.Debug)
{
_session.WatchChar(XlatLevel(level), label, value);
}
public void WatchChar(string label, char value, Level level = Level.Debug)
{
_session.WatchChar(XlatLevel(level), label, value);
}
public void Watch(string label, float value, Level level = Level.Debug)
{
_session.WatchFloat(XlatLevel(level), label, value);
}
public void WatchFloat(string label, float value, Level level = Level.Debug)
{
_session.WatchFloat(XlatLevel(level), label, value);
}
public void Watch(string label, double value, Level level = Level.Debug)
{
_session.WatchDouble(XlatLevel(level), label, value);
}
public void WatchDouble(string label, double value, Level level = Level.Debug)
{
_session.WatchDouble(XlatLevel(level), label, value);
}
public void Watch(string label, short value, Level level = Level.Debug)
{
_session.WatchShort(XlatLevel(level), label, value);
}
public void WatchShort(string label, short value, Level level = Level.Debug)
{
_session.WatchShort(XlatLevel(level), label, value);
}
public void ClearWatches()
{
_session.ClearWatches();
}
public void ClearLog()
{
_session.ClearLog();
}
public void StackTrace(string label, Level level = Level.Debug)
{
_session.LogCurrentStackTrace(XlatLevel(level), label);
}
public void EnterMethod(string method, Level level = Level.Debug)
{
_session.EnterMethod(XlatLevel(level), method);
}
public void LeaveMethod(string method, Level level = Level.Debug)
{
_session.LeaveMethod(XlatLevel(level), method);
}
}
}