/// <summary> /// 寻找合适的书籍输出器。 /// </summary> /// <param name="bookToken">书籍节点。</param> /// <returns>支持指定书籍节点的书籍输出器。</returns> /// <exception cref="NotSupportedException">未找到支持节点的小说下载插件。</exception> /// <exception cref="NotSupportedException">不支持的插件类型。</exception> protected internal IBookWriter FindBookWriterForBookToken(NDTBook bookToken) { NovelDownLoadPluginBookTokenAttribute attribute = bookToken.GetType().GetCustomAttribute <NovelDownLoadPluginBookTokenAttribute>(true); if (attribute == null) { throw new NotSupportedException("未找到支持节点的小说下载插件。"); } // 获取已注册的插件实例。 if (this.Plugins.TryGetValue(attribute.PluginGuid, out IPlugin plugin) && plugin is INovelDownloadPlugin ndPlugin) { if (!this.BookWriters.TryGetValue(ndPlugin.Guid, out IBookWriter bookWriter)) // 尝试从已注册的书籍输出器中寻找。 { // 指定插件未注册书籍输出器,采用默认书籍输出器。 if (ndPlugin is ILightNovelDownloadPlugin) { bookWriter = new LightNovelBookWriter(); } else { bookWriter = new NormalBookWriter(); } } // 组装组件。 var catalog = new TypeCatalog(typeof(NovelDownloadPluginBase), typeof(BookWriterBase), typeof(PluginManager)); var container = new CompositionContainer(catalog); container.ComposeParts(plugin, bookWriter, this); return(bookWriter); } else { throw new NotSupportedException("不支持的插件类型。"); } }