VB.NET动态插件组件 [英] VB.NET dynamic plugin components

查看:298
本文介绍了VB.NET动态插件组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是一个VB开发人员,但我领导着在VB中部分使用了大量的项目。其中一项要求是实现插件架构,支持动态可扩展的应用程序的核心。

I am not a VB developer but I am heading up a large project in which VB is partially used. One of the requirements is to implement a plugin architecture to support dynamically extendable application core.

我们的VB开发人员似乎认为它可以存储在BLL的DLL - 保持接口都在原来的核心应用 - 使之无用,直至扩展安装

Our VB developer seems to think its possible to store the BLL in a DLL - keeping the interface all in the original core application - rendering it useless until the extensions are installed.

显然,这是不太理想。我想知道它是否能够保持整个子应用程序/组件在不同的DLL加载到核心平台???

Obviously this is less than ideal. I would like to know whether its possible to keep the entire sub application/component in a distinct DLL load it into the core platform???

任何想法?

推荐答案

这是不是问题的了,看看我的例子code。 这是存在于单独的DLL抽象类:

This is not problem at all, take a look at my sample code. Here is abstract class that exists in separate dll:

public abstract class ServerTask
{
    public int TaskId { get; set;}

    /// <summary>
    /// Gets description for ServerTask
    /// </summary>
    public abstract string Description { get; }


}

这是由插件实现code:

This is code from plugin implementation:

public class SampleTask : GP.Solutions.WF.Entities.Tasks.ServerTask
{

    public override string Description
    {
        get 
        {
            return "Sample plugin";
        }
    }

}

最后起价核心应用程序C $ C加载插件:

And finally code from core application that loads plugin:

    /// <summary>
    /// Loads Plugin from file
    /// </summary>
    /// <param name="fileName">Full path to file</param>
    /// <param name="lockFile">Lock loaded file or not</param>
    /// <returns></returns>
    static Entities.Tasks.ServerTask LoadServerTask(string fileName, bool lockFile, int taskId)
    {
        Assembly assembly = null;
        Entities.Tasks.ServerTask serverTask = null;
        if (lockFile)
        {
            assembly = System.Reflection.Assembly.LoadFile(fileName);
        }
        else
        {
            byte[] data = Services.Common.ReadBinaryFile(fileName);
            assembly = System.Reflection.Assembly.Load(data);
        }
        Type[] types = assembly.GetTypes();
        foreach (Type t in types)
        {
            if (t.IsSubclassOf(typeof(Entities.Tasks.ServerTask)))
            {
                serverTask = (Entities.Tasks.ServerTask)Activator.CreateInstance(t);
                serverTask.TaskId = taskId;
                break;
            }
        }
        if (serverTask == null)
        {
            throw new Exception("Unable to initialize to ServerTask type from library '" + fileName + "'!");
        }
        return serverTask;
    }

如果您不熟悉C#只是用C#VB.NET的在线转换器。

If you are not familiar with c# just use c# to vb.net online converter.

快乐编码和最诚挚的问候! 格雷戈尔PRIMAR

Happy coding and best regards! Gregor Primar

这篇关于VB.NET动态插件组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