Lotus & VB.NET(5):Session,Database and DbDirectory

水如烟 2009-07-11 11:20:31
一般用到的几个对象
...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
HanMo 2009-08-31
  • 打赏
  • 举报
回复
结帐
水如烟 2009-07-11
  • 打赏
  • 举报
回复
UserName.vb
Namespace LzmTW.Lotus
Public Class UserName
Inherits LzmTW.uSystem.IComClassBase(Of IName)

Friend Sub New(ByVal user As IName)
MyBase.New(user)
End Sub

End Class
End Namespace


Session.vb
Namespace LzmTW.Lotus
Public Class Session
Inherits LzmTW.uSystem.IComClassBase(Of ISession)
Private user As UserName

Friend Sub New(ByVal session As ISession)
MyBase.New(session)
If Me.IsValid Then
user = New UserName(Me.com.UserNameObject)
End If
End Sub

Public ReadOnly Property UserName() As UserName
Get
Return user
End Get
End Property

Public Function OpenLocalDatabase(ByVal database As String) As Database
Return Me.OpenDatabase(Nothing, database)
End Function

Public Function OpenServerDatabase(ByVal database As String) As Database
Return Me.OpenDatabase(Notes.Environment.Server, database)
End Function

Public Function OpenDatabase(ByVal server As String, ByVal database As String) As Database
Dim db As IDatabase
db = Me.com.GetDatabase(server, database, False)
Return New Database(db)
End Function

Public Function GetLocalDirectory() As DbDirectory
Return New DbDirectory(Me.com.GetDbDirectory(Nothing))
End Function

Public Function GetServerDirectory() As DbDirectory
Return New DbDirectory(Me.com.GetDbDirectory(Notes.Environment.Server))
End Function

Protected Overrides Sub ReleaseOtherComsBeforeReleaseMainCom()
If Not Me.user Is Nothing Then
Me.user.Dispose()
End If
End Sub

End Class
End Namespace
水如烟 2009-07-11
  • 打赏
  • 举报
回复
DbDirectory.vb
Namespace LzmTW.Lotus
Public Class DbDirectory
Inherits LzmTW.uSystem.IComClassBase(Of IDbDirectory)

Friend Sub New(ByVal directory As IDbDirectory)
MyBase.New(directory)
End Sub

Public Function GetFirstDatabase(Optional ByVal type As DB_TYPES = DB_TYPES.NOTES_DATABASE) As Database
Return New Database(Me.com.GetFirstDatabase(type))
End Function

Public Function GetNextDatabase() As Database
Return New Database(Me.com.GetNextDatabase)
End Function

Public Sub ForEachDatabase(ByVal action As Action(Of Database), Optional ByVal type As DB_TYPES = DB_TYPES.NOTES_DATABASE)
Dim db As Database = Me.GetFirstDatabase(type)
While Not db.com Is Nothing
action(db)
db = Me.GetNextDatabase
End While
End Sub

End Class
End Namespace


Database.vb
Namespace LzmTW.Lotus
Public Class Database
Inherits LzmTW.uSystem.IComClassBase(Of IDatabase)

Sub New(ByVal database As IDatabase)
MyBase.New(database)
End Sub

Public Function CanOpen() As Boolean
If Me.Com Is Nothing Then Return False

If Not Me.Com.IsOpen Then
Try
Me.Com.Open()
Catch ex As Exception
End Try
End If

Return Me.Com.IsOpen
End Function


End Class
End Namespace


