Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,37 @@ private static List<Exception> GetVersionMismatchedReferencesInAppDomain(Assembl
}
return output;
}

/// <summary>
/// Attempts to import assemblies as node libraries from a given set of file paths.
/// </summary>
/// <param name="model">The Dynamo model</param>
/// <param name="paths">The list of paths from which to attempt importing </param>
public static void ImportAssemblies(DynamoModel model, IEnumerable<string> 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe I should add a new method directly in the model?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a public method in ExtensionLibraryLoader that essentially redirects the call to DynamoModel.LoadNodeLibrary.

}
}
catch (Exception e)
{
model.Logger?.Log($"Exception while trying to load assembly {path}: {e}");
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/DynamoCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this function as well?

});
StartupUtils.ImportAssemblies(model, cmdLineArgs.ImportedPaths);
}

return model;
}
Expand Down
33 changes: 3 additions & 30 deletions src/DynamoWPFCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -139,33 +139,6 @@ private static void RunKeepAlive(StartupUtils.CommandLineArguments cmdLineArgs)
}
}

/// <summary>
/// Attempts to import an assembly as a node library from a given file path.
/// </summary>
/// <param name="model"></param>
/// <param name="path"></param>
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);
Expand Down
Loading