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/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index eac5ab32d3d..c087fbc8d50 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 OnWorkspaceOpened(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..c66588d7abb 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.OnWorkspaceOpened(model.NodeLibraryDependencies, + ReadyParams.StartupParams.PathManager.PackagesDirectories); + } } }