MTPipeline.MTScriptPlugin.1
A Visual Basic Script plug-in is wrapped in a C++ shell, which is called by the Pipeline server to perform the functionality of the plug-in. You need to create two files to create a new plug-in using Visual Basic Script:
A configuration file (XML extension) (see Configuration example)
A Visual Basic Script (usually with a VBS extension)
The Visual Basic Script file contains the functionality of the plug-in.
Global objects that provide an interface for writing to the log file follow. For a description, see "Configure Method".
MTLog
MTNameID
MTSystemContext
A sample Visual Basic Script plug-in follows:
-------------- available symbols ---------------
' MTLog
' MTNameID
' MTSystemContext
'-------------------------------------------------
'-- Symbol definition -
Dim init_charge_prop_name
Dim rate_prop_name
Dim duration_prop_name
Dim amount_prop_name
'-- Main routine -
init = 12 + 34 '-- just for demo purposes
'-- end of main routine --
'------------------------------------------------------------------------
' Configure - PlugIn initialization
'------------------------------------------------------------------------
sub MTPipeline_Configure(ByVal ConfigPropSet)
On Error Resume Next
Dim MTProp
MTLog.Init "logging", "[PlugIn]"
MTLog.LogString 5, "start Configuration in script"
Set MTProp = ConfigPropSet.NextWithName("init_charge_prop_name")
if err then
MTLog.LogString 2, "Fail to get data field: init_charge_prop_name"
Exit sub
end if
init_charge_prop_name = MTProp.ValueAsString
if err then
MTLog.LogString 2, "Fail to get string data value of init_charge_prop_name"
Exit sub
end if
Set MTProp = Nothing
Set MTProp = ConfigPropSet.NextWithName("rate_prop_name")
if err then
MTLog.LogString 2, "Fail to get data field: rate_prop_name"
Exit sub
end if
rate_prop_name = MTProp.ValueAsString
if err then
MTLog.LogString 2, "Fail to get string data value of rate_prop_name"
Exit sub
end if
Set MTProp = Nothing
Set MTProp = ConfigPropSet.NextWithName("duration_prop_name")
if err then
MTLog.LogString 2, "Fail to get data field: duration_prop_name"
Exit sub
end if
duration_prop_name = MTProp.ValueAsString
if err then
MTLog.LogString 2, "Fail to get string data value of duration_prop_name"
Exit sub
end if
Set MTProp = Nothing
Set MTProp = ConfigPropSet.NextWithName("amount_prop_name")")
if err then
MTLog.LogString 2, "Fail to get data field: amount_prop_name"
Exit sub
end if
amount_prop_name = MTProp.ValueAsString
if err then
MTLog.LogString 2, "Fail to get string data value of amount_prop_name"
Exit sub
end if
Set MTProp = Nothing
MTLog.LogString 5, "Finished Configuration in script"
end sub
'------------------------------------------------------------------------
' ProcessSession - Process single session
'------------------------------------------------------------------------
sub MTPipeline_ProcessSession(ByVal Session)
On Error Resume Next
Dim id
Dim initChargeVal, rateVal, durationVal, amountVal
Dim name, log
initChargeVal = 0
rateVal = 0
durationVal = 0
amountVal = 0
MTLog.LogString 5, "start process session here"
Set log = MTSystemContext.GetLog()
Set name = MTSystemContext.GetNameID()
'-- Get initial charge value -
id = name.GetNameID(init_charge_prop_name)
if err then
MTLog.LogString 2, "Fail to get name id of: init_charge_prop_name"
Exit sub
end if
initChargeVal = Session.GetdecimalProperty(id)
if err then
MTLog.LogString 2, "Fail to get decimal data: init_charge_prop_name"
Exit sub
end if
'-- Get rate value -
id = MTNameID.GetNameID(rate_prop_name)
if err then
MTLog.LogString 2, "Fail to get name id of: rate_prop_name"
Exit sub
end if
rateVal = Session.GetdecimalProperty(id)
if err then
MTLog.LogString 2, "Fail to get decimal data: rate_prop_name"
Exit sub
end if
'-- Get call duration value -
id = MTNameID.GetNameID(duration_prop_name)
if err then
MTLog.LogString 2, "Fail to get name id of: duration_prop_name"
Exit sub
end if
durationVal = Session.GetLongProperty(id)
if err then
MTLog.LogString 2, "Fail to get long data: duration_prop_name"
Exit sub
end if
'-- Get result amount property id -
id = MTNameID.GetNameID(amount_prop_name)
if err then
MTLog.LogString 2, "Fail to get name id of: amount_prop_name"
Exit sub
end if
'-- Calculate the final amount -
amountVal = ( (durationVal * rateVal) + initChargeVal)
'-- Set the result into session object -
Session.SetdecimalProperty id, amountVal
if err then
MTLog.LogString 2, "Fail to set decimal data: amount_prop_name"
Exit sub
end if
log.LogString 5, "Finished process session"
end sub
'------------------------------------------------------------------------
' ProcessSessionSet - Process session set
'------------------------------------------------------------------------
sub MTPipeline_ProcessSessionSet(ByVal SessionSet)
Dim mysess
'-- Go through each session --
for each mysess in SessionSet
MTPipeline_ProcessSession mysess
next
end sub
To handle exception errors properly, use Microsoft's font-size:9.0pt;font-family:"Courier New"'>On Error Resume Next statement at the beginning of each MTPipeline_Configure and MTPipeline_ProcessSession subroutine. If an error occurs, the Script Host plug-in continues processing. This allows you to test whether an error occurred.
Within the subroutine, each time you call an interface from an object, issue an IF statement against the err object to check whether the call is successful. You can then handle the error appropriately. In the example below, the Script Host plug-in logs a message and exits.
An example of using the On Error statement for error processing follows. If the property value does not exist, the Script Host plug-in continues processing and logs an error.
sub MTPipeline_ProcessSession(ByVal Session)
On Error Resume Next
id = MTNameID.GetNameID(init_charge_prop_name)
initChargeVal = Session.GetdecimalProperty(id)
if err then
MTLog.LogString 2, "Error getting decimal property value"
Exit sub
end if
&ldots;
end sub
For details on the Microsoft On Error statement, see the Microsoft MSDN Library.
You can use the err.Raise statement for generating run-time errors. Using the err.Raise statement allows you to generate detailed errors when writing plug-ins. For example, you can specify the source that generated the error and message associated with the error. The messages appear in the System Failures Log of the Operations application.
For information on the System Failures Log, see the Operations User Guide. Errors generated using the err.Raise statement cause the plug-in to exit.
The format of the err.Raise statement follows:
err.Raise constant , message
where constant is the constant that generates the error and error number (required), and message is text describing the error (optional). err is the object, and Raise is the method.
Sample code using the err.Raise statement without generating a message follows:
err.Raise 8H80070057
Sample code using the err.Raise statement and generating a message follows:
err.Raise 8HE1500003 , "Bad number of minutes."
Pipeline logging for Visual Basic Script plug-ins is done using the IMTlog interface. The IMTlog interface in Visual Basic Script is a global object called MTLog. This object can be called anywhere you want to log a message, so long as you first call the MTLog.Init method.
The format of the call to the MTLog.Init method follows:
MTLog.Init "logging", "[message_type]"
where logging is the directory containing the logging configuration file and message_type is the type of log entry. A sample line of code follows:
MTLog.Init "\config\Logging\logging.xml", "[PlugIn]"
Java Script and other scripting languages will be supported in the future.
Do not modify existing subroutine names.
For more information on the err.Raise statement, see the following URL:
http://msdn.microsoft.com/library/officedev/office97/output/F1/D6/S5B293.HTM