Procházet zdrojové kódy

Qconsole:

fix loading command from merged assemblies (add distinct) and debug
Dalibor Votruba před 6 roky
rodič
revize
7617a92b90
1 změnil soubory, kde provedl 5 přidání a 4 odebrání
  1. 5 4
      QConsole/QConsole/Engine.cs

+ 5 - 4
QConsole/QConsole/Engine.cs

@@ -64,7 +64,7 @@ namespace Quadarax.Foundation.QConsole
             {
                 var command = Construct<AbstractCommand>(commandClass, paramConstrTypes, paramConstrValues);
                 _commands.Add(command);
-                WriteDebugInfo($"Command definition '{command}' added.");
+                WriteDebugInfo($"Command definition '{command}' added - class '{command.GetType().FullName}', assembly '{command.GetType().Assembly.GetName().Name}'.");
             }
 
             WriteDebugInfo("Console initialized.");
@@ -223,14 +223,14 @@ namespace Quadarax.Foundation.QConsole
            
             WriteDebugInfo($"Loading command assemblies ...");
 
-            var defaultTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToList();
+            var defaultTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).Distinct().ToList();
             
             var customTypes = new List<Type>();
             if (_configuration.CommandDefinitionAssebmly != null)
             {
                 foreach (var assembly in _configuration.CommandDefinitionAssebmly)
                 {
-                    customTypes.AddRange(assembly.GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).ToArray());
+                    customTypes.AddRange(assembly.GetTypes().Where(type => type.GetCustomAttributes(attribute.GetType(), true).Length > 0).Distinct().ToArray());
                     WriteDebugInfo(assembly.GetName().Name + " was scanned for commands.");
                 }
             }
@@ -240,6 +240,7 @@ namespace Quadarax.Foundation.QConsole
             }
             WriteDebugInfo($"Command definition obtaining process found {defaultTypes.Count} default definitions and {customTypes.Count} custom definitions.");
             defaultTypes.AddRange(customTypes);
+            defaultTypes = defaultTypes.Distinct().ToList();
 
             foreach (var disabledCommand in _configuration.DisabledCommands)
             {
@@ -247,7 +248,7 @@ namespace Quadarax.Foundation.QConsole
                 if (disabled==null)
                     continue;
                 defaultTypes.Remove(disabled);
-                WriteDebugInfo($"Commnad class '{disabled.Name}' was skipped by configuration.");
+                WriteDebugInfo($"Commnad class '{disabled.Name}', fullname '{disabled.FullName}', assembly '{disabled.Assembly.GetName().Name}' was skipped by configuration.");
             }
 
             return defaultTypes.ToArray();