@@ -25,14 +25,13 @@ Method OnPreServer() As %Status
2525
2626Method Server () As %Status
2727{
28- Set timeout =.5
28+ Set timeout =.1
2929 set quit =0
30- set dataGN =" " ,event =" "
3130 #dim exception As %Exception.AbstractException
3231 Set len =32656
3332 while 'quit {
3433 try {
35- Set data =..Read (.len , .status , $select ( $isobject ( event ): 0 . 1 , 1 : timeout ) )
34+ Set data =..Read (.len , .status , timeout )
3635 If $$$ISERR(status ),$$$GETERRORCODE(status ) = $$$CSPWebSocketClosed {
3736 set quit =1
3837 quit
@@ -65,7 +64,7 @@ Method SendBlocksData() As %Status
6564 set child = ..ChildPID
6665 set resName = ..ResourceName
6766
68- set responseData = ##class (%ListOfDataTypes ).%New ()
67+ set responseData = ##class (%DynamicArray ).%New ()
6968 kill blocksData
7069 set countData =0
7170 set atEnd =0
@@ -79,30 +78,29 @@ Method SendBlocksData() As %Status
7978 set $listbuild (parent ,block ,global ,fill )=data
8079 if $p (..Event ," _" ,2 )=" tree" {
8180 if '$data (blocksData (parent )) {
82- set blocksData (parent )=##class (%ZEN.proxyObject ).%New ()
81+ set blocksData (parent )=##class (%DynamicObject ).%New ()
8382 set blocksData (parent ).block = parent
84- set blocksData (parent ).child = ##class (%ListOfDataTypes ).%New ()
85- do responseData .Insert (blocksData (parent ))
83+ set blocksData (parent ).child = ##class (%DynamicArray ).%New ()
84+ do responseData .%Push (blocksData (parent ))
8685 }
87- do blocksData (parent ).child .Insert (block )
86+ do blocksData (parent ).child .%Push (block )
8887 } else {
8988 if '$data (blocksData (global )) {
90- set blocksData (global )=##class (%ZEN.proxyObject ).%New ()
89+ set blocksData (global )=##class (%DynamicObject ).%New ()
9190 set blocksData (global ).global = global
92- set blocksData (global ).blocks = ##class (%ListOfDataTypes ).%New ()
93- do responseData .Insert (blocksData (global ))
91+ set blocksData (global ).blocks = ##class (%DynamicArray ).%New ()
92+ do responseData .%Push (blocksData (global ))
9493 }
95- set blockInfo = ##class (%ListOfDataTypes ).%New ()
96- do blockInfo .Insert (block )
97- do blockInfo .Insert (fill )
98- do blocksData (global ).blocks .Insert (blockInfo )
94+ set blockInfo = ##class (%DynamicArray ).%New ()
95+ do blockInfo .%Push (block )
96+ do blockInfo .%Push (fill )
97+ do blocksData (global ).blocks .%Push (blockInfo )
9998 kill blockInfo
10099 }
101100 quit :$i (countData )>=1000
102101 }
103-
104102 if responseData .Size > 0 {
105- do ..Write (..Event , responseData )
103+ do ..Write (..Event , responseData )
106104 }
107105 if atEnd {
108106 set ..Event = " "
@@ -111,13 +109,14 @@ Method SendBlocksData() As %Status
111109 quit $$$OK
112110}
113111
114- Method Action (obj As %ZEN . proxyObject ) As %Status
112+ Method Action (obj As %DynamicObject ) As %Status
115113{
116114 set st = $$$OK
117115 #dim exception As %Exception.AbstractException
118116 try {
117+ quit :obj =" "
119118 set action = obj .event
120- set data = ##class (%ListOfDataTypes ).%New ()
119+ set data = ##class (%DynamicArray ).%New ()
121120 if action =" ping" {
122121 set sc =..Write (action , " pong" )
123122 } elseif $p (action ," _" )=" blocks" {
@@ -228,7 +227,7 @@ ClassMethod ReadBlocks(aAsTree As %Boolean = 0, aBlockId As %Integer = 3, aParen
228227add (parentBlock ,blockId ,global ,offset )
229228 set data =$listbuild (parentBlock ,blockId )
230229 if 'aAsTree set data =data _$listbuild (global ,$j (offset /blockSize *100 ,0 ,0 ))
231- do $system .Event .Signal (ResourceName , data )
230+ do $system .Event .Signal (ResourceName , data )
232231}
233232
234233/// Reads up to len characters from the client.
@@ -238,8 +237,13 @@ Method Read(ByRef len As %Integer = 32656, ByRef sc As %Status, timeout As %Inte
238237{
239238 Set json = ##super (len , .sc , timeout )
240239 Do :$$$ISERR(sc ) ..EndServer ()
241- Set st = ##class (%ZEN.Auxiliary.jsonProvider ).%ConvertJSONToObject (json ,,.obj ,1 )
242- Do :$$$ISERR(st ) ..EndServer ()
240+ quit :json =" " " "
241+ try {
242+ set obj = ##class (%DynamicObject ).%FromJSON (json )
243+ } catch ex {
244+ set sc = ex .AsStatus ()
245+ set obj = " "
246+ }
243247 Quit obj
244248}
245249
@@ -248,49 +252,12 @@ Method Write(eventName As %String = "", data As %String) As %Status
248252 if '$d (data ) {
249253 quit ##super (eventName )
250254 }
251- set response = ##class (%ZEN.proxyObject ).%New ()
255+ set response = ##class (%DynamicObject ).%New ()
252256 set response .event = eventName
253257 set response .data = data
254258
255- Quit ##super (..OutputToStr (response ," %ToJSON" ))
256- }
257-
258- ClassMethod OutputToStr (obj , method , args ...) As %String [ ProcedureBlock = 0 ]
259- {
260- Set str =" "
261- //Redirect IO to the current routine - makes use of the labels defined below
262- Use $io ::(" ^" _$ZNAME )
263-
264- //Enable redirection
265- Do ##class (%Device ).ReDirectIO (1 )
266-
267- if $isobject (obj ) {
268- Do $Method (obj ,method ,args ...)
269- } elseif $$$comClassDefined(obj ) {
270- Do $ClassMethod (obj ,method ,args ...)
271- }
272-
273- //Disable redirection
274- Do ##class (%Device ).ReDirectIO (0 )
275- Quit str
276- //Labels that allow for IO redirection
277- //Read Character - we Don't care about reading
278- rchr (c ) quit
279- //Read a string - we Don't care about reading
280- rstr (sz ,to ) quit
281- //Write a character - call the output label
282- wchr (s ) Do output ($char (s )) quit
283- //Write a form feed - call the output label
284- wff () Do output ($char (12 )) quit
285- //Write a newline - call the output label
286- wnl () Do output ($char (13 ,10 )) quit
287- //Write a string - call the output label
288- wstr (s ) Do output (s ) quit
289- //Write a tab - call the output label
290- wtab (s ) Do output ($char (9 )) quit
291- //Output label - this is where you would handle what you actually want to Do.
292- // in our case, we want to Write to str
293- output (s ) Set str =str _s quit
259+ set json = response .%ToJSON ()
260+ quit ##super (json )
294261}
295262
296263}
0 commit comments