''logging
Class LogObj As ErrorHandler
Private logdoc As NotesDocument 'при создании не сохраняется, инициализация - CreateLogDoc
Private logbody As NotesRichTextItem
Private logfileStream As NotesStream
Private tmpfileName As String
Private CodePage As String
Private toRTFlag As Boolean
Sub New()
CodePage="UTF-8"
toRTFlag=False
Call CreateLogDoc()
End Sub
Property Set toRT(b As Boolean)
toRTFlag=b
End Property
Sub Delete()
Call Closelog()
End Sub
Function CreateLogDoc() As NotesDocument
On Error Goto ErrorHandler
Dim ses As New NotesSession
Dim db As NotesDatabase
Set db=ses.CurrentDatabase
Set logdoc=db.CreateDocument()
Call logdoc.ReplaceItemValue({Form},{processLog})
Set logbody=logdoc.CreateRichTextItem({body})
tmpfileName=GetNotesTempDirectory()&{\}& logdoc.UniversalID &{.txt}
Set CreateLogDoc=logdoc
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
'***************************************
Function OpenLogDocWks(wks As NotesUIWorkspace) As NotesUIDocument
On Error Goto ErrorHandler
If Not logdoc Is Nothing Then
Call Me.CloseLog()
If wks Is Nothing Then
Dim logwks As New NotesUIWorkspace
Set OpenLogDocWks=logwks.EditDocument(False,logdoc,True)
Else
Set OpenLogDocWks=wks.EditDocument(False,logdoc,True)
End If
End If
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
'***************************************
Function OpenLogDoc() As NotesUIDocument
Set OpenLogDoc=OpenLogDocWks(Nothing)
End Function
'***************************************
Function GetLastLogDoc() As NotesUIDocument
Dim db As NotesDatabase
Dim wks As New NotesUIWorkspace
Dim ses As New NotesSession
On Error Goto ErrorHandler
Set db=ses.CurrentDatabase
Dim coll As NotesDocumentCollection
Set coll=db.AllDocuments
Dim doc As NotesDocument
Set doc=coll.GetLastDocument
Do While Not doc Is Nothing
If doc.Form(0)="processLog" Then
Exit Do
End If
Loop
If doc Is Nothing Then Exit Function
Set logdoc=doc
Set GetLastLogDoc=OpenLogDoc()
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
'***************************************
Function WriteLogDoc(txt As String) As Boolean
On Error Goto ErrorHandler
If toRTFlag Then
If Not logbody Is Nothing Then
logbody.AppendText(txt)
logbody.AddNewline(1)
End If
Else
Call WriteLogDocFile(txt)
End If
WriteLogDoc=True
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
'***************************************
Function WriteLogDocFile(txt As String) As NotesStream
On Error Goto ErrorHandler
If logfileStream Is Nothing Then
Dim ses As New NotesSession
Set logfileStream=ses.CreateStream()
Call logfileStream.Open(tmpfileName, CodePage)
Call logfileStream.WriteText(txt,EOL_CRLF)
Else
Call logfileStream.WriteText(txt,EOL_CRLF)
End If
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
'***************************************
Function CloseLog() As Boolean
On Error Goto ErrorHandler
If CloseLog Then Goto ExitFunction
If (Not logfileStream Is Nothing) Then
Call logfileStream.Close()
If (Not logdoc Is Nothing) Then
Call AddAttachment(tmpfileName,logdoc, {body})
Kill tmpfileName
End If
End If
If (Not logdoc Is Nothing) Then Call logdoc.Save(True,False)
CloseLog=True
ExitFunction:
Exit Function
ErrorHandler:
Call Me.RaiseError()
Resume ExitFunction
End Function
End Class