Пример #1
0
        /// <summary>
        /// Attempts to load the specified plugin.  If the plugin is already loaded, this
        /// does nothing.  If not, the assembly is loaded an an instance is created.
        /// </summary>
        /// <param name="scriptIdent">Script identifier.</param>
        /// <param name="report">Report with errors and warnings.</param>
        /// <returns>True on success.</returns>
        public bool LoadPlugin(string scriptIdent, out FileLoadReport report)
        {
            // Make sure the most recent version is compiled.
            string dllPath = PluginDllCache.GenerateScriptDll(scriptIdent,
                                                              mProject.ProjectPathName, out report);

            if (dllPath == null)
            {
                return(false);
            }

            if (DomainManager == null)
            {
                if (mActivePlugins.TryGetValue(scriptIdent, out IPlugin plugin))
                {
                    return(true);
                }
                Assembly asm = Assembly.LoadFile(dllPath);
                plugin = PluginDllCache.ConstructIPlugin(asm);
                mActivePlugins.Add(scriptIdent, plugin);
                report = new FileLoadReport(dllPath);       // empty report
                return(true);
            }
            else
            {
                IPlugin plugin = DomainManager.PluginMgr.LoadPlugin(dllPath, scriptIdent);
                return(plugin != null);
            }
        }
Пример #2
0
        /// <summary>
        /// Attempts to load the specified plugin.  If the plugin is already loaded, this
        /// does nothing.  If not, the assembly is loaded and an instance is created.
        /// </summary>
        /// <param name="scriptIdent">Script identifier.</param>
        /// <param name="report">Report with errors and warnings.</param>
        /// <returns>True on success.</returns>
        public bool LoadPlugin(string scriptIdent, out FileLoadReport report)
        {
            // Make sure the most recent version is compiled.
            string dllPath = PluginDllCache.GenerateScriptDll(scriptIdent,
                                                              mProject.ProjectPathName, out report);

            if (dllPath == null)
            {
                return(false);
            }

            if (DomainMgr == null)
            {
                if (mActivePlugins.TryGetValue(scriptIdent, out IPlugin plugin))
                {
                    return(true);
                }
                Assembly asm = Assembly.LoadFile(dllPath);
                plugin = PluginDllCache.ConstructIPlugin(asm);
                mActivePlugins.Add(scriptIdent, plugin);
                report = new FileLoadReport(dllPath);       // empty report
                return(true);
            }
            else
            {
                CheckHealth();
                IPlugin plugin = DomainMgr.PluginMgr.LoadPlugin(dllPath, scriptIdent,
                                                                out string failMsg);
                if (plugin == null)
                {
                    report.Add(FileLoadItem.Type.Error, "Failed loading plugin: " + failMsg);
                }
                else
                {
                    mLoadedPlugins.Add(new LoadedPluginPath(scriptIdent, dllPath));
                }
                return(plugin != null);
            }
        }