Skip to content

Commit 94de43b

Browse files
Merge pull request #101 from MEAT-Inc/develop
Debug logging toggles and version increases
2 parents 39d28e3 + bcb56d0 commit 94de43b

5 files changed

Lines changed: 68 additions & 38 deletions

File tree

SharpExpressions/PassThruExpressionGenerator.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ public static PassThruExpressionsGenerator LoadExpressionsFile(string Expression
228228
/// 8) Store the built values on this class instance to return out our built expression objects
229229
/// 9) Log completed building and return the collection of built expressions
230230
/// </summary>
231+
/// <param name="EnableGeneratorLogging">When true, logging for this generator is enabled. Defaults to false</param>
231232
/// <returns>Returns a set of file objects which contain the PT commands from a file.</returns>
232-
public PassThruExpression[] GenerateLogExpressions()
233+
public PassThruExpression[] GenerateLogExpressions(bool EnableGeneratorLogging = false)
233234
{
234235
// Log building expression log command line sets now
235236
this._expressionsLogger.WriteLog($"CONVERTING INPUT LOG FILE {this.PassThruLogFile} INTO AN EXPRESSION SET NOW...", LogType.InfoLog);
@@ -290,6 +291,12 @@ public PassThruExpression[] GenerateLogExpressions()
290291
OutputExpressions[MatchIndex] = NextPassThruExpression;
291292
OutputFileContent[MatchIndex] = NextPassThruExpression.ToString();
292293

294+
// If logging is disabled, fire an event and move onto the next iteration
295+
if (!EnableGeneratorLogging) {
296+
this.OnGeneratorProgress?.Invoke(this, new ExpressionProgressEventArgs(LoopsCompleted, TimeMatches.Length));
297+
return;
298+
}
299+
293300
// Setup our scope diagnostic properties for the generator logger
294301
this._generationLogger.AddScopeProperties(
295302
new KeyValuePair<string, object>("expression-method", ExpressionTypes.ToString().ToUpper()),
@@ -319,11 +326,15 @@ public PassThruExpression[] GenerateLogExpressions()
319326
}
320327
catch (Exception GenerateExpressionEx)
321328
{
322-
// Log out and failures thrown during this operation
323-
this._expressionsLogger.WriteLog($"FAILED TO GENERATE AN EXPRESSION FROM INPUT COMMAND {MatchContents} (Index: {MatchIndex})!", LogType.WarnLog);
324-
this._generationLogger.WriteLog($"FAILED TO GENERATE AN EXPRESSION FROM INPUT COMMAND {MatchContents} (Index: {MatchIndex})!", LogType.WarnLog);
325-
this._expressionsLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", GenerateExpressionEx, LogType.WarnLog, LogType.TraceLog);
326-
this._generationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", GenerateExpressionEx, LogType.WarnLog, LogType.TraceLog);
329+
// Check if logging is enabled for this routine
330+
if (EnableGeneratorLogging)
331+
{
332+
// Log out and failures thrown during this operation
333+
this._expressionsLogger.WriteLog($"FAILED TO GENERATE AN EXPRESSION FROM INPUT COMMAND {MatchContents} (Index: {MatchIndex})!", LogType.WarnLog);
334+
this._generationLogger.WriteLog($"FAILED TO GENERATE AN EXPRESSION FROM INPUT COMMAND {MatchContents} (Index: {MatchIndex})!", LogType.WarnLog);
335+
this._expressionsLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", GenerateExpressionEx, LogType.WarnLog, LogType.TraceLog);
336+
this._generationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", GenerateExpressionEx, LogType.WarnLog, LogType.TraceLog);
337+
}
327338

328339
// Update progress values if needed now using the event for the progress checker
329340
this.OnGeneratorProgress?.Invoke(this, new ExpressionProgressEventArgs(LoopsCompleted++, TimeMatches.Length));

SharpExpressions/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[assembly: Guid("73552094-035A-4DFB-BEC4-5116EC7993EF")]
2020

2121
// Version information
22-
[assembly: AssemblyVersion("0.5.13.291")]
23-
[assembly: AssemblyFileVersion("0.5.13.291")]
22+
[assembly: AssemblyVersion("0.5.14.297")]
23+
[assembly: AssemblyFileVersion("0.5.14.297")]
2424
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2525

SharpSimulator/PassThruSimulationGenerator.cs

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ public static PassThruSimulationGenerator LoadExpressionsFile(string Expressions
209209
/// Uses the input Expressions objects on this generator and converts them into a collection of simulation objects
210210
/// These are then written to a file for our simulation output
211211
/// </summary>
212+
/// <param name="EnableGeneratorLogging">When true, logging for this generator is enabled. Defaults to false</param>
212213
/// <returns>The collection of built simulation channels from our log file</returns>
213-
public PassThruSimulationChannel[] GenerateLogSimulation()
214+
public PassThruSimulationChannel[] GenerateLogSimulation(bool EnableGeneratorLogging = false)
214215
{
215216
// Start by pulling in our grouped simulation channel objects
216217
var GroupedExpressions = this._generateGroupedIds();
@@ -259,22 +260,31 @@ public PassThruSimulationChannel[] GenerateLogSimulation()
259260

260261
// Tick the loop counter and setup our channel properties
261262
LoopsCompleted++;
262-
this._generationLogger.AddScopeProperties(
263-
new KeyValuePair<string, object>("sim-channel-id", SimChannelId),
264-
new KeyValuePair<string, object>("sim-message-pairs", ChannelExpressions.Length),
265-
new KeyValuePair<string, object>("generation-count", $"{LoopsCompleted} OF {TotalLoops}"),
266-
new KeyValuePair<string, object>("generation-progress", ((double)LoopsCompleted / (double)TotalLoops * 100.00).ToString("F2")));
263+
if (EnableGeneratorLogging)
264+
{
265+
// Only run this routine if logging is enabled for this generator
266+
this._generationLogger.AddScopeProperties(
267+
new KeyValuePair<string, object>("sim-channel-id", SimChannelId),
268+
new KeyValuePair<string, object>("sim-message-pairs", ChannelExpressions.Length),
269+
new KeyValuePair<string, object>("generation-count", $"{LoopsCompleted} OF {TotalLoops}"),
270+
new KeyValuePair<string, object>("generation-progress", ((double)LoopsCompleted / (double)TotalLoops * 100.00).ToString("F2")));
271+
}
267272

268273
// If no commands found, then just move onto the next channel
269274
if (PTConnectCommands.Length == 0)
270275
{
271-
// Log out our exception and invoke a new progress event with the properties we configured above
272-
this._simulationLogger.WriteLog($"FAILED TO GENERATE SIMULATION CHANNEL WITH ID {SimChannelId}! NO PTCONNECT COMMANDS WERE FOUND!", LogType.ErrorLog);
273-
this._generationLogger.WriteLog($"FAILED TO GENERATE SIMULATION CHANNEL WITH ID {SimChannelId}! NO PTCONNECT COMMANDS WERE FOUND!", LogType.ErrorLog);
274-
this._simulationLogger.WriteLog($"CHANNEL EXPRESSIONS CONTAINED {ChannelExpressions.Length} EXPRESSION OBJECTS", LogType.ErrorLog);
275-
this._generationLogger.WriteLog($"CHANNEL EXPRESSIONS CONTAINED {ChannelExpressions.Length} EXPRESSION OBJECTS", LogType.ErrorLog);
276+
// Check if logging is enabled for this generator
277+
if (EnableGeneratorLogging)
278+
{
279+
// Log out our exception and invoke a new progress event with the properties we configured above
280+
this._simulationLogger.WriteLog($"FAILED TO GENERATE SIMULATION CHANNEL WITH ID {SimChannelId}! NO PTCONNECT COMMANDS WERE FOUND!", LogType.ErrorLog);
281+
this._generationLogger.WriteLog($"FAILED TO GENERATE SIMULATION CHANNEL WITH ID {SimChannelId}! NO PTCONNECT COMMANDS WERE FOUND!", LogType.ErrorLog);
282+
this._simulationLogger.WriteLog($"CHANNEL EXPRESSIONS CONTAINED {ChannelExpressions.Length} EXPRESSION OBJECTS", LogType.ErrorLog);
283+
this._generationLogger.WriteLog($"CHANNEL EXPRESSIONS CONTAINED {ChannelExpressions.Length} EXPRESSION OBJECTS", LogType.ErrorLog);
284+
}
276285

277286
// Return out to our next loop/channel
287+
this.OnGeneratorProgress?.Invoke(this, new SimulationProgressEventArgs(LoopsCompleted, TotalLoops));
278288
return;
279289
}
280290

@@ -290,7 +300,7 @@ public PassThruSimulationChannel[] GenerateLogSimulation()
290300
.FirstOrDefault(ProtocolName => ProtocolInUse.ToString().Contains(ProtocolName)) + "_" + ConnectCommand.BaudRate);
291301

292302
// If no read commands were found or no write commands were found, move onto the next channel instance
293-
if (PTReadCommands.Length == 0 || PTWriteCommands.Length == 0)
303+
if ((PTReadCommands.Length == 0 || PTWriteCommands.Length == 0) && EnableGeneratorLogging)
294304
{
295305
// Log out our exception and invoke a new progress event with the properties we configured above
296306
this._simulationLogger.WriteLog($"FAILED TO GENERATE NEW SIMULATION CHANNEL WITH ID {SimChannelId}! NO PTREAD/PTWRITE COMMANDS WERE FOUND!", LogType.ErrorLog);
@@ -299,6 +309,7 @@ public PassThruSimulationChannel[] GenerateLogSimulation()
299309
this._generationLogger.WriteLog($"CHANNEL EXPRESSIONS CONTAINED {ChannelExpressions.Length} EXPRESSION OBJECTS", LogType.ErrorLog);
300310

301311
// Return out to our next loop/channel
312+
this.OnGeneratorProgress?.Invoke(this, new SimulationProgressEventArgs(LoopsCompleted, TotalLoops));
302313
return;
303314
}
304315

@@ -319,27 +330,35 @@ public PassThruSimulationChannel[] GenerateLogSimulation()
319330
// Now insert this expression object based on what keys are in the output collection of expressions
320331
SimChannelsBuilt.Add(SimChannelId, SimChannelBuilt);
321332

322-
// Log information about the built out command objects.
323-
this._generationLogger.WriteLog($"BUILT NEW {SimChannelBuilt.ChannelProtocol} CHANNEL WITH A SPECIFIED BAUD RATE OF {SimChannelBuilt.ChannelBaudRate}");
324-
this._generationLogger.WriteLog(
325-
$"PULLED OUT THE FOLLOWING INFO FROM OUR COMMANDS (CHANNEL ID {SimChannelId}):" +
326-
$" {PTConnectCommands.Length} PT CONNECTS" +
327-
$" | {PTFilterCommands.Length} FILTERS" +
328-
$" | {PTReadCommands.Length} READ COMMANDS" +
329-
$" | {PTWriteCommands.Length} WRITE COMMANDS" +
330-
$" | {SimChannelBuilt.MessagePairs.Length} MESSAGE PAIRS TOTAL");
333+
// Check if logging is enabled for this routine
334+
if (EnableGeneratorLogging)
335+
{
336+
// Log information about the built out command objects.
337+
this._generationLogger.WriteLog($"BUILT NEW {SimChannelBuilt.ChannelProtocol} CHANNEL WITH A SPECIFIED BAUD RATE OF {SimChannelBuilt.ChannelBaudRate}");
338+
this._generationLogger.WriteLog(
339+
$"PULLED OUT THE FOLLOWING INFO FROM OUR COMMANDS (CHANNEL ID {SimChannelId}):" +
340+
$" {PTConnectCommands.Length} PT CONNECTS" +
341+
$" | {PTFilterCommands.Length} FILTERS" +
342+
$" | {PTReadCommands.Length} READ COMMANDS" +
343+
$" | {PTWriteCommands.Length} WRITE COMMANDS" +
344+
$" | {SimChannelBuilt.MessagePairs.Length} MESSAGE PAIRS TOTAL");
345+
}
331346
}
332347

333348
// Invoke a new progress event here and move onto the next channel
334349
this.OnGeneratorProgress?.Invoke(this, new SimulationProgressEventArgs(LoopsCompleted, TotalLoops));
335350
}
336351
catch (Exception BuildChannelCommandEx)
337352
{
338-
// Log failures out and find out why the fails happen then move to our progress routine or move to next iteration
339-
this._simulationLogger.WriteLog($"FAILED TO GENERATE A SIMULATION CHANNEL FROM A SET OF EXPRESSIONS!", LogType.ErrorLog);
340-
this._generationLogger.WriteLog($"FAILED TO GENERATE A SIMULATION CHANNEL FROM A SET OF EXPRESSIONS!", LogType.ErrorLog);
341-
this._simulationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", BuildChannelCommandEx, LogType.ErrorLog);
342-
this._generationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", BuildChannelCommandEx, LogType.ErrorLog);
353+
// Check if logging is enabled for this routine
354+
if (EnableGeneratorLogging)
355+
{
356+
// Log failures out and find out why the fails happen then move to our progress routine or move to next iteration
357+
this._simulationLogger.WriteLog($"FAILED TO GENERATE A SIMULATION CHANNEL FROM A SET OF EXPRESSIONS!", LogType.ErrorLog);
358+
this._generationLogger.WriteLog($"FAILED TO GENERATE A SIMULATION CHANNEL FROM A SET OF EXPRESSIONS!", LogType.ErrorLog);
359+
this._simulationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", BuildChannelCommandEx, LogType.ErrorLog);
360+
this._generationLogger.WriteException("EXCEPTION THROWN IS LOGGED BELOW", BuildChannelCommandEx, LogType.ErrorLog);
361+
}
343362

344363
// Invoke a new progress event here and move on
345364
this.OnGeneratorProgress?.Invoke(this, new SimulationProgressEventArgs(LoopsCompleted++, TotalLoops));

SharpSimulator/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[assembly: Guid("183F7A6A-E107-4209-8A11-044A08DEAEE4")]
2020

2121
// Version information
22-
[assembly: AssemblyVersion("0.12.7.261")]
23-
[assembly: AssemblyFileVersion("0.12.7.261")]
22+
[assembly: AssemblyVersion("0.12.8.266")]
23+
[assembly: AssemblyFileVersion("0.12.8.266")]
2424
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2525

SharpWrapper/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[assembly: InternalsVisibleTo("SharpWrap2534Tests")]
2121

2222
// Version information
23-
[assembly: AssemblyVersion("6.1.12.476")]
24-
[assembly: AssemblyFileVersion("6.1.12.476")]
23+
[assembly: AssemblyVersion("6.1.12.477")]
24+
[assembly: AssemblyFileVersion("6.1.12.477")]
2525
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
2626

0 commit comments

Comments
 (0)