Ejemplo n.º 1
0
        public void Load(Package package)
        {
            TryLoadPackageIntoLibrary(package);

            var assemblies =
                LocalPackages.SelectMany(x => x.EnumerateAndLoadAssembliesInBinDirectory().Where(y => y.IsNodeLibrary));

            PackagesLoaded?.Invoke(assemblies.Select(x => x.Assembly));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try loading package into Library (including all node libraries and custom nodes)
        /// and add to LocalPackages.
        /// </summary>
        /// <param name="package"></param>
        private void TryLoadPackageIntoLibrary(Package package)
        {
            Add(package);

            // Prevent duplicate loads
            if (package.LoadState.State == PackageLoadState.StateTypes.Loaded)
            {
                return;
            }

            // Prevent loading packages that have been specifically marked as unloaded
            if (package.LoadState.State == PackageLoadState.StateTypes.Unloaded)
            {
                return;
            }

            List <Assembly> loadedNodeLibs = new List <Assembly>();

            try
            {
                // load node libraries
                foreach (var assem in package.EnumerateAndLoadAssembliesInBinDirectory())
                {
                    if (assem.IsNodeLibrary)
                    {
                        try
                        {
                            OnRequestLoadNodeLibrary(assem.Assembly);
                            loadedNodeLibs.Add(assem.Assembly);
                        }
                        catch (LibraryLoadFailedException ex)
                        {
                            Log(ex.GetType() + ": " + ex.Message);
                        }
                    }
                }

                // load custom nodes
                var packageInfo = new Graph.Workspaces.PackageInfo(package.Name, new Version(package.VersionName));
                var customNodes = OnRequestLoadCustomNodeDirectory(package.CustomNodeDirectory, packageInfo);
                package.LoadedCustomNodes.AddRange(customNodes);

                package.EnumerateAdditionalFiles();

                // If the additional files contained an extension manifest, then request it be loaded.
                var extensionManifests = package.AdditionalFiles.Where(
                    file => file.Model.Name.Contains("ExtensionDefinition.xml") && !file.Model.Name.Contains("ViewExtensionDefinition.xml")).ToList();
                foreach (var extPath in extensionManifests)
                {
                    var extension = RequestLoadExtension?.Invoke(extPath.Model.FullName);
                    if (extension != null)
                    {
                        RequestAddExtension?.Invoke(extension);
                    }
                    requestedExtensions.Add(extension);
                }

                package.SetAsLoaded();
                PackgeLoaded?.Invoke(package);
                PackagesLoaded?.Invoke(loadedNodeLibs);

                PythonServices.PythonEngineManager.Instance.
                LoadPythonEngine(package.LoadedAssemblies.Select(x => x.Assembly));
            }
            catch (CustomNodePackageLoadException e)
            {
                Package originalPackage =
                    localPackages.FirstOrDefault(x => x.CustomNodeDirectory == e.InstalledPath);
                OnConflictingPackageLoaded(originalPackage, package);

                package.LoadState.SetAsError(e.Message);
            }
            catch (Exception e)
            {
                if (e is DynamoServices.AssemblyBlockedException)
                {
                    var failureMessage = string.Format(Properties.Resources.PackageLoadFailureForBlockedAssembly, e.Message);
                    DynamoServices.LoadLibraryEvents.OnLoadLibraryFailure(failureMessage, Properties.Resources.LibraryLoadFailureMessageBoxTitle);
                }
                package.LoadState.SetAsError(e.Message);
                Log("Exception when attempting to load package " + package.Name + " from " + package.RootDirectory);
                Log(e.GetType() + ": " + e.Message);
            }
        }
Ejemplo n.º 3
0
 private void OnPackagesLoaded(IEnumerable <Assembly> assemblies)
 {
     PackagesLoaded?.Invoke(assemblies);
 }