Ejemplo n.º 1
0
        private void AddDllFile(string filename)
        {
            try
            {
                Assembly assem;

                // we're not sure if this is a managed assembly or not
                // we try to load it, if it fails - we add it as an additional file
                var result = PackageLoader.TryLoadFrom(filename, out assem);
                if (result)
                {
                    var assemName = assem.GetName().Name;

                    // The user has attempted to load an existing dll from another path. This is not allowed
                    // as the existing assembly cannot be modified while Dynamo is active.
                    if (this.Assemblies.Any(x => assemName == x.Assembly.GetName().Name))
                    {
                        MessageBox.Show(string.Format(Resources.PackageDuplicateAssemblyWarning,
                                                      dynamoViewModel.BrandingResourceProvider.ProductName),
                                        Resources.PackageDuplicateAssemblyWarningTitle,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
                        return; // skip loading assembly
                    }

                    Assemblies.Add(new PackageAssembly()
                    {
                        Assembly      = assem,
                        IsNodeLibrary = true // assume is node library when first added
                    });
                    RaisePropertyChanged("PackageContents");
                }
                else
                {
                    AddAdditionalFile(filename);
                }
            }
            catch (Exception e)
            {
                UploadState = PackageUploadHandle.State.Error;
                ErrorString = String.Format(Resources.MessageFailedToAddFile, filename);
                dynamoViewModel.Model.Logger.Log(e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Enumerates all assemblies in the package
        /// </summary>
        /// <returns>The list of all node library assemblies</returns>
        internal IEnumerable <PackageAssembly> EnumerateAssembliesInBinDirectory()
        {
            var assemblies = new List <PackageAssembly>();

            if (!Directory.Exists(BinaryDirectory))
            {
                return(assemblies);
            }

            // Use the pkg header to determine which assemblies to load and prevent multiple enumeration
            // In earlier packages, this field could be null, which is correctly handled by IsNodeLibrary
            var nodeLibraries = Header.node_libraries;

            foreach (var assemFile in (new System.IO.DirectoryInfo(BinaryDirectory)).EnumerateFiles("*.dll"))
            {
                Assembly assem;

                // dll files may be un-managed, skip those
                var result = PackageLoader.TryLoadFrom(assemFile.FullName, out assem);
                if (result)
                {
                    // IsNodeLibrary may fail, we store the warnings here and then show
                    IList <ILogMessage> warnings = new List <ILogMessage>();

                    assemblies.Add(new PackageAssembly()
                    {
                        Assembly      = assem,
                        IsNodeLibrary = IsNodeLibrary(nodeLibraries, assem.GetName(), ref warnings)
                    });

                    warnings.ToList().ForEach(this.Log);
                }
            }

            foreach (var assem in assemblies)
            {
                LoadedAssemblies.Add(assem);
            }

            return(assemblies);
        }
Ejemplo n.º 3
0
        private void AddDllFile(string filename)
        {
            try
            {
                Assembly assem;

                // we're not sure if this is a managed assembly or not
                // we try to load it, if it fails - we add it as an additional file
                var result = PackageLoader.TryLoadFrom(filename, out assem);
                if (result)
                {
                    this.Assemblies.Add(assem);
                    this.RaisePropertyChanged("PackageContents");
                }
                else
                {
                    AddAdditionalFile(filename);
                }
            }
            catch (Exception e)
            {
                this.dynamoViewModel.Model.Logger.Log(e);
            }
        }