在MSDN上浏览Smart Client时发现了CAB(Composite UI Application Block) ,一下被它的描述吸引了,下载后扫了一遍源代码,的确是值得好好研究一番,以后的开发中就用它了。
今天学习了Lab 1: Introduction to Developing with the Composite UI Application Block 。感觉界面的组合布局上和ASP.NET2.0中的WebParts有点类似(对webparts只是了解一点,没用过:D).这样在对付一些复杂界面时的确会方便许多。由于对Inversion of Control (IOC) 和 Dependency Injection 不太了解,所有看起来还是很费劲的。只好先照着例子试验一下,先有个感性的认识再说。
在这个例子中对GPSModule的调用是通过ProfileCatalog.xml的配置来实现的。我想如果用户损坏了此配置文件怎么办?是不是自己做个维护配置文件小工具,可以通过可视界面来初始化、修改配置信息较好。
今天了解了一下内容:
1、模块配置文件名必须是ProfileCatalog.xml吗?
通过跟踪program.Run()发现在基类CabApplication的Sub Run()中调用LoadModules()时加载默认的配置文件名是在SolutionProfileReader类中定义的:
Private innerCatalogFilePath As String = DefaultCatalogFile
''' <summary>
''' The default profile to use if no profile is specified.
''' </summary>
Public Const DefaultCatalogFile As String = "ProfileCatalog.xml"
''' <summary>
''' Initializes a new instance which will use the <see cref="DefaultCatalogFile"/> as
''' the solution profile.
''' </summary>
Public Sub New()Sub New()
End Sub
''' <summary>
''' Initializes a new instance that will use the specified file as the solution profile.
''' </summary>
''' <param name="catalogFilePath">The path to the solution profile. This file must be
''' located under the application folder.</param>
Public Sub New()Sub New(ByVal catalogFilePath As String)
Me.innerCatalogFilePath = GetFullPathOrThrowIfInvalid(catalogFilePath)
End Sub
'其他...
End Class
此类的重载构造函数Sub New(ByVal catalogFilePath As String)说明还是可以修改配置文件名的。
2、服务的两种加载类型
a)在CabApplication的Sub LoadModules()调用时自动加载到内存中。
b) 在服务被首次调用时才加载。
需要在服务类增加属性并指定AddOnDemand为True , 比如:
< Service( GetType (IDistanceCalculatorservice), AddOnDemand: = True ) > _
Public Class DistanceCalculatorservice Class DistanceCalculatorservice
Implements IDistanceCalculatorservice
Public Function ComputeDistance()Function ComputeDistance(ByVal latitude As Integer, ByVal longitude As Integer) As Integer Implements IDistanceCalculatorservice.ComputeDistance
Return 1234
End Function
End Class
3、GPSWorkItem中显示GPSView的WorkSpace控件名称必须和主界面中DeckWorkspace控件的Name一致,是否可以通过配置取消这种硬编码上的依赖?
Inherits WorkItem
Protected Overrides Sub OnRunStarted()Sub OnRunStarted()
MyBase.OnRunStarted()
'“MainWorkspace”为主窗体中DeckWorkspace的Name
Dim GPSWorkspace As IWorkspace = Workspaces("MainWorkspace")
GPSWorkspace.Show(Items.AddNew(Of GPSView)())
End Sub
End Class
4、可以把一个Form显示到WorkSpace中吗?
可以的,但是需要在Form的构造函数中设置窗体的TopLevel=False 。
Public Sub New()Sub New()
' 此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
' 在 InitializeComponent() 调用之后添加任何初始化。
'必须将TopLevel设置成False才能将此窗体添加到WorkSpace中
Me.TopLevel = False
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Dock = Windows.Forms.DockStyle.Fill
End Sub
End Class
Public Class GPSWorkItem Class GPSWorkItem
Inherits WorkItem
Protected Overrides Sub OnRunStarted()Sub OnRunStarted()
MyBase.OnRunStarted()
'“MainWorkspace”为主窗体中DeckWorkspace的Name
Dim GPSWorkspace As IWorkspace = Workspaces("MainWorkspace")
GPSWorkspace.Show(Items.AddNew(Of Form1)())
End Sub
End Class
时间不早了,天亮了还要出差去奉贤,过去又不能上网咯,等下周回来了再研究吧!