/// <summary> /// 构建第一级的所有插件。 /// </summary> /// <returns>第一级的所有插件列表。</returns> public IAddin[] BuildFirstLevelAddins() { if (!_isInit) { throw new InvalidOperationException("Need initialize"); } IList <IAddin> addins = new List <IAddin>(); BuildImpl(_root.GetChilds()[0], ref addins); return(addins.ToArray()); }
/// <summary> /// 获取节点的子插件实例。 /// </summary> /// <param name="node">节点。</param> /// <returns>子节点列表。</returns> private IAddin[] GetChildsImpl(AddinTreeNode node) { ReadOnlyCollection <AddinTreeNode> items = null; if (node.IsVirtual || node.Exposes == null) { return(new IAddin[0]); } IList <IAddin> addins = new List <IAddin>(); Lazy <AddinDescriptor> temp = null; foreach (String expose in node.Exposes) { items = node.GetChilds(expose); if (items == null) { continue; } foreach (AddinTreeNode item in items) { if (item.IsVirtual) { continue; } temp = ((AddinNode)item).Descriptor; if (temp.IsValueCreated && temp.Value.BuildState == AddinBuildState.Build) { addins.Add(temp.Value.Addin); } } } return(addins.ToArray()); }
/// <summary> /// 构建节点的插件实例。 /// </summary> /// <param name="node">节点。</param> /// <param name="addins">构建完成的插件。</param> private void BuildImpl(AddinTreeNode node, ref IList <IAddin> addins) { ReadOnlyCollection <AddinTreeNode> items = null; if (node.Exposes == null) { return; } foreach (String expose in node.Exposes) { items = node.GetChilds(expose); if (items == null) { continue; } foreach (AddinTreeNode item in items) { if (item.IsVirtual) { BuildImpl(item, ref addins); } else { try { addins.Add(((AddinNode)item).Buid()); } catch (Exception ex) { } } } } }
/// <summary> /// 初始化插件管理器。 /// </summary> /// <param name="configFile">配置文件。</param> /// <param name="initExposes">初始化挂载点。</param> public void Initialize(String configFile, Tuple <String, String, String[]>[] initExposes = null) { if (_isInit) { return; } if (String.IsNullOrWhiteSpace(configFile)) { throw new ArgumentNullException("configFile"); } configFile = AddinManager.GetFileFullPath(configFile); if (!File.Exists(configFile)) { throw new FileNotFoundException(configFile); } ConfigFile = configFile; _root = new RootNode(); _nodes.Add(_root.FullPath, _root); _nodes.Add(_root.GetChilds()[0].FullPath, _root.GetChilds()[0]); _nodes.Add(_root.GetChilds()[1].FullPath, _root.GetChilds()[1]); CreateAddinTreeNodes(initExposes); GenerateAddinTree(); _isInit = true; }