1、参考链接

参考:http://www.cnblogs.com/liulun/archive/2009/05/27/1491116.html

Live Writer API参考:http://msdn.microsoft.com/en-us/library/aa702864.aspx

获取用户名密码参考:http://www.cnblogs.com/xiaoshatian/archive/2010/09/14/1825561.html

经过修改后的项目文件查看如下:LiveWriterPlugin2.7z

2、Live Writer API调用实例

2.1、添加关键引用

using WindowsLive.Writer.Api;
using System.Windows.Forms;
using System.Web;

引用的dll文件在你安装windows live writer的根目录下

名字叫WindowsLive.Writer.Api.dll

2.2、框体类文件

添加一个类文件,此文件程序用来处理用户插入的代码

    public static class ContentProcessor
{
public static string ProcessedContent { get; private set; }
public static void Process(string originalContent)
{
ProcessedContent = (!string.IsNullOrEmpty(originalContent)
?string.Format("<fieldset style=\"background-color:#E0EFF6;color:#15428B\"><pre>{0}</pre></div>", HttpUtility.HtmlEncode(originalContent))
:string.Empty
);
}
}

添加一个windows form窗体,如图:

给确定按钮添加的事件为

        private void button1_Click(object sender, EventArgs e)
{
ContentProcessor.Process(this.textBox1.Text);
this.Close();
}

其中ContentProcessor.Process(this.textBox1.Text);

就是调用的我们上一个类文件中的处理程序

2.2.1、插件类文件

    [WriterPlugin("7c371eef-e350-4aae-af28-91613a9137e3", "xland", Description = "insert code plugin", Name = "xland", PublisherUrl = "http://www.cnblogs.com/liulun")]
[InsertableContentSource("insert code",SidebarText="insert code")]
public class MyPlugin:ContentSource
{
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
new ProcessForm().ShowDialog();
content = ContentProcessor.ProcessedContent;
return (!string.IsNullOrEmpty(content) ? DialogResult.OK : DialogResult.No);
}
}

其中7c371eef-e350-4aae-af28-91613a9137e3为一个GUID

其他的一些信息是插件在live writer中的信息

函数中第一句是创建一个窗口(我们刚才制作的窗口)

第二句获取我们输入的数据(处理过后的数据)

第三句让live writer知道有东西要插入。

content变量是live writer中的,所以要用ref修饰

都完成后只要把生成的dll文件放在live writer安装目录下Plugins文件夹内就可以了

此文章就是用这个插件写的

贴个图看下

2.2.2、插件类文件图标

c#项目中,添加图片到根目录(图片为18*16大小),右键图片属性,生成操作:嵌入的资源,添加ImagePath如下。

    [WriterPlugin("7c371eef-e350-4aae-af28-91613a9137e3", "xland", ImagePath="icon.png",Description = "insert code plugin", Name = "xland", PublisherUrl = "http://www.cnblogs.com/liulun")]
[InsertableContentSource("insert code",SidebarText="insert code")]
public class MyPlugin:ContentSource
{
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
new ProcessForm().ShowDialog();
content = ContentProcessor.ProcessedContent;
return (!string.IsNullOrEmpty(content) ? DialogResult.OK : DialogResult.No);
}
}

2.2.3、源代码下载

LiveWriterPlugin.rar

另外:

我在我的blog中设置了这样的样式

pre { white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ }
* html pre { word-wrap: break-word; /* Internet Explorer 5.5+ */ white-space : normal ; /* Internet Explorer 5.5+ */ }

具体设置方法是,进入你的博客园后台》》》选项》》》config》》》通过CSS定制页面 

这样设置主要是不让代码太宽,撑破页面

 

******************************************************

3、获取用户信息

Windows Live Writer是颇受欢迎的博客客户端,除了支持多种博客服务之外,还具备良好的扩展性,允许第三方开发插件来扩展或补充功能,我也为它开发了两个插件:用来补充Slug的SlugHelper和补充图片Exif信息的ExifInfo

但你有没有想过,虽然这些第三方插件的确为我们提供了方便,但它们真的值得信赖吗?

 

最近搬家,没有网络,闲暇时便用“.NET Reflector”来查看Windows Live Writer的内部实现,期望能找到对我开发插件有帮助的API,没想到却发现了令人大吃一惊的东西,Windows Live Writer插件可以轻而易举地窃取你的博客账号和密码!

想知道是怎么做到的吗?只需要随便开发一个插件,添加对“WindowsLive.Writer.BlogClient.dll”的引用和以下的using:

 

1
using WindowsLive.Writer.BlogClient;

 

在适当的位置添加以下代码:

 

1
2
3
4
5
6
7
8
9
10
11
StringBuilder sb = new StringBuilder();
string[] blogIds = BlogSettings.GetBlogIds();
foreach (string blogId in blogIds)
{
BlogSettings blogSetting = BlogSettings.ForBlogId(blogId);
sb.AppendLine("blogname: " + blogSetting.BlogName);
sb.AppendLine("homepage: " + blogSetting.HomepageUrl);
sb.AppendLine("username: " + blogSetting.Credentials.Username);
sb.AppendLine("password: " + blogSetting.Credentials.Password);
sb.AppendLine("===============================================");
}

 

执行后查看sb.ToString(),你会看到你添加到Windows Live Writer里的所有博客信息,包括博客名称、主页地址、用户名和密码,可怕之处就在于密码是明文的。

