Exemplo n.º 1
0
        private void PreloadLibraries(IEnumerable <string> preloadLibraries)
        {
            importedLibraries.AddRange(preloadLibraries);

            foreach (var library in importedLibraries)
            {
                CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library);
            }
        }
Exemplo n.º 2
0
        private void PreloadLibraries()
        {
            importedLibraries.AddRange(DynamoPathManager.Instance.PreloadLibraries);

            foreach (var library in importedLibraries)
            {
                CompilerUtils.TryLoadAssemblyIntoCore(libraryManagementCore, library);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads zero touch library module from given assembly.
        /// </summary>
        /// <param name="assembly"></param>
        public ZeroTouchModule(string assembly)
        {
            var core = CreateCore();

            if (!CompilerUtils.TryLoadAssemblyIntoCore(core, assembly))
            {
                throw new InvalidOperationException("Failed to load : " + assembly);
            }

            var library = new LibraryMirror(core, assembly, core.ClassTable.ClassNodes);

            types = library.GetClasses();
        }
Exemplo n.º 4
0
        public void Init()
        {
            string libraryPath = "FFITarget.dll";

            var options = new ProtoCore.Options();

            options.RootModulePathName = string.Empty;

            libraryServicesCore = new ProtoCore.Core(options);
            libraryServicesCore.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(libraryServicesCore));
            libraryServicesCore.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(libraryServicesCore));

            CompilerUtils.TryLoadAssemblyIntoCore(libraryServicesCore, libraryPath);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library"></param>
        public bool ImportLibrary(string library)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                string errorMessage = Properties.Resources.InvalidLibraryFormat;
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryHasBeenLoaded, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (!pathManager.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryPathCannotBeFound, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = LibraryManagementCore.ClassTable;

                int functionNumber = functionTable.procList.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library);


                if (LibraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format(Properties.Resources.LibraryBuildError, library);
                    Log(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in LibraryManagementCore.BuildStatus.Errors)
                    {
                        Log(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                    return(false);
                }

                LoadLibraryMigrations(library);

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.procList.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message));
                return(false);
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));

            // After a library is loaded, update the library core data with the liveRunner core data
            UpdateLibraryCoreData();
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library">The library to be loaded</param>
        /// <param name="isExplicitlyImportedLib">Indicates if the library has been imported using the "File | ImportLibrary" command</param>
        internal bool ImportLibrary(string library, bool isExplicitlyImportedLib = false)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                string errorMessage = Properties.Resources.InvalidLibraryFormat;
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryHasBeenLoaded, library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return(false);
            }

            // Copy the library path so that the path can be reported in the case of a failure
            // to resolve the library path. If there is a failure "library" is set to null.
            string path = library;

            if (!pathManager.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format(Properties.Resources.LibraryPathCannotBeFound, path);

                // In the case that a library was explicitly imported using the "File|Import Library" command
                // set the load failed args to not throw an exception if the load fails. This can happen after using
                // File|Import Library and then moving or deleting the library.
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(path, errorMessage,
                                                                   throwOnFailure: !isExplicitlyImportedLib));

                return(false);
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = LibraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = LibraryManagementCore.ClassTable;

                int functionNumber = functionTable.Procedures.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(LibraryManagementCore, library);


                if (LibraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format(Properties.Resources.LibraryBuildError, library);
                    Log(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in LibraryManagementCore.BuildStatus.Errors)
                    {
                        Log(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    throw new Exception(errorMessage);
                }

                LoadLibraryMigrations(library);

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.Procedures.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message,
                                                                   throwOnFailure: !isExplicitlyImportedLib));
                return(false);
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));

            // After a library is loaded, update the library core data with the liveRunner core data
            UpdateLibraryCoreData();
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Import a library (if it hasn't been imported yet).
        /// </summary>
        /// <param name="library"></param>
        public void ImportLibrary(string library, ILogger logger)
        {
            if (null == library)
            {
                throw new ArgumentNullException();
            }

            if (!library.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) &&
                !library.EndsWith(".ds", StringComparison.InvariantCultureIgnoreCase))
            {
                const string errorMessage = "Invalid library format.";
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (importedFunctionGroups.ContainsKey(library))
            {
                string errorMessage = string.Format("Library {0} has been loaded.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            if (!DynamoPathManager.Instance.ResolveLibraryPath(ref library))
            {
                string errorMessage = string.Format("Cannot find library path: {0}.", library);
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                return;
            }

            OnLibraryLoading(new LibraryLoadingEventArgs(library));

            try
            {
                DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

                var functionTable = libraryManagementCore.CodeBlockList[0].procedureTable;
                var classTable    = libraryManagementCore.ClassTable;

                int functionNumber = functionTable.procList.Count;
                int classNumber    = classTable.ClassNodes.Count;

                CompilerUtils.TryLoadAssemblyIntoCore(libraryManagementCore, library);

                if (libraryManagementCore.BuildStatus.ErrorCount > 0)
                {
                    string errorMessage = string.Format("Build error for library: {0}", library);
                    logger.LogWarning(errorMessage, WarningLevel.Moderate);
                    foreach (ErrorEntry error in libraryManagementCore.BuildStatus.Errors)
                    {
                        logger.LogWarning(error.Message, WarningLevel.Moderate);
                        errorMessage += error.Message + "\n";
                    }

                    OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, errorMessage));
                    return;
                }

                var loadedClasses = classTable.ClassNodes.Skip(classNumber);
                foreach (var classNode in loadedClasses)
                {
                    ImportClass(library, classNode);
                }

                var loadedFunctions = functionTable.procList.Skip(functionNumber);
                foreach (var globalFunction in loadedFunctions)
                {
                    ImportProcedure(library, globalFunction);
                }
            }
            catch (Exception e)
            {
                OnLibraryLoadFailed(new LibraryLoadFailedEventArgs(library, e.Message));
                return;
            }

            OnLibraryLoaded(new LibraryLoadedEventArgs(library));
        }