ACE has built-in functionality and tools for various purposes. Using this built-in functionality is preferable to writing it in VBS. Since VBS is an interpreted language, reproducing it in VBS damages performance.
Here is a list of the built-in functions and the appropriate way to use them:
IsWithinTimeslot
This is the simplest of the built-in functions. Its purpose is to enable the business logic to tell whether the system is currently within a timeslot or not. This removes the need to manage a variable in the timeslot enter and timeslot exit functions in order to do the same thing. For example, instead of running the following code:
Dim amIWithinATimeslot
Sub OnTimeslotEnter(time)
amIWithinATimeslot = 1
End sub
Sub OnTimeslotExit(time)
amIWithinATimeslot = 0
End sub
Sub OnEvent(eventDetails)
If amIWithinATimeslot = 1 Then
count = count + 1
End if
End sub
You can run this much simpler code, instead:
Sub OnEvent(eventDetails)
If context.IsWithinTimeslot Then
count = count + 1
End if
End sub
If you want to use or keep information about the timestamp of the timeslot enter and exit, this functionality would not cover your needs. But normally this is not needed, and this code is sufficient.
TimeOfLastEvent
This function gives you the timestamp of the last raw data or intermediate data event that was handled. This means you do not need to save this information in the event handler, as it is directly available through this function. For example:
Function result
Dim LastEventTimestamp
LastEventTimestamp = Context.TimeOfLastEvent
End function
TimeOfLastEventHandler
This function returns the timestamp of the last event handler called by ace. This includes not only raw and intermediate data event handlers, but also any system events that were called as well. This is especially useful in event handlers that do not receive the time to e.g. the result function. For example:
Function result
Dim LastEventHandlerTimestamp
LastEventHandlerTimestamp= Context.TimeOfLastEventHandler
End function
NetTime
This function allows you to specify two timestamps and to receive the net time (in seconds) that the system was within timeslot for the current rule, between those two timestamps. This especially is a cumbersome functionality and should not be implemented in VBS. Implementing this in VBS would entail keeping a list of all the timeslot enters and exits or calculating the difference between each time of entering timeslot exit directly, in order to figure out the time span between them. Under extreme conditions, this might happen a large number of times and this would not be good for calculation performance. The internal function does the same after significant optimization, and so does it much efficiently. For example:
Function result
Dim MyNetTime
MyNetTime = Tools.NetTime(MyBeginTimestamp, MyEndTimestamp)
End function
The context object
The context object has a variety of parameters that supply information about:
Accessing this information directly from the database using Safe ODBC is extremely inefficient and makes no sense as the information is readily available from the context object. If possible, always use the built in functionality is a way to get information.
|
Copyright © 2013 CA.
All rights reserved.
|
|