在使用 OSGI.NET进行插件式的开发时,需要对 Mainfest.xml 进行配置, Mainfest 文件是插件的重要配置文件,其中暴露了插件启动方式以及插件启动时所依赖的程序集或其它资源的信息.一个完整的Mainfest 文件的信息如下

<?xml version="1.0" encoding="utf-8"?>
<Bundle xmlns="urn:uiosp-bundle-manifest-2.0" Name="Wisdo.HomePlugin" SymbolicName="Wisdo.HomePlugin" Version="1.0.0.0" InitializedState="Active" StartLevel="3">
  <Activator Type="Wisdo.HomePlugin.BundleActivator" Policy="Immediate" />
  <Runtime>
    <Assembly Path="bin/Wisdo.HomePlugin.dll" Share="false" />
    <Assembly Path="bin\Wisdo.EFDataModels.dll" Share="false" />
    <Assembly Path="bin\Wisdo.Commons.dll" Share="false" />
    <Assembly Path="bin\EntityFramework.dll" Share="false" />
    <Dependency BundleSymbolicName="UIShell.NavigationService" Resolution="Mandatory" />
    <Dependency BundleSymbolicName="UIShell.PermissionService" Resolution="Mandatory" />
    <Dependency BundleSymbolicName="UIShell.PageFlowService" Resolution="Mandatory" />
  </Runtime>
  <Extension Point="PageFlowService.PageNode">
    <PageNode Name="LoginPage" Priority="30" Value="~/Wisdo.HomePlugin/Hello/Index" />
  </Extension>
</Bundle>

 节点 Bundle 描述插件名称[Name] xml 文件架构[xmlns] 对应的命名空间名字[SymbolicName] 版本号[]Version  以及激活状态[InitializedState]

 节点 Activator 描述插件启动时所要调用的激活器[Type], 以及启动的方式[Policy] 另外还有个属性 Level 表示启动的顺序,默认是2,最大是50,数字越小,启动的越早

 Runtime 节点定义了插件启动时所需要的资源:

[Assembly] 表示所依赖的本地的程序集,一般指向插件的bin 目录,

[Dependency] 表示依赖的其它的插件,类型是 xml 文件,也是就其它插件的 Mainfest .xml 文件

Extension 是扩展,表示对插件进行扩展 ,其中的属性 Point 是定义的扩展点

 [PageNode] 表示在插件页面上的一些导航节点,即一个超连接,可以连接到另外一个页面上

 

接下来看看 Activator 激活器的定义

using System;
using System.Collections.Generic;
using System.Text;
using UIShell.OSGi;
using UIShell.PageFlowService;
using UIShell.PermissionService;

namespace Wisdo.HomePlugin
{
    public class BundleActivator : IBundleActivator
    {
        public static AppNavigationModel NavigationModel { get; private set; }
        public static IBundle Bundle { get; private set; }
        public static ServiceTracker<IPermissionService> PermissionServiceTracker { get; private set; }
        public static ServiceTracker<IPageFlowService> PageFlowServiceTracker { get; private set; }

        public static PageNode LayoutPageNode
        {
            get
            {
                return PageFlowServiceTracker.DefaultOrFirstService.GetPageNode("LayoutPage");
            }
        }

        public void Start(IBundleContext context)
        {
        // 插件启动的相关内容  比如 打开数据库连接
            Bundle = context.Bundle;
            NavigationModel = new AppNavigationModel(context.Bundle);
            PermissionServiceTracker = new ServiceTracker<IPermissionService>(context);
            PageFlowServiceTracker = new ServiceTracker<IPageFlowService>(context);
        }

        public void Stop(IBundleContext context)
        {
           // 插件停止的相关内容 比如 翻译数据库连接
        }
    }
}

 

posted on 2015-12-13 13:57  wisdo  阅读(581)  评论(0编辑  收藏  举报