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

推荐订阅源

人人都是产品经理
人人都是产品经理
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】
Webroot Blog
Webroot Blog
小众软件
小众软件
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Cloudbric
Cloudbric
AI
AI
WordPress大学
WordPress大学
博客园 - 聂微东
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
博客园 - Franky
V
V2EX
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
H
Help Net Security
量子位
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recorded Future
Recorded Future
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
C
Cisco Blogs
S
Security Affairs

博客园 - Timothy Ye

扩展方法使用小结 IIS7中Host WCF遇到的问题 博客园字体美化小技巧 - Timothy Ye - 博客园 个人闲置物品挥泪处理(8月27日更新) Visual Studio IDE配色方案 HTC Touch Pro 的重力感应功能 C# IDE Mobile – Write your C# code anywhere! Visual Studio 2010 Beta1 is available for download 小黑降温记 Windows 7 新特性体验 Unity 学习笔记(3) -- 生命周期管理 换了新鼠标 Unity 学习笔记(2) -- 配置文件的使用 Unity 学习笔记(1) -- Unity简介及简单使用 Microsoft My Phone 体验 SQL中的日期计算 快速开启、屏蔽Vista下的UAC提示 Dynamic Plugins Manager (五) Plugins Manager 源码下载 Dynamic Plugins Manager (四) 插件及Demo源码下载
Dynamic Plugins Manager (三) Demo
Timothy Ye · 2008-12-11 · via 博客园 - Timothy Ye

2008-12-11 12:26  Timothy Ye  阅读(359)  评论()    收藏  举报

下面来演示一下Plugins Manager,先看看我们事先做好的Interface和两个具体实现的插件.

   Interface,接口定义:

程序代码 程序代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Component
{
    public interface IComponent
    {
        string Invoke();
    }
}

    整个接口,只声明了一个Invoke方法,这也是具体的插件必须实现的一个方法。

   第一个插件类 class1.cs

程序代码 程序代码

    namespace Component
{

    public class Class1 : MarshalByRefObject,IComponent
    {
        string message = string.Empty;
        int number;
        float number2;

        public Class1(string input, int num)
        {
            message = input;
            number = num;
            number2 = 0;
        }

        public Class1(int num1, float num2)
        {
            message = "none";
            number = num1;
            number2 = num2;
        }

        public string Invoke()
        {
            return "This is TestLibrary. member---message:" + message + "number:" + number.ToString() + "number2:" +number2.ToString();
        }
    }
}

    第二个插件类 class2.cs

程序代码 程序代码

namespace Component
{
    public class Class2 : MarshalByRefObject,IComponent
    {
        public Class2()
        {
        }

        public string Invoke()
        {
            return "This is TestLibrary2 without construct param";
        }
    }
}

    这里我们看到区别,第一个插件,需要构造函数,第二个插件不需要构造函数,所以在配置文件中,第二个插件可以关闭掉ConstructParam这个节点。

   下面我们将Class1.cs编译好,放到插件目录中,改名为TestLibrary.dll,将Class2.cs直接改名为TestLibrary2.cs,放到插件目录中。
   演示的目的:插件1需要在加载时,构造初始化函数,而插件2不需要。
               插件1,是已经编译好的dll,不需要实时编译,但是插件2需要。

   下面是测试的截图

   1.插件目录,一个放入编译好的dll,一个放入.cs源码
  

     2.启动测试程序,看到2个插件都已经被加载

     3.此时,再查看插件的目录,我们会看到Plugin Manager为我们编译,并生成的插件2的dll

   4.查看插件的日志记录

   5.插件的调用
   选中TestLibrary,点击Invoke按钮:

  选中TestLibrary2,点击Invoke按钮:

   6.插件的动态卸载和发布
     a.动态卸载,可以直接使用Plugins Manager的UnloadPluginByName直接通过程序调用卸载。也可以手动打开插件的配置文件,将EnablePlugin设置为False
       b.动态发布,直接在插件目录中,建立一个新的子目录,然后将插件的dll和xml配置文件直接拷入即可
     关于第6点,这些功能的演示,截图比较麻烦,大家可以直接使用测试程序测试即可。