%REM
*********************************************
Class AgentBase
Description: launch agent base for local or onServer
%END REM
Class AgentBase As ErrorHandler
Private agent As NotesAgent
Private ses As NotesSession
Private db As NotesDatabase
Private logger As Logger
Private targetDB As NotesDatabase
Private NDCFile As NDCFile
Sub New(targetDb As NotesDatabase)
Dim routineName As String
routineName="New"
On Error GoTo ErrH
'your code here
Set me.targetDB=targetDB
Set ses=New NotesSession
Set db=ses.Currentdatabase
Set agent=ses.Currentagent
Set NDCfile=New NDCFile
If ses.Isonserver Then
Call Me.InitializeOnServer()
Else
Call Me.Initialize()
End If
Quit:
Exit Sub
ErrH:
Error Err, RaiseError
Resume Quit
End Sub
Sub Initialize()
On Error GoTo ErrH
Print {Running...}
Dim NDC As NotesDocumentCollection
Dim doc As NotesDocument, path As String
Dim lst List As String
'************ UI part
Dim wks As New NotesUIWorkspace
Dim uiview As NotesUIView
Set uiview=wks.Currentview
Set NDC=uiview.Documents
'check doc for contains unid list
Set doc=NDC.Getfirstdocument()
path=DetachDocFiles(doc,UNIDS_FILE_WILCARD, lst)
If Len(path)>0 Then Set NDC=NDCfile.Collection(path):Set doc=NDC.Getfirstdocument()
Dim txt As String
Set logger=New Logger({log})
Set logger=Process(NDC, me.targetDB, logger)
'Call logger.ShowLog()
Quit:
Exit Sub
ErrH:
Dim s As String
s=RaiseError
If Not logger Is Nothing Then logger.PrintMsg({!!!Errors:} &s):logger.Save
Error Err, s
End Sub
%REM
*--------------------------------------------
Sub InitializeOnServer
Description: Comments for Sub
%END REM
Sub InitializeOnServer
Dim routineName As String
routineName="InitializeOnServer"
On Error GoTo ErrH
'your code here
Dim NDC As NotesDocumentCollection
Dim doc As NotesDocument, path As String
Dim lst List As String
Set me.logger=New Logger({log})
'************ backend
If Len(agent.Parameterdocid)>0 Then
Set doc=me.db.Getdocumentbyid(agent.Parameterdocid)
If me.targetDB Is Nothing Then Set me.targetDB=GetDBbyRID(me.db.Server,GetDBRID(doc,{body}))
path=DetachDocFiles(doc,{*}, lst)
'reassign new instance, remove body (and files) from doc
Set me.logger.Document=doc
If Len(path)>0 And path Like {*.zip} Then
Dim fName
fName=me.NDCfile.Decompress(path)
Kill path
'gather packet document collection
path=fName(UBound(fName)) &me.NDCFile.FSSEP &fName(0)
Set NDC=me.NDCFile.Collection(path)
Kill path
me.logger.PrintMsg({file:} & path)
Else
me.logger.PrintMsg({*Attach is absent})
End If
Else
me.logger.PrintMsg({*without paramdoc})
End If
'process
Set me.logger=Me.Process(NDC, me.targetDB, logger)
Call me.logger.Save()
Quit:
Exit Sub
ErrH:
Dim s As String
s=RaiseError
If Not logger Is Nothing Then logger.PrintMsg({!!!Errors:} &s):logger.Save
Error Err, s
End Sub
%REM
*--------------------------------------------
Function Process
Description: collection could be NDC, NVN, NEC
%END REM
Function Process(collection As variant, db As NotesDatabase, logger As Logger) As Logger
Dim routineName As String
routineName="Process"
On Error GoTo ErrH
'your code here
Set Process=logger
Quit:
Exit Function
ErrH:
Error Err, RaiseError
Resume Quit
End Function
End Class