惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
博客园 - Franky
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
小众软件
小众软件
Jina AI
Jina AI
L
Lohrmann on Cybersecurity
罗磊的独立博客
I
Intezer
W
WeLiveSecurity
T
Tenable Blog
Cyberwarzone
Cyberwarzone
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Securelist
Recent Announcements
Recent Announcements
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
S
SegmentFault 最新的问题
S
Security Affairs
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Register - Security
The Register - Security
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
L
LINUX DO - 最新话题
F
Fortinet All Blogs
雷峰网
雷峰网
Security Latest
Security Latest
大猫的无限游戏
大猫的无限游戏
P
Palo Alto Networks Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】

博客园 - 拖鞋不脱

【原】Silverlight内存泄漏原因、检测及解决(Memory Leak of Silverlight:Reason、Detection and Solving) 【随】不好用的Ria Services 【原】检测是否包含特定字符串的几种方法以及性能比较 【原】StreamInsight 浅入浅出(六)—— Debugger 【原】StreamInsight 浅入浅出(五)—— LINQ 语法 【原】StreamInsight 浅入浅出(四)—— 例子 【原】StreamInsight 浅入浅出(三)—— 适配器 【原】StreamInsight 浅入浅出(二)—— 流与事件 【原】Silverlight 自定义控件模板管理 【原】StreamInsight 浅入浅出(一)—— 基本概念 【原】小软件开发心得(二)——推广、测试 【原】小软件开发心得(一)——需求、开发 【原】豆瓣电台桌面版——Win7任务栏支持+托盘+快捷键+历史记录 【原】Sql Server性能优化——Slide Window 【原】Sql Server性能优化——Partition(管理分区) 【随】Silverlight请求服务的缓存文件问题 【原】Sql Server性能优化——Partition(创建分区) 【原】Sql Server性能优化——Compression 【译】VS2010中C#的增强
【原】豆瓣电台桌面版插件开发——搜索插件
拖鞋不脱 · 2010-06-10 · via 博客园 - 拖鞋不脱

【原】豆瓣电台桌面版插件开发——搜索插件

2010-06-10 21:30  拖鞋不脱  阅读(2353)  评论()    收藏  举报

豆瓣电台桌面版之所以在3.0之后采用了插件架构,一方面是为了练手,而更主要是为了方便。方便用户使用,方便我的开发和发布,更是要方便其他有需求的同学的扩展和二次开发。

观察豆瓣电台桌面版的插件管理界面,就可以发现事实上插件也分几种,目前包括“搜索插件”、“过滤插件”、“歌曲处理”、“历史记录”等几种插件。其中“搜索插件”最为简单,目前接口也比较完善,而且可能用户的需求差异也会比较大,所以先放出“搜索插件”的开发方法。

准备工作

首先是下载豆瓣电台桌面版最新版,在下载下来的压缩包中找到Slippor.Common.PluginFramework.dll、Slippor.Douban.Radio.Search.dll这两个dll。

然后新建一个Class Library工程,建议取名为XXSearchPlugin,并添加上述两个dll的引用到新建的工程中。至此,准备工作完成。

开发搜索引擎插件

一个搜索引擎插件能有多简单?只需要两个类!

其中一个类继承Slippor.Douban.Radio.Search下的BaseSearch基类(这是一个应用了ISearch接口的类,已经实现了所有的方法,只需要提供几个字段的信息即可)。以巨鲸搜索为例,JuJingSearch是这样的:

using Slippor.Douban.Radio.Search;

namespace JuJingSearchPlugin
{
    public class JuJingSearch : BaseSearch
    {
        public JuJingSearch()
        {
            _searchUrl = "http://www.top100.cn/search/index.aspx?keyword={0}";
            _name = "巨鲸";
            _encoder = "utf-8";
        }
    }
}

这里有三个字段:_searchUrl就是搜索引擎的搜索特征Url,“{0}”是搜索关键字的占位符;_name是显示名称;_encoder是对搜索关键字的编码字符集,默认为“gb2312”。

除此之外,还需要一个插件类,用于提供插件的相关信息,同样很简单:

using System.ComponentModel;
using Slippor.Common.PluginFramework;
using Slippor.Douban.Radio.Search;

namespace JuJingSearchPlugin
{
    [Description("巨鲸搜索引擎")]
    [DisplayName("巨鲸搜索")]
    [Author("拖鞋不脱")]
    [Version("1.0.0.0")]
    [PluginCategory(PluginCategory.Search)]
    public class JuJingSearchPlugin : SearchPlugin
    {
        protected override ISearch Search
        {
            get { return new JuJingSearch(); }
        }
    }
}

继承了SearchPlugin类,只需实现Search属性就可以了。这里面看起来字数比较多的是类前面的特性“Attribute”标注。各个Attibute的含义都很明了,其中PluginCategory用于指明这个插件是属于哪个类型的插件,这里当然是PluginCategory.Search了。

小提示

正如我之前所说,BaseSearch实现了ISearch接口,而对于相应的SearchPlugin类来说,要实现的Search属性也只要应用了ISearch接口即可。那么当然可以让搜索引擎类直接应用ISearch接口,具体实现方式就不细述了,只提醒一下可能需要引用Slippor.Douban.Radio.Assist.dll这个dll。

备注

这里只放出搜索插件的开发方法是因为目前只有这类插件的接口比较稳定,其余的有待进一步稳定。当然也可以茶余饭后挑几个dll自己研究下,很简单的,尤其是配合reflector大杀器之后。

如果有童鞋开发的插件愿意共享出来,十分欢迎。请将源代码发予我,我会在检测之后发布在豆瓣电台桌面版——插件大全中。之所以必须是源代码,是出于安全的考虑,请大家谅解。