'Constants would normally be defined in a module or class
Const NEXTSTEP_START = "NS-START"
Const NEXTSTEP_SELECTED = "NS-SELECTED"
Const HOOK_OK = "OK"
Const HOOK_CANCEL = "CANCEL"
'...
'User just selected Next Step operation
sHookResponse = mobjHookComponent.CallIn(NEXTSTEP_START, _
mobjCurrentItem, mobjCurrentUser, "")
...
'User just selected the Step to move the item to
sHookResponse = mobjHookComponent.CallIn(NEXTSTEP_SELECTED, _
mobjCurrentItem, mobjCurrentUser, sSelectedStep)
Hook component Code:
'Note: Hook constants file would need to be included
Function CallIn(ByVal sHookId as String, vParam1 as Variant, _
vParam2 as Variant, vParam3 as Variant) as String
Dim sReturnValue as String
Dim objWorkitem as clsWorkitem
Dim objUser as clsUser
Dim sSelectedStep as String
On Error Goto CallIn_Handler
Select Case sHookId
Case NEXTSTEP_START
'Processing to be done when NextStep is first invoked
Set objWorkitem = vParam1
Set objUser = vParam2
Call WriteLog( sHookId, "Item ID: " & _
objWorkitem.WorkitemID & ", User ID: " & _
objUser.UserID )
sHookId = HOOK_OK
Case NEXTSTEP_SELECTED
Set objWorkitem = vParam1
Set objUser = vParam2
sSelectedStep = vParam3
Call WriteLog( sHookId, "Item ID: " & _
objWorkitem.WorkitemID & ", User ID: " & _
objUser.UserID & ", Step: " & vParam3 )
'...do whatever processing is required...
sHookId = HOOK_OK
Case else
'Unknown hook, possibly introduced to product
' after this component was written.
'Just allow it, but do nothing.
Call WriteLog( sHookId, "Unrecognised Hook" )
sReturnValue = HOOK_OK
End Select
CallIn = sReturnValue
Exit Function
CallIn_Handler:
'Handle the error...
End Function
Sub WriteLog( sHookID as String, sText as String )
Dim sFullText as String
sFullText = Time$ & " " & sHookID & " " & sText
Debug.Print sFullText
'Log to file used mainly for testing
'and for diagnosing production systems
If IsFileLoggingOn(sHookID) then
'Output log info to text file...
End If
End Sub (to be continue )
Next step Started
"NS-START"
objUser
objWorkitem
""
Next step Step Selected
"NS-SELECTED"
objUser
objWorkitem
sStepName
這樣簡單的一個例子,三個變數(加上鉤子標識符)可能就已經足夠了,可是為了避免了將
來介面改變帶來的麻煩,你總是不得不增加更多的函數,列表1顯示了一個核心產品的簡單
代碼:一個鉤子組件,一個鉤子的調用執行個體
為了執行客戶三個複選框的功能,你應該從鉤子組件項目中添加一個複選框表單,並且通過
下面代碼調用:
Case NEXTSTEP_SELECTED
'...Cast variables and Call WriteLog()...
'Show the checklist
frmChecklist.Show vbModal
If frmCheckList.AllRequiredItemsTicked Then
sReturnValue = HOOK_OK
Else
MsgBox "You have not ticked all the " & _
"required items. " & _
"Next Step cannot continue", vbExclamation
Call WriteLog( sHookId, "Cancel sent back -- " & _
"all required items not ticked" )
sReturnValue = HOOK_CANCEL
End If
' ... more code
鉤子組件影響核心產品:
核心產品為可能發生變化的需求設定點,然後將對他們的控制委託給鉤子組件,接著響應鉤
子組件返回的狀態,
資料對象引用
當鉤子組件接收到一個對資料對象的引用時,核心產品需要捕獲鉤子組件引起了什麼變化,
如果你不想鉤子組件修改一個對象的參數,可以通過使用一個宣傳對象或者鎖對象,或者一
個在調用方法前設定部分特性的對象,如果你允許改變,對象可以驗證他們,或者記錄他們,
當方法返回時通過核心產品驗證他們,例如使用者需要用兩個鉤子更新一個有引用關鍵字的工
作項目
Case NEXTSTEP_SELECTED
'...cast variables and call WriteLog()...
sRefKey = GetMainframeKey(objWorkitem.WorkitemID)
objWorkitem.Reference = sRefKey
sReturnValue = HOOK_OK
然後核心產品可以查詢返回的工作項目對象: