16,555
社区成员
发帖
与我相关
我的任务
分享
Namespace LzmTW.Lotus
Public MustInherit Class IComClassBase(Of T)
Inherits LzmTW.uSystem.IComClassBase(Of T)
Sub New(ByVal com As T)
MyBase.New(com)
End Sub
Public Overloads Sub ReleaseCom(ByVal com As Object, Optional ByVal GCCollection As Boolean = False)
MyBase.ReleaseCom(com)
If GCCollection Then
GC.SuppressFinalize(Me)
GC.Collect(2)
End If
End Sub
Public Function ConvertToString(ByVal value As Object, Optional ByVal separator As Char = ";"c) As String
If value Is Nothing Then Return Nothing
Dim list As List(Of String) = MyBase.GetList(Of String)(value)
Dim result As String = String.Join(separator, list.ToArray)
list.Clear()
Return result
End Function
Public Function ConvertToArray(Of V)(ByVal value As String, Optional ByVal separator As Char = ";"c) As Array
Dim list As New List(Of V)
Dim result As Array
If Not value Is Nothing Then
For Each s As String In value.Split(separator)
list.Add(MyBase.ChangeTo(Of V)(s))
Next
End If
result = list.ToArray
list.Clear()
Return result
End Function
Public Function CreateInstancesFromComs(Of [To], From)(ByVal coms As Object) As List(Of [To])
Dim creator As New Creator(Of [To], From)
If Not coms Is Nothing Then
MyBase.ForEach(Of From)(coms, AddressOf creator.Action)
End If
Return creator.Result
End Function
Private Class Creator(Of U, V)
Private list As New List(Of U)
Private classType As Type = GetType(U)
Private comType As Type = GetType(V)
Private binding As Reflection.BindingFlags = _
Reflection.BindingFlags.NonPublic Or _
Reflection.BindingFlags.Public Or _
Reflection.BindingFlags.Instance
Private ctor As Reflection.ConstructorInfo
Sub New()
ctor = classType.GetConstructor(binding, Nothing, Reflection.CallingConventions.HasThis, New Type() {comType}, Nothing)
End Sub
Public Sub Action(ByVal com As V)
list.Add(CType(ctor.Invoke(New Object() {com}), U))
End Sub
Public ReadOnly Property Result() As List(Of U)
Get
Return list
End Get
End Property
End Class
End Class
End Namespace
Namespace LzmTW.Lotus
Public Class Notes
Private Shared Password As New SecurePassword
Private Shared ErrMsg As String
Private Sub New()
End Sub
Public Shared ReadOnly Property LastErro() As String
Get
Return ErrMsg
End Get
End Property
Public Shared Sub ResetPassword(ByVal password As String)
Notes.Password.Reset(password)
End Sub
Public Shared ReadOnly Property Environment() As Environment
Get
Return Environment.Instance
End Get
End Property
Public Overloads Shared Function CreateSession(ByVal userID As String, ByVal password As String) As Session
Environment.UserID = userID
Return CreateSession(password)
End Function
Public Overloads Shared Function CreateSession(ByVal password As String) As Session
Dim ComSession As ISession
ComSession = New NotesSession
Try
ComSession.Initialize(password)
ErrMsg = String.Empty
Catch ex As Exception
Marshal.ReleaseComObject(ComSession)
ComSession = Nothing
ErrMsg = ex.ToString
End Try
Return New Session(ComSession)
End Function
Public Overloads Shared Function CreateSession() As Session
Return CreateSession(Nothing)
End Function
Public Shared Function AutoCreateSession() As Session
If Password.SecureString Is Nothing Then Return CreateSession()
Return CreateSession(Marshal.PtrToStringAuto(Marshal.SecureStringToBSTR(Password.SecureString)))
End Function
End Class
End Namespace