插件开发--BE插件开发

U9的插件主要分为3种,即
(1)BE插件
(2)UI插件
(3)BP/SV插件

1.新建类库解决方案


2.新建插件类,并引用以下dll,UBF安装目录U9.VOB.Product.UBF\UBFStudio\Runtime
UFSoft.UBF.Analysis.Exceptions.dll
UFSoft.UBF.Business.dll
并继续接口UFSoft.UBF.Eventing.IEventSubscriber


3.实现接口代码,以之前做过的礼品单据作为插件对象,则要引入礼品单据的BE的dll,并复制以下代码,据实际情况实现逻辑

class GiftDocBEPlugExtend : UFSoft.UBF.Eventing.IEventSubscriber
    {

        public void Notify(params object[] args)
        {
            //throw new NotImplementedException();
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
            {
                return;
            }

            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
            {
                return;
            }

            //以下代码实现业务逻辑
            HomaGiftDoc doc = key.GetEntity() as HomaGiftDoc;
            if (doc == null)
            {
                return;
            }

            if (doc.DocNo == "")
            {
                throw new Exception("单号不能为空!");
            }

            for (int i = 0; i < doc.HomaGiftDocLine.Count; i++)
            {
                if (doc.HomaGiftDocLine[i].ItemQty <= 0)
                {
                    throw new Exception("" + doc.HomaGiftDocLine[i].RowNo + "数量不能小于0!");
                }
            }
        }
    }
插件实现代码

 

4.编译后,据错误分别引用需要的dll




5.配置文件,配置文件命名建议以命名空间作为前缀,后缀必须为.sub.xml


6.配置文件节点说明
Homa.test.ch01.GiftDocBE.sub.xml

<?xml version="1.0" encoding="utf-8" ?>
<pub-sub>
  <subcription event="Homa.test.ch01.GiftDocBE.HomaGiftDoc.Validate">
    <subscriber type="GiftDocPlug.GiftDocBEPlugExtend,GiftDocPlug.dll" />
  </subcription>
</pub-sub> 

event:为调用的实体(Homa.test.ch01.GiftDocBE.HomaGiftDoc)+触发事件(如:Validate、Inserting、Inserted、Updating、Updated)
type:命名空间+类名,程序集dll名(命名空间.dll)


7.部署插件
(1)拷贝生成的dll至Portal\ApplicationServer\Libs
(2)拷贝配置文件至Portal\bin


8.最后看看运行效果

posted @ 2015-06-25 17:28  --宁静以致远--  阅读(1463)  评论(0编辑  收藏  举报