DLL的动态下载运行[返回] 中国计算机报2000年第21期 DLL的动态下载运行 业 宁   Lotus Domino 是网络上先进的群件和电子邮件服务器,与客户端应用 Lotus Notes 相配合,具有灵活的安全模式,支持任意大小的多企业构架,全域范围的搜索服务,支持对绝大部分企业系统级的实时访问,功能非常强大。但尺有所短,寸有所长,有时我们需要编制一些DLL来弥补其不足。但问题是这些DLL需要在本地机器上运行,我们不能手工地在每台机器上做拷贝,如果单位很大,工作站很多,或者有远程工作站,那么维护的工作量将非常巨大。下面介绍一种从Domino服务器上动态下载DLL到本地机器运行的方法。   使用操作系统的DLL   如果这些DLL是本地系统自己的API,则直接调用,这里我们举一个例子来说明。   我们要求程序运行时判断本地系统时间,如果系统时间是1999年9月9日,则要求系统退出。   1.在Declarations中,我们定义:   Rem 声明一个SYSTEMTIME的结构   Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer   End Type    Const WM—CLOSE = &H10   声明过程或函数,它们都是kernel32.dll 或user32.dll中的API。   Declare Sub GetLocalTime Lib ″kernel32″Alias ″GetLocalTime″ (lpSystemTime As SYSTEMTIME)   Declare Function GetActiveWindow Lib ″user32″ Alias ″GetActiveWindow″ () As Long   Declare Function CloseWindow Lib ″user32″ Alias ″CloseWindow″ (Byval hwnd As Long) As Long   Declare Function PostMessage Lib ″user32″ Alias ″PostMessageA″ (Byval hwnd As Long, Byval wMsg As Long, Byval wParam As Long, Byval lParam As Long) As Long   2.在Initialize事件中,我们键入如下代码:   Dim stime As SYSTEMTIME Dim hwnd As Long    Rem 取得当前活动窗口的句柄 hwnd=GetActiveWindow() Rem 取系统时间保存在SYSTEMTIME结构中    Call GetLocalTime(stime) If(stime.wyear=1999) And stime.wmonth=9 And stime.wDay=9 Then Messagebox(″谢谢使用!″,MB—OK+16,″再见″)    Rem 退出Notes Call postmessage(hwnd,WM—CLOSE,0,0) End If   使用用户编制的DLL   如果是用户编制的DLL,则调用起来稍微麻烦一点,因为本地机器上可能没有DLL,这就需要把它下载到本地。   可以在需要DLL的Notes数据库中增加一个表单或者在表单中增加一个域用于保存DLL。下面的这个例子是把两个动态链接库my—1.dll和my—2.dll存放在DLLForm域中,当用户运行服务器中的Notes数据库时,程序开始搜索本地机器的系统目录,如果发现两个动态链接库已经在本地,则不下载,否则开始下载。下面是设计步骤:   1.首先在Notes中建立一个名叫DllForm的表单,在表单中设计一个名叫DllInHere的RTF域,然后保存。    以DllForm这个表单生成一个文档,文档的DllInHere域中附加了my—1.dll和my—2.dll两个Dll。   2. 在Declaration 中我们声明:   Declare Function GetSystemDirectoryA Lib ″kernel32″ (Byval lpBuffer As String, Byval uSize As Long) As Long   3.在Initalize事件中键入如下代码:   Dim sysSize As Long Dim uSize As Long Dim sysPath As String uSize = 50   Rem 取得系统路径字符串的长度 sysSize=GetSystemDirectoryA(sysPath,uSize) Rem 给系统路径变量置初值,确定准确长度   For i=1 To sysSize sysPath=sysPath+″″ Next   Rem 取出Window的system目录或者Window NT的system32目录 sysSize=GetSystemDirectoryA(sysPath,uSize) Dim pathName1,pathName2 As String, fileName1,fileName2 As String Dim rtitem As Variant Dim collection As NotesDocumentCollection Set uidb = session.CurrentDatabase ′ Dim collection As NotesDocumentCollection pathName1 = syspath+″\my—1.dll″ pathName2 = syspath+″\my—2.dll″   Rem 判断本地系统是否已经下载 fileName1 = Dir$(pathName1, 0) fileName2 = Dir$(pathName2, 0) Rem 如果没有下载则从服务器下载 If fileName1 = ″″ Then search$ = { Form = ″DllForm″ } Set collection = uidb.Search( search$, Nothing, 0 ) If collection.Count = 0 Then Print ″No dll″ Rem 判断文档是否存在 End If    Rem 取得第一个文档中的 DllInHere域 Set pzdoc = collection.GetFirstDocument( ) Set rtitem = pzdoc.GetFirstItem( ″dll″ ) i=0    Rem 判断域类型 If ( rtitem.Type = RICHTEXT ) Then Forall o In rtitem.EmbeddedObjects If i=0 Then    Rem 下载第一个DLL到系统目录 Call o.ExtractFile (pathName1) i=1 End If If i=1 Then    Rem 下载第二个DLL到系统目录 Call o.ExtractFile(pathName2) End If End Forall End If End If   这样,DLL就下载到本地。DLL一旦下载完毕,应用程序就可以调用其中的函数了。   小结   在一个中等以上规模的企业中,网络中的节点往往有几百、上千个,客户端软件的升级是网络管理员最感到头疼的事,使用本文介绍的自动下载方法,可以极大地减轻管理员的工作负担。另外利用C++、VB等编制的DLL程序也是对Notes功能的一个有力补充。

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