2014年1月13日 星期一

Calling Lotus Notes Agent From .NET (Domino 7)

今天參考 http://ithelp.ithome.com.tw/question/10109131 的做法來寫一支Winform去啟動 Notes的Agent(因為Scheduled Agent經常會罷工只好手動).

做完之後, 發現大部份Agent都無法執行RunOnServer.(報錯)

找不到原因之下,最後只好在其中一個看板寫一個簡單的啟動其他Agent之轉接Agent程式.再由C#來啟動這支轉接Agent就都OK啦!

這支轉接Agent的Code 如下
(Declarations)
Dim session As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView

Dim agent As NotesAgent
Dim profile As NotesDocument
Dim currentLog As NotesLog

Sub Initialize
Dim m_item As NotesItem
Dim m_db As NotesDatabase
Dim m_agent As NotesAgent
'Dim m_col As NotesDocumentCollection
Dim m_mail As NotesDocument
Set session=New NotesSession
Set db=session.CurrentDatabase
Set agent = session.CurrentAgent
Set currentLog = New NotesLog( db.Title+" - Agent - "+agent.Name+" on "+db.Server )
Set profile=db.GetProfileDocument("SystemProfile")
Call currentLog.OpenNotesLog( db.Server, profile.LogPath(0) )
Call currentLog.LogAction("代理程式執行檢查 : "+agent.Name)
Set m_db=session.GetDatabase(db.Server,"Flow\CheckFlow.nsf",False)
If Not m_db Is Nothing Then
Call currentLog.LogAction("取得資料庫 : "+m_db.Title)
Set m_agent =m_db.GetAgent("GetSapDataAgent")
If Not m_agent Is Nothing Then
m_find=True
Print "Run Agent : "+m_agent.Name
Call currentLog.LogAction("開始執行代理程式 : "+m_agent.Name)
If m_agent.RunOnServer=0 Then
m_runOk=True
Call currentLog.LogAction("完成執行代理程式 : "+m_agent.Name)
Else
Call currentLog.LogError(1,"代理程式執行錯誤!!")
End If
Else
Call currentLog.LogError(1,"無法取得代理程式,代理程式執行錯誤!!")
End If
Else
Call currentLog.LogError(1,"無法取得資料庫,代理程式執行錯誤!!")
End If
currentLog.LogAction("代理程式結束作業完成!!")
Call currentLog.Close
End Sub