@@ -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 ) ) ;
0 commit comments