如果插件的作者心怀不轨,他完全可以利用这些内容来控制你的博客。所以在使用第三方插件之前,最好能够确定该插件是值得信赖的。

另外,开源的插件也是个不错的选择,你可以检查插件的代码中是否包含泄露隐私的内容,并自行编译使用。

我开发的SlugHelperExifInfo两个插件都是开源项目,欢迎使用。

学习编写Windows Live Writer插件的更多相关文章

  1. windows live writer插件说明文档(附录网盘地址)

    百度云地址:http://pan.baidu.com/s/1hqnjzjY 1.Screen Capture tool 用于直接在WLWriter中进行截图的一个插件,要配合SnagIt 这个软件使用 ...

  2. 编写自己的Windows Live Writer插件

    起因 自从小猪使用Windows Live Writer(wlw)来写博客之后就很少打开网站的后台编辑器了,这真是个写博客的好东西啊,但是任何东西都是不完美的.索契冬奥会开幕式都会把五环弄成四环呢!对 ...

  3. 如何安装Windows Live Writer插件

    Windows Live Writer 是一个强大的离线博客编辑工具,通过它可以离线编辑内容丰富的博文.它不但支持微软的live space,还支持诸如Wordpress 这样的开源博客系统. Win ...

  4. 一次查找Windows Live Writer的VSPaste插件丢失RTF格式信息的经历

    背景 我在博客园上写博客是使用Windows Live Writer,代码高亮插件是使用Paste from Visual Studio(下文简称VSPaste). Windows Live Writ ...

  5. Windows Live Writer介绍及相关问题解决

    今天本来想说更新一篇我的文章,更新的过程中添加了很多的内容,里面的图片太多了,导致我浏览器占用的内存不断增大,浏览器变得很卡,最后过了好久我终于更新完文章打算保存的时候居然卡住,然后所有我更新的文字和 ...

  6. Windows Live Writer代码插件整理

    以下code插件命名按照 Windows Live Writer 中显示的插件名 1.Source code plug-in(cnblogs官方推荐) 界面: 效果: /** * Returns th ...

  7. Windows Live Writer离线编写博客

    WLW最新版本为2012,官网下载 Windows Live Writer配置步骤 使用Windows Live Writer 2012和Office Word 2013 发布文章到博客园全面总结 L ...

  8. Windows Live Writer编写Octopress

    Windows live Writer是一个可以用来离线编写,并发布博客的工具. Octopress是一个静态博客生成系统.使用群体多是geek,主要有显示代码清晰,git同步,并且不用购买空间的特点 ...

  9. Windows Live Writer的Markdown插件MarkdownInLiveWriter支持语法高亮了

    我前几天开发的Windows Live Writer的Markdown的插件MarkdownInLiveWriter支持语法高亮了.参见下图: 基本上就是把我的另一个插件CodeInLiveWrite ...

随机推荐

  1. iOS - OC/Swift:验证手机号/固话用正则表达式

    /** * 验证手机号是否正确 * @param unknown_type $mobile */ OC: - (BOOL)isMobileNumber:(NSString *)mobileNum { ...

  2. hdu 1249 三角形

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1249 part=3*s*(s-1)+2 #include<stdio.h> #includ ...

  3. Java系列笔记(3) - Java 内存区域和GC机制

    目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Garbage Collection, ...

  4. 设计模式学习之策略模式(Strategy,行为型模式)(13)

    转载地址:http://www.cnblogs.com/zhili/p/StragetyPattern.html 一.引言 本文要介绍的策略模式也就是对策略进行抽象,策略的意思就是方法,所以也就是对方 ...

  5. 如何在java中使用别人提供的jar包进行导入,编译,运行

    一步一步往前走, 现在折分! JAR包即为上篇文章的东东. 测试JAVA文件. package com.security; import com.security.AESencrp; /** * 实现 ...

  6. SPOJ220 Relevant Phrases of Annihilation(后缀数组)

    引用罗穗骞论文中的话: 先将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,再将后缀分组.判断的时候,要看是否有一组后缀在每个原来的字符串中至少出现两次,并 ...

  7. 企业QQ 增加在线交谈链接

    企业QQ的在线交流链接跟普通QQ的在线交流不一样,普通QQ的在线交流,可以在http://shang.qq.com/v3/widget.html生成:企业qq的链接可以按以下步骤添加: 第一步:引入企 ...

  8. 2-06使用SQL语句创建数据库3

    向现有数据库中添加文件组和数据文件几种方式以及步骤: 第一种:在视图下添加文件组和数据文件. 添加文件组的步骤: 右击你想要添加文件组的数据库点属性,然后点文件组就可以添加. 添加数据文件的步骤: 下 ...

  9. hdu 4036 2011成都赛区网络赛F 模拟 **

    为了确保能到达终点,我们需要满足下面两个条件 1.能够到达所有山顶 2.能够在遇到苦土豆时速度大于他 二者的速度可以用能量守恒定律做,苦土豆的坐标可通过三角形相似性来做 #include<cst ...

  10. mathematica练习程序(获得股票数据)

    从去年的11月开始,中国的股市就一直大涨,不知道这次能持续多长时间. 为了获得股票数据,我用matlab试了网上的一些方法,总是失败,所以就改用mathematica,一行代码就可以了. DateLi ...