Esempio n. 1
0
        /// <summary>
        /// 创建插件对象。
        /// </summary>
        /// <param name="pluginTree">依附的插件树对象。</param>
        /// <param name="name">插件名称,该名称必须在同级插件中唯一。</param>
        /// <param name="filePath">插件文件路径(完整路径)。</param>
        /// <param name="parent">所属的父插件。</param>
        /// <remarks>创建的插件对象,并没有被加入到<paramref name="parent"/>参数指定的父插件的子集中(<seealso cref="Zongsoft.Plugins.Plugin.Children"/>)。</remarks>
        internal Plugin(PluginTree pluginTree, string name, string filePath, Plugin parent)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            _pluginTree = pluginTree ?? throw new ArgumentNullException(nameof(pluginTree));
            _name       = name.Trim();
            _filePath   = filePath;
            _parent     = parent;
            _isHidden   = string.Equals(Path.GetFileName(filePath), ".plugin", StringComparison.OrdinalIgnoreCase);
            _status     = PluginStatus.None;
            _manifest   = new PluginManifest(this);
            _children   = new PluginCollection(this);
            _builtins   = new List <Builtin>();

            _parsers  = new FixedElementCollection <IParser>();
            _builders = new BuilderElementCollection();
        }
Esempio n. 2
0
        /// <summary>
        /// 创建插件对象。
        /// </summary>
        /// <param name="pluginTree">依附的插件树对象。</param>
        /// <param name="name">插件名称,该名称必须在同级插件中唯一。</param>
        /// <param name="filePath">插件文件路径(完整路径)。</param>
        /// <param name="parent">所属的父插件。</param>
        /// <remarks>创建的插件对象,并没有被加入到<paramref name="parent"/>参数指定的父插件的子集中(<seealso cref="Zongsoft.Plugins.Plugin.Children"/>)。</remarks>
        internal Plugin(PluginTree pluginTree, string name, string filePath, Plugin parent)
        {
            if (pluginTree == null)
            {
                throw new ArgumentNullException("pluginTree");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            _pluginTree = pluginTree;
            _name       = name.Trim();
            _filePath   = filePath;
            _parent     = parent;
            _status     = PluginStatus.None;
            _manifest   = new PluginManifest(this);
            _children   = new PluginCollection(this);
            _builtins   = new List <Builtin>();

            _modules  = new FixedElementCollection <IApplicationModule>();
            _parsers  = new FixedElementCollection <IParser>();
            _builders = new BuilderElementCollection();
        }
Esempio n. 3
0
        private void LoadPlugins(PluginCollection plugins, PluginLoaderSetup settings)
        {
            if (plugins == null || plugins.Count < 1)
            {
                return;
            }

            var stack = new Stack <Plugin>();

            //注意:①. 先加载同级插件
            foreach (var plugin in plugins)
            {
                //确保同级插件栈内的所有插件一定都是未加载的插件
                if (plugin.Status == PluginStatus.Loading)
                {
                    this.TryPushToStack(plugin, stack);
                    this.LoadPlugin(stack, pluginName => plugins[pluginName], settings);
                }
            }

            //注意:②. 再依次加载各个子插件
            foreach (var plugin in plugins)
            {
                if (plugin.Status == PluginStatus.Loaded)
                {
                    this.LoadPlugins(plugin.Children, settings);
                }
            }
        }
        internal PluginLoader(PluginResolver resolver, PluginLoaderSetup setup)
        {
            if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            _resolver = resolver;
            _settings = setup;
            _plugins  = new PluginCollection();
        }
        private void LoadPlugins(PluginCollection plugins, PluginLoaderSetup settings)
        {
            if (plugins == null || plugins.Count < 1)
            {
                return;
            }

            Plugin hidden = null;
            var    stack  = new Stack <Plugin>();

            //注意:①. 先加载同级插件(忽略隐藏式插件)
            foreach (var plugin in plugins)
            {
                //确保同级插件栈内的所有插件一定都是未加载的插件
                if (plugin.Status == PluginStatus.Loading)
                {
                    //如果是隐藏式插件,则先忽略它,放待最后再来加载
                    if (plugin.IsHidden)
                    {
                        hidden = plugin;
                    }
                    else
                    {
                        this.TryPushToStack(plugin, stack);
                        this.LoadPlugin(stack, pluginName => (plugins.TryGet(pluginName, out var found) ? found : null), settings);
                    }
                }
            }

            //注意:②. 再依次加载各个子插件
            foreach (var plugin in plugins)
            {
                if (plugin.Status == PluginStatus.Loaded)
                {
                    this.LoadPlugins(plugin.Children, settings);
                }
            }

            //注意:③. 如果当前层级中含有隐藏式插件,则留待最后再来加载它
            if (hidden != null)
            {
                this.TryPushToStack(hidden, stack);
                this.LoadPlugin(stack, pluginName => (plugins.TryGet(pluginName, out var found) ? found : null), settings);
            }
        }
Esempio n. 6
0
 internal PluginLoader(PluginResolver resolver)
 {
     _resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
     _plugins  = new PluginCollection();
 }