forked from ARSBlue/ToolBox-4-Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemEvent.cls
155 lines (141 loc) · 5.27 KB
/
SystemEvent.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/// This class contains all information about system events
///
/// ARSBlue ToolBox-4-Iris
/// Copyright © 2019 ARS Blue GmbH
/// http://www.ars-blue.at
Class arsblue.event.SystemEvent Extends arsblue.event.Event
{
/// The event type (SYSTEM, LOGIN, JOB or CALLIN).
Property Type As %EnumString(VALUELIST = ",SYSTEM,LOGIN,JOB,CALLIN,CALLOUT");
/// The event type action flag.
/// <ul>
/// <li>1...startup, login or start.</li>
/// <li>2...shutdown, logout or stop.</li>
Property Action As %Integer(MAXVAL = 2, MINVAL = 1);
/// The event action details.
Property ActionDetails As %DynamicObject;
/// This method adds a system event listener.
/// <ul>
/// <li>EventListener...the created system event listener.</li>
/// <li>EventTarget...the event target.</li>
/// <li>EventDeamon...the event listener deamon.</li>
/// <li>EventQueue...the event listener queue.</li>
/// <li>Types...the system event types to monitor (see <code>arsblue.event.SystemEventListener.SetTypes</code> method for more details).</li>
/// </ul>
/// Returns status OK if successfully created a system event listener, any other status signals failure and the listener will be set to null!
ClassMethod AddEventListener(ByRef EventListener As EventListener = {$$$NULLOREF}, EventTarget As %String = "", EventDeamon As %Integer, EventQueue As arsblue.event.EventQueue, Types As %String) As %Status
{
#dim status as %Status = $$$OK
try
{
new %objlasterror
set:('$$$TypeOf(EventListener,..%ClassName(1)_"Listener")) EventListener=$ClassMethod(..%ClassName(1)_"Listener","%New") $$$Throw($G(%objlasterror,$$$OK))
if ($D(Types)) $$$ThrowOnError(EventListener.SetTypes(Types))
}
catch (exc)
{
set status=exc.AsStatus()
}
if ($$$ISERR(status))
{
set EventListener=$$$NULLOREF
quit status
}
else
{
quit ##super(.EventListener,EventTarget,.EventDeamon,.EventQueue)
}
}
/// This method gets a system event listener.
/// <ul>
/// <li>EventListener...the created system event listener.</li>
/// <li>EventTarget...the event target.</li>
/// <li>EventDeamon...the event listener deamon.</li>
/// <li>EventQueue...the event listener queue.</li>
/// <li>Types...the system event types to monitor (see <code>arsblue.event.SystemEventListener.SetTypes</code> method for more details).</li>
/// </ul>
/// Returns the system event listener or null on any failure!
ClassMethod GetEventListener(EventTarget As %String = "", EventDeamon As %Integer, EventQueue As arsblue.event.EventQueue, Types As %String) As EventListener
{
do ..GetEventListenerSQL(.sql,.params,EventTarget,.EventDeamon,.EventQueue,.Types)
set stmt=##class(%SQL.Statement).%New()
quit:($$$ISERR(stmt.%Prepare(.sql))) $$$NULLOREF
set rs=stmt.%Execute(params...)
set eventListener=$$$NULLOREF
set:(rs.%Next()) eventListener=##class(arsblue.event.EventListener).%OpenId(rs.ID)
quit eventListener
}
/// This method gets the SQL statement to get a system event listener.
/// This method will be overwritten by derived events specifying the event parameters.
/// NOTE: Don't forget to call super class first!
/// <ul>
/// <li>sql...the SQL statement (by reference).</li>
/// <li>params...the SQL statement parameters (by reference).</li>
/// <li>EventTarget...the event target classname to call.</li>
/// <li>EventDeamon...the event listener deamon.</li>
/// <li>EventQueue...the event listener queue.</li>
/// <li>Types...the system event types to monitor (see <code>arsblue.event.SystemEventListener.SetTypes</code> method for more details).</li>
/// </ul>
/// Returns the system event listener SQL statement.
ClassMethod GetEventListenerSQL(ByRef sql, ByRef params, EventTarget As %String = "", EventDeamon As %Integer, EventQueue As arsblue.event.EventQueue, Types As %String) [ Private ]
{
do ##super(.sql,.params,EventTarget,.EventDeamon,.EventQueue)
if ($D(EventQueue))
{
set types=","_$ZCVT(Types,"U")_","
for type="SYSTEM","LOGIN","JOB","CALLIN","CALLOUT"
{
if ($F(types,","_type_"=1,"))
{
set sql($I(sql))="and Type"_$ZCVT(type,"W")_"=?",params($I(params))=1
}
elseif ($F(types,","_type_"=2,"))
{
set sql($I(sql))="and Type"_$ZCVT(type,"W")_"=?",params($I(params))=2
}
elseif ($F(types,","_type_",") || $F(types,","_type_"=3,"))
{
set sql($I(sql))="and Type"_$ZCVT(type,"W")_"=?",params($I(params))=3
}
else
{
set sql($I(sql))="and Type"_$ZCVT(type,"W")_"=?",params($I(params))=0
}
}
}
}
/// This method fires the system event.
/// Returns status OK if successfully processed event, any other status signals failure!
Method FireEvent() As %Status
{
$$$QuitOnError(##super())
#dim status as %Status = $$$OK
try {
set status=$ClassMethod(..EventListener.EventTarget,"OnSystemEvent",$this)
}
catch (exc)
{
set status=exc.AsStatus()
}
quit status
}
Storage Default
{
<Data name="ActionDetails">
<Attribute>ActionDetails</Attribute>
<Structure>node</Structure>
<Subscript>"arsblue.event.SystemEvent.ActionDetails"</Subscript>
</Data>
<Data name="SystemEventDefaultData">
<Subscript>"SystemEvent"</Subscript>
<Value name="1">
<Value>Type</Value>
</Value>
<Value name="2">
<Value>Action</Value>
</Value>
</Data>
<DefaultData>SystemEventDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}
}