diff --git a/src/DynamoApplications/StartupUtils.cs b/src/DynamoApplications/StartupUtils.cs index 103b83d14df..84f15610550 100644 --- a/src/DynamoApplications/StartupUtils.cs +++ b/src/DynamoApplications/StartupUtils.cs @@ -491,5 +491,37 @@ private static List GetVersionMismatchedReferencesInAppDomain(Assembl } return output; } + + /// + /// Attempts to import assemblies as node libraries from a given set of file paths. + /// + /// The Dynamo model + /// The list of paths from which to attempt importing + public static void ImportAssemblies(DynamoModel model, IEnumerable paths) + { + ArgumentNullException.ThrowIfNull(model, nameof(model)); + ArgumentNullException.ThrowIfNull(paths, nameof(paths)); + + foreach(var path in paths) + { + try + { + var filePath = new System.IO.FileInfo(path); + if (!filePath.Exists) + { + model.Logger?.Log($"Could not find requested import library at path{path}"); + } + else + { + var assembly = Assembly.LoadFile(path); + model.LoadNodeLibrary(assembly, true); + } + } + catch (Exception e) + { + model.Logger?.Log($"Exception while trying to load assembly {path}: {e}"); + } + } + } } } diff --git a/src/DynamoCLI/Program.cs b/src/DynamoCLI/Program.cs index 4de3f8329e9..348af4fb360 100644 --- a/src/DynamoCLI/Program.cs +++ b/src/DynamoCLI/Program.cs @@ -108,10 +108,10 @@ private static DynamoModel StartupDynamo(StartupUtils.CommandLineArguments cmdLi model.ShutdownCompleted += (m) => { ShutDown(); }; - cmdLineArgs.ImportedPaths?.ToList().ForEach(path => + if (cmdLineArgs.ImportedPaths != null) { - CommandLineRunner.ImportAssembly(model, path); - }); + StartupUtils.ImportAssemblies(model, cmdLineArgs.ImportedPaths); + } return model; } diff --git a/src/DynamoWPFCLI/Program.cs b/src/DynamoWPFCLI/Program.cs index fcb37a02894..628caa0c887 100644 --- a/src/DynamoWPFCLI/Program.cs +++ b/src/DynamoWPFCLI/Program.cs @@ -110,10 +110,10 @@ private static DynamoViewModel StartupDynamo(StartupUtils.CommandLineArguments c } }); - cmdLineArgs.ImportedPaths.ToList().ForEach(path => + if (cmdLineArgs.ImportedPaths != null) { - ImportAssembly(model, path); - }); + StartupUtils.ImportAssemblies(model, cmdLineArgs.ImportedPaths); + } return viewModel; } @@ -139,33 +139,6 @@ private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs) } } - /// - /// Attempts to import an assembly as a node library from a given file path. - /// - /// - /// - private static void ImportAssembly(DynamoModel model, string path) - { - try - { - var filePath = new System.IO.FileInfo(path); - if (!filePath.Exists) - { - Console.WriteLine($"could not find requested import library at path{path}"); - } - else - { - Console.WriteLine($"attempting to import assembly {path}"); - var assembly = System.Reflection.Assembly.LoadFile(path); - model.LoadNodeLibrary(assembly, true); - } - } - catch (Exception e) - { - Console.WriteLine($"exception while trying to load assembly {path}: {e}"); - } - } - private static void ShutDown() { Environment.Exit(0);