@@ -24,6 +24,7 @@ public class ModuleResolver : IModuleResolver
2424
2525 // Parses different command aliases and parameters to their respective ICommand(s)
2626 public IDictionary < string , IList < Func < string [ ] , ICommand > > > CommandParsers => _commandParsers ;
27+
2728 private static IDictionary < string , IList < Func < string [ ] , ICommand > > > _commandParsers =
2829 new Dictionary < string , IList < Func < string [ ] , ICommand > > > ( ) ;
2930
@@ -46,7 +47,16 @@ static ModuleResolver()
4647 {
4748 CommandDocumentation = new StringBuilder ( ) ;
4849 ScanAssembly ( ) ;
49- File . WriteAllText ( "commands.txt" , CommandDocumentation . ToString ( ) ) ;
50+ #if DEBUG
51+ try
52+ {
53+ File . WriteAllText ( "commands.txt" , CommandDocumentation . ToString ( ) ) ;
54+ }
55+ catch ( Exception )
56+ {
57+ // Ignore, just used for reference when building locally
58+ }
59+ #endif
5060 }
5161
5262 public ModuleResolver ( ILogger < ModuleResolver > logger )
@@ -120,7 +130,7 @@ private void CreateCommandHandler<TCommand>() where TCommand : ICommand
120130 _logger . LogError ( e , "Command handling failed for {Message} (sync)" , matchedCommand . Message . Text ) ;
121131 activity ? . SetStatus ( ActivityStatusCode . Error , $ "Command failed: { matchedCommand . Message . Text } ") ;
122132 }
123-
133+
124134 AppDiagnostics . TrackCommand ( commandType . Name , moduleType , startTime ) ;
125135 }
126136
@@ -154,7 +164,7 @@ private void CreateCommandHandler<TCommand>() where TCommand : ICommand
154164 _logger . LogError ( ex , "Command handling failed for {Message} (async)" , matchedCommand . Message . Text ) ;
155165 activity ? . SetStatus ( ActivityStatusCode . Error , $ "Command failed: { matchedCommand . Message . Text } { ex . Message } ") ;
156166 }
157-
167+
158168 AppDiagnostics . TrackCommand ( commandType . Name , moduleType , startTime ) ;
159169 }
160170 } ) ;
@@ -224,7 +234,7 @@ private void CreateEventHandler<TEvent>() where TEvent : IEvent
224234 using var activity = TraceEventType ( eventType . Name ) ? Telemetry . ActivitySource . StartActivity ( "AsyncEventHandler:" + moduleType ) : null ;
225235 activity ? . SetTag ( "bf2wa.event-type" , eventType . Name ) ;
226236 activity ? . SetTag ( "bf2wa.module-type" , moduleType ) ;
227-
237+
228238 try
229239 {
230240 await asyncHandler . HandleAsync ( matchedEvent ) ;
@@ -234,7 +244,7 @@ private void CreateEventHandler<TEvent>() where TEvent : IEvent
234244 _logger . LogError ( ex , "Event handling failed for {Event} (async)" , matchedEvent ) ;
235245 activity ? . SetStatus ( ActivityStatusCode . Error , $ "Event failed: { eventType . Name } , { ex . Message } ") ;
236246 }
237-
247+
238248 AppDiagnostics . TrackEvent ( eventType . Name , moduleType , startTime ) ;
239249 }
240250 } ) ;
@@ -246,7 +256,7 @@ private void CreateEventHandler<TEvent>() where TEvent : IEvent
246256
247257 if ( handlerCount == 0 )
248258 _logger . LogTrace ( "No event handlers registered for {EventName}" , typeof ( TEvent ) . Name ) ;
249-
259+
250260 static bool TraceEventType ( string ? eventType ) => eventType != nameof ( PlayerPositionEvent ) && eventType != nameof ( ProjectilePositionEvent ) ;
251261 }
252262
@@ -303,8 +313,7 @@ private static Func<string[], ICommand> GetCommandParser(Type commandType, Comma
303313
304314 // Assign the rest of the string to the last parameter?
305315 var shouldCombineRemainingParameters = attr . Parameters . Length == ( index + 1 ) && attr . CombineLast ;
306- var argumentValue = shouldCombineRemainingParameters ?
307- string . Join ( " " , args . Skip ( index ) ) : args [ index ++ ] ;
316+ var argumentValue = shouldCombineRemainingParameters ? string . Join ( " " , args . Skip ( index ) ) : args [ index ++ ] ;
308317
309318 var convertedValue = Convert . ChangeType ( argumentValue , propertyInfo . PropertyType ) ;
310319 propertyInfo . SetValue ( command , convertedValue ) ;
@@ -399,10 +408,14 @@ private class EventModule
399408
400409public class CommandArgumentCountException : Exception
401410{
402- public CommandArgumentCountException ( string message ) : base ( message ) { }
411+ public CommandArgumentCountException ( string message ) : base ( message )
412+ {
413+ }
403414}
404415
405416public class CommandParseException : Exception
406417{
407- public CommandParseException ( string message ) : base ( message ) { }
418+ public CommandParseException ( string message ) : base ( message )
419+ {
420+ }
408421}
0 commit comments