Skip to content

Commit 3124a49

Browse files
committed
Reverted some changes to the console app :)
1 parent 2ca8ee9 commit 3124a49

File tree

1 file changed

+29
-57
lines changed

1 file changed

+29
-57
lines changed

src/Samples/Exceptionless.SampleConsole/Program.cs

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ namespace Exceptionless.SampleConsole {
2929
public class Program {
3030
private static readonly int[] _delays = { 0, 50, 100, 1000 };
3131
private static int _delayIndex = 2;
32-
33-
private static readonly InMemoryExceptionlessLog _log = new InMemoryExceptionlessLog {
34-
MinimumLogLevel = LogLevel.Info
35-
};
36-
32+
private static readonly InMemoryExceptionlessLog _log = new InMemoryExceptionlessLog { MinimumLogLevel = LogLevel.Info };
3733
private static readonly object _writeLock = new object();
3834

39-
private static readonly TimeSpan[] _dateSpans = { TimeSpan.Zero, TimeSpan.FromMinutes(5), TimeSpan.FromHours(1), TimeSpan.FromDays(1), TimeSpan.FromDays(7), TimeSpan.FromDays(TimeSpanExtensions.AvgDaysInAMonth), TimeSpan.FromDays(TimeSpanExtensions.AvgDaysInAMonth * 3) };
40-
35+
private static readonly TimeSpan[] _dateSpans = {
36+
TimeSpan.Zero,
37+
TimeSpan.FromMinutes(5),
38+
TimeSpan.FromHours(1),
39+
TimeSpan.FromDays(1),
40+
TimeSpan.FromDays(7),
41+
TimeSpan.FromDays(TimeSpanExtensions.AvgDaysInAMonth),
42+
TimeSpan.FromDays(TimeSpanExtensions.AvgDaysInAMonth * 3)
43+
};
4144
private static int _dateSpanIndex = 3;
4245

4346
public static void Main(string[] args) {
@@ -84,11 +87,7 @@ public static void Main(string[] args) {
8487
ExceptionlessClient.Default.Configuration.AddPlugin(ctx => {
8588
// use server settings to see if we should include this data
8689
if (ctx.Client.Configuration.Settings.GetBoolean("IncludeConditionalData", true))
87-
ctx.Event.AddObject(new {
88-
Total = 32.34,
89-
ItemCount = 2,
90-
91-
}, "ConditionalData");
90+
ctx.Event.AddObject(new { Total = 32.34, ItemCount = 2, Email = "[email protected]" }, "ConditionalData");
9291
});
9392
ExceptionlessClient.Default.Configuration.Settings.Changed += (sender, changedArgs) => Trace.WriteLine($"Action: {changedArgs.Action} Key: {changedArgs.Item.Key} Value: {changedArgs.Item.Value}");
9493

@@ -110,11 +109,7 @@ public static void Main(string[] args) {
110109
ExceptionlessClient.Default.Configuration.UseSessions(false, null, true);
111110
ExceptionlessClient.Default.SubmitSessionStart();
112111
} else if (keyInfo.Key == ConsoleKey.D6)
113-
SendContinuousEvents(250, token, ev: new Event {
114-
Type = Event.KnownTypes.Log,
115-
Source = "SampleConsole.Program.Main",
116-
Message = "Sample console application event"
117-
});
112+
SendContinuousEvents(250, token, ev: new Event { Type = Event.KnownTypes.Log, Source = "SampleConsole.Program.Main", Message = "Sample console application event" });
118113
else if (keyInfo.Key == ConsoleKey.D7)
119114
ExceptionlessClient.Default.SubmitSessionEnd();
120115
else if (keyInfo.Key == ConsoleKey.D8)
@@ -185,28 +180,13 @@ private static ConsoleKeyInfo GetKeyFromRedirectedConsole() {
185180
}
186181

187182
private static void SampleApiUsages() {
188-
ExceptionlessClient.Default.CreateLog("SampleConsole", "Has lots of extended data").AddObject(new {
189-
myApplicationVersion = new Version(1, 0),
190-
Date = DateTime.Now,
191-
__sessionId = "9C72E4E8-20A2-469B-AFB9-492B6E349B23",
192-
SomeField10 = "testing"
193-
}, "Object From Code").AddObject(new {
194-
Blah = "Test"
195-
}, name: "Test Object").AddObject("Exceptionless is awesome", "String Content").AddObject(new int[] { 1, 2, 3, 4, 5 }, "Array Content").AddObject(new object[] { new {
196-
This = "This"
197-
},
198-
new {
199-
Is = "Is"
200-
},
201-
new {
202-
A = "A"
203-
},
204-
new {
205-
Test = "Test",
206-
Data = new {
207-
Punctuation = "!!!!"
208-
}
209-
} }, "Array With Nested Content").Submit();
183+
ExceptionlessClient.Default.CreateLog("SampleConsole", "Has lots of extended data")
184+
.AddObject(new { myApplicationVersion = new Version(1, 0), Date = DateTime.Now, __sessionId = "9C72E4E8-20A2-469B-AFB9-492B6E349B23", SomeField10 = "testing" }, "Object From Code")
185+
.AddObject(new { Blah = "Test" }, name: "Test Object")
186+
.AddObject("Exceptionless is awesome", "String Content")
187+
.AddObject(new int[] { 1, 2, 3, 4, 5 }, "Array Content")
188+
.AddObject(new object[] { new { This = "This" }, new { Is = "Is" }, new { A = "A" }, new { Test = "Test", Data = new { Punctuation = "!!!!" } } }, "Array With Nested Content")
189+
.Submit();
210190

211191
ExceptionlessClient.Default.SubmitFeatureUsage("MyFeature");
212192
ExceptionlessClient.Default.SubmitNotFound("/somepage");
@@ -219,13 +199,11 @@ private static void SampleApiUsages() {
219199
}
220200
}
221201

222-
private const int OPTIONS_MENU_LINE_COUNT = 14;
223-
202+
private const int OPTIONS_MENU_LINE_COUNT = 15;
224203
private static void WriteOptionsMenu() {
225204
lock (_writeLock) {
226205
Console.SetCursorPosition(0, 0);
227-
ClearConsoleLines(0, OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT);
228-
206+
ClearConsoleLines(0, OPTIONS_MENU_LINE_COUNT - 1);
229207
Console.WriteLine("1: Send 1");
230208
Console.WriteLine("2: Send 100");
231209
Console.WriteLine("3: Send continuous");
@@ -246,19 +224,18 @@ private static void WriteOptionsMenu() {
246224
private static void ClearOutputLines(int delay = 1000) {
247225
Task.Run(() => {
248226
Thread.Sleep(delay);
249-
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT, OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT);
227+
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT, OPTIONS_MENU_LINE_COUNT + 4);
250228
});
251229
}
252230

253231
private const int LOG_LINE_COUNT = 10;
254-
255232
private static void StartDisplayingLogMessages() {
256233
Task.Factory.StartNew(async () => {
257234
while (true) {
258235
var logEntries = _log.GetLogEntries(LOG_LINE_COUNT);
259236
lock (_writeLock) {
260-
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT + 4, OPTIONS_MENU_LINE_COUNT + LOG_LINE_COUNT);
261-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 4);
237+
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT + 5, OPTIONS_MENU_LINE_COUNT + 6 + LOG_LINE_COUNT);
238+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 6);
262239
foreach (var logEntry in logEntries) {
263240
var originalColor = Console.ForegroundColor;
264241
Console.ForegroundColor = GetColor(logEntry);
@@ -267,7 +244,6 @@ private static void StartDisplayingLogMessages() {
267244
}
268245
}
269246

270-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 1);
271247
await Task.Delay(250);
272248
}
273249
});
@@ -305,7 +281,7 @@ private static void ClearConsoleLines(int startLine = 0, int endLine = -1) {
305281
}
306282

307283
private static void SendContinuousEvents(int delay, CancellationToken token, int maxEvents = Int32.MaxValue, int maxDaysOld = 90, Event ev = null) {
308-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT);
284+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
309285
Console.WriteLine("Press 's' to stop sending.");
310286
int eventCount = 0;
311287

@@ -322,8 +298,7 @@ private static void SendContinuousEvents(int delay, CancellationToken token, int
322298
SendEvent(ev, false);
323299
eventCount++;
324300
lock (_writeLock) {
325-
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT + 1, OPTIONS_MENU_LINE_COUNT + 3);
326-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
301+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 4);
327302
Console.WriteLine("Submitted {0} events.", eventCount);
328303
}
329304

@@ -335,7 +310,6 @@ private static void SendContinuousEvents(int delay, CancellationToken token, int
335310
}
336311

337312
private static readonly RandomEventGenerator _rnd = new RandomEventGenerator();
338-
339313
private static void SendEvent(Event ev = null, bool writeToConsole = true) {
340314
_rnd.MinDate = DateTime.Now.Subtract(_dateSpans[_dateSpanIndex]);
341315
_rnd.MaxDate = DateTime.Now;
@@ -344,8 +318,7 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
344318

345319
if (writeToConsole) {
346320
lock (_writeLock) {
347-
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT, OPTIONS_MENU_LINE_COUNT + 3);
348-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 1);
321+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
349322
Console.WriteLine("Submitted 1 event.");
350323
Trace.WriteLine("Submitted 1 event.");
351324
}
@@ -356,8 +329,7 @@ private static void SendEvent(Event ev = null, bool writeToConsole = true) {
356329

357330
private static void SendAllCapturedEventsFromDisk() {
358331
lock (_writeLock) {
359-
ClearConsoleLines(OPTIONS_MENU_LINE_COUNT, OPTIONS_MENU_LINE_COUNT + 3);
360-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 1);
332+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
361333
Console.WriteLine("Sending captured events...");
362334
}
363335

@@ -373,7 +345,7 @@ private static void SendAllCapturedEventsFromDisk() {
373345

374346
eventCount++;
375347
lock (_writeLock) {
376-
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
348+
Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 3);
377349
Console.WriteLine("Sent {0} events.", eventCount);
378350
}
379351
}

0 commit comments

Comments
 (0)