From 0b7b1e8a97571f6bc1077d10449276d362da0360 Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Tue, 16 Feb 2021 23:11:55 -0500 Subject: [PATCH 1/3] try loading packages by workspace references --- src/DynamoPackages/PackageLoader.cs | 33 ++++++++++++++++++- src/DynamoPackages/PackageManagerExtension.cs | 6 ++++ src/Engine/ProtoCore/Core.cs | 2 +- src/Engine/ProtoCore/RuntimeCore.cs | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index eac5ab32d3d..b6cf8bba9aa 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -6,6 +6,7 @@ using Dynamo.Core; using Dynamo.Exceptions; using Dynamo.Extensions; +using Dynamo.Graph.Workspaces; using Dynamo.Interfaces; using Dynamo.Logging; using Dynamo.Utilities; @@ -91,7 +92,7 @@ public PackageLoader(IEnumerable packagesDirectories) if (packagesDirectories == null) throw new ArgumentNullException("packagesDirectories"); - this.packagesDirectories.AddRange(packagesDirectories); + //this.packagesDirectories.AddRange(packagesDirectories); this.packagesDirectories.Add(StandardLibraryDirectory); var error = PathHelper.CreateFolderIfNotExist(DefaultPackagesDirectory); @@ -102,6 +103,36 @@ public PackageLoader(IEnumerable packagesDirectories) packagesDirectoriesToVerifyCertificates.Add(StandardLibraryDirectory); } + internal void OnWorkspaceRead(IEnumerable packageDependencies, + IEnumerable packageDirectories) + { + var pkgs = new List(); + foreach (var root in packageDirectories) + { + foreach (var dir in + Directory.EnumerateDirectories(root, "*", SearchOption.TopDirectoryOnly)) + { + var headerPath = Path.Combine(dir, "pkg.json"); + if (PathHelper.IsValidPath(headerPath)) + { + var discoveredPkg = Package.FromJson(headerPath, AsLogger()); + if(discoveredPkg == null) continue; + + foreach (var info in packageDependencies) + { + // if workspace package dependency is present in downloaded packages, load it. + if (info.Name == discoveredPkg.Name && info.Version.ToString() == discoveredPkg.VersionName) + { + pkgs.Add(discoveredPkg); + break; + } + } + } + } + } + LoadPackages(pkgs); + } + /// /// Initialize a new instance of PackageLoader class /// diff --git a/src/DynamoPackages/PackageManagerExtension.cs b/src/DynamoPackages/PackageManagerExtension.cs index b5ab3d80d44..68916646783 100644 --- a/src/DynamoPackages/PackageManagerExtension.cs +++ b/src/DynamoPackages/PackageManagerExtension.cs @@ -224,6 +224,12 @@ private void OnCurrentWorkspaceChanged(IWorkspaceModel ws) (ws as WorkspaceModel).CollectingCustomNodePackageDependencies += GetCustomNodePackageFromID; (ws as WorkspaceModel).CollectingNodePackageDependencies += GetNodePackageFromAssemblyName; currentWorkspace = ws; + + if (PackageLoader != null && ws is HomeWorkspaceModel model) + { + PackageLoader.OnWorkspaceRead(model.NodeLibraryDependencies, + ReadyParams.StartupParams.PathManager.PackagesDirectories); + } } } diff --git a/src/Engine/ProtoCore/Core.cs b/src/Engine/ProtoCore/Core.cs index 6a7e62f2e11..40c81f64d56 100644 --- a/src/Engine/ProtoCore/Core.cs +++ b/src/Engine/ProtoCore/Core.cs @@ -828,7 +828,7 @@ public void ResetSSASubscript(Guid guid, int subscript) public void Cleanup() { - CLRModuleType.ClearTypes(); + //CLRModuleType.ClearTypes(); } } } diff --git a/src/Engine/ProtoCore/RuntimeCore.cs b/src/Engine/ProtoCore/RuntimeCore.cs index d5c88188c96..60528d9ce7c 100644 --- a/src/Engine/ProtoCore/RuntimeCore.cs +++ b/src/Engine/ProtoCore/RuntimeCore.cs @@ -270,7 +270,7 @@ protected void OnDispose() public void Cleanup() { OnDispose(); - CLRModuleType.ClearTypes(); + //CLRModuleType.ClearTypes(); } public void NotifyExecutionEvent(ExecutionStateEventArgs.State state) From 45187da28a9de76459e15b278127896a24b6b793 Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Tue, 16 Feb 2021 23:45:34 -0500 Subject: [PATCH 2/3] fixes --- src/DynamoCore/Models/DynamoModel.cs | 4 +++- src/Engine/ProtoCore/Core.cs | 2 +- src/Engine/ProtoCore/RuntimeCore.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index e1c6dd4b1e7..6df56dafc1a 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -1693,6 +1693,8 @@ private bool OpenJsonFileFromPath(string fileContents, string filePath, bool for OnComputeModelDeserialized(); SetPeriodicEvaluation(ws); + + CurrentWorkspace = ws; } } } @@ -1771,7 +1773,7 @@ private void OpenWorkspace(WorkspaceModel ws) } AddWorkspace(ws); - CurrentWorkspace = ws; + //CurrentWorkspace = ws; OnWorkspaceOpened(ws); } diff --git a/src/Engine/ProtoCore/Core.cs b/src/Engine/ProtoCore/Core.cs index 40c81f64d56..6a7e62f2e11 100644 --- a/src/Engine/ProtoCore/Core.cs +++ b/src/Engine/ProtoCore/Core.cs @@ -828,7 +828,7 @@ public void ResetSSASubscript(Guid guid, int subscript) public void Cleanup() { - //CLRModuleType.ClearTypes(); + CLRModuleType.ClearTypes(); } } } diff --git a/src/Engine/ProtoCore/RuntimeCore.cs b/src/Engine/ProtoCore/RuntimeCore.cs index 60528d9ce7c..d5c88188c96 100644 --- a/src/Engine/ProtoCore/RuntimeCore.cs +++ b/src/Engine/ProtoCore/RuntimeCore.cs @@ -270,7 +270,7 @@ protected void OnDispose() public void Cleanup() { OnDispose(); - //CLRModuleType.ClearTypes(); + CLRModuleType.ClearTypes(); } public void NotifyExecutionEvent(ExecutionStateEventArgs.State state) From 5ab470a407ef2ca260b5c79f042bd933b88f1f08 Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Tue, 16 Feb 2021 23:55:34 -0500 Subject: [PATCH 3/3] rename method --- src/DynamoPackages/PackageLoader.cs | 2 +- src/DynamoPackages/PackageManagerExtension.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index b6cf8bba9aa..c087fbc8d50 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -103,7 +103,7 @@ public PackageLoader(IEnumerable packagesDirectories) packagesDirectoriesToVerifyCertificates.Add(StandardLibraryDirectory); } - internal void OnWorkspaceRead(IEnumerable packageDependencies, + internal void OnWorkspaceOpened(IEnumerable packageDependencies, IEnumerable packageDirectories) { var pkgs = new List(); diff --git a/src/DynamoPackages/PackageManagerExtension.cs b/src/DynamoPackages/PackageManagerExtension.cs index 68916646783..c66588d7abb 100644 --- a/src/DynamoPackages/PackageManagerExtension.cs +++ b/src/DynamoPackages/PackageManagerExtension.cs @@ -227,7 +227,7 @@ private void OnCurrentWorkspaceChanged(IWorkspaceModel ws) if (PackageLoader != null && ws is HomeWorkspaceModel model) { - PackageLoader.OnWorkspaceRead(model.NodeLibraryDependencies, + PackageLoader.OnWorkspaceOpened(model.NodeLibraryDependencies, ReadyParams.StartupParams.PathManager.PackagesDirectories); } }