Agile.Net 组件式开发平台 - 驱动开发示例

首先讲一下概念,此驱动非彼驱动。在Agle.Net中我们将组件规划成两种类型,一种是基于业务的窗体组件,一种是提供扩展功能的驱动组件。

打个比方例如一般系统中需要提供身份证读卡功能,然而市面上有很多种身份证读卡器,我们无法约束客户都是用同一种读卡器,为了扩展性我们将身份证读卡功能封装为驱动组件。

那么是用不同的身份证读卡器设备,我们提供相应的封装实现就可以了。下面我来演示一个简单的驱动型组件开发例程。

 

Agile.Net开发管理平台项目,已经托管在开源中国码云平台(http://git.oschina.net

登陆码云平台进入项目主页(http://git.oschina.net/MuAgile/AgileDevelop)即可浏览下载源代码。

 

1.开发环境搭建

   软件安装请参考文章《Agile.Net 组件式开发平台 - 开发环境部署》

   下载项目【AgileDevelop】->【附件】中的数据库备份文件,恢复数据库到SqlServer,建议数据库命名"Agile"。

 

2.获取项目源代码

   1. 启动 Microsoft Visual Studio,进入菜单项【工具】->【选项】->【源代码管理】-> 设置选项【当前源代码管理插件】下拉框中选择【Microsoft Git 提供程序】。        

   2. VS切换到团队资源管理器界面,进入菜单项【项目】->【连接到团队项目】。

   3. 在本地Git存储库栏目中,输入Git项目地址,克隆"AgileDevelop"项目。

   4. 关于Git的源代码管理系统的使用方法,请参考相关文档学习。

 

3.创建第一个驱动

   1. 新建一个类库命名为"Driver.IDCard",框架版本为Net4.0,引用 Agile.Cord.dll , Agile.Entity.dll 等平台SDK库文件。

   2. 新增一个驱动类,继承【Agile.Core.Addin.PluginDriverBase】驱动基类并重写"OnOpen"、"OnClose" 方法。

   3. 添加【PluginAttribute】标签,添加组件描述。

namespace Driver.IDCard
{
    [PluginAttribute("69715891-FBA5-428A-94B1-5C6D5C28926F", "身份证阅读驱动", "华视二代身份证读卡器阅读驱动")]
    public class Driver : Agile.Core.Addin.PluginDriverBase
    {
        private bool _IsOpen;

        /// <summary>
        /// 调用驱动组件并执行方法
        /// </summary>
        /// <param name="args">参数</param>
        /// <returns></returns>
        protected override object OnOpen(object args)
        {
            try
            {
this.Init();
                frmCard frm = new frmCard();
                if (frm.ShowDialog() == DialogResult.OK)
                    return frm.IDCard.ToClone(); else
                    return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.OnClose();
            }
} /// <summary> /// 关闭(卸载)驱动组件 /// </summary> /// <returns></returns> protected override void OnClose() { try
{
SDK.CVR_CloseComm();
}
catch { } } /// <summary> /// 初始化设备连接 /// </summary> /// <returns></returns> private void Init() {
            if (_IsOpen == false)
            {
                int ret = -1;
                for (int port = 1001; port <= 1016; port++)
                {
                    ret = SDK.CVR_InitComm(port); if (ret == 1) break;
                }
                if (ret != 1)
                {
                    for (int port = 1; port <= 4; port++)
                    {
                        ret = SDK.CVR_InitComm(port);
                        if (ret == 1) break;
                    }
                }

                if (ret == 1)
                {
                    _IsOpen = true;
                    return;
                }
                else if (ret == 0)
                    throw new Exception("读卡器连接失败!动态库加载异常。");
                else if (ret == 2)
                    throw new Exception("读卡器连接失败!端口开启异常。");
                else
                    throw new Exception("读卡器连接失败!发生未知异常。");
            }
} } }

 

4.至此一个简单的平台驱动组件已经开发完成了,下面咱们来调用试试看。

private void btn_NoneCard_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    //通过以下四种方式调用驱动组件
    //方式一
    //var driver = Controller.GetIPlugin(Guid.Parse("69715891-FBA5-428A-94B1-5C6D5C28926F")) as IPluginDriver;
    //方式二
    //var driver = Controller.GetIPlugin("Driver.NoneCard.dll", "Driver.NoneCard.Driver", "Drivers") as IPluginDri
    //方式三
    //var driver = Agile.Library.Controller.GetIPlugin("Driver.NoneCard.Driver.Driver") as IPluginDriver;
    //方式四
    var driver = Agile.Library.Controller.GetIPlugin<Driver.IDCard.Driver>() as IPluginDriver;
    IDCard entity = driver.Open();
}

 

OK 运行成功,那么咱们第一个驱动组件【身份证阅读驱动】已经开发好了,Agile.Net开发管理平台中包含本案例完整源代码。

转载于:https://www.cnblogs.com/MuNet/p/6639615.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Agile.net Code Protection - Powerful .NET Code Protection & Obfuscation Solution Agile.NET code protection solution offers better protection for your .NET code by providing a protection that goes beyond standard obfuscation methods. Our advanced code protection technology delivers a layered protection approach that combines our patented code virtualization technology, code encryption, obfuscation, and anti-reverse engineering countermeasures embedded into existing application code. Unbreakable Code Protection Agile.net uses a patented technology that transforms MSIL code into virtual opcodes that will only be understood by a secure virtual machine. The virtual machine processes the virtual opcodes directly, emulating the original code behavior without transforming the code back to its original form. Breaking the protection becomes NP-complete problem, thus making Agile.net the only obfuscator that guarantees your code can't be broken! Next Generation Obfuscator Obfuscates every aspect of your code, including class and method names, managed resources, user strings, methods implementation, system and library calls. Agile.net Protects more of your application than any other obfuscator because it knows what is safe to change and what needs to be left alone. Nevertheless, it gives you full control of the obfuscation process. Works with all .NET Technologies Join our rapidly growing customer base consisting of thousands of customers using Agile.net every day to protect their software running on WinRT, WP7, WP8, .NET 2.0 and up, Compact Framework 2.0 and up, ASP. NET, Silverlight 2.0 and up (XAML), WPF (BAML), XNA, ClickOnce and more
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值