-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClassBuilder.cls
714 lines (608 loc) · 23.5 KB
/
ClassBuilder.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/// v1.3 <br>
/// Builds a table structure for a MTConnect current file based on a probe file.
Class MTConnect.BO.ClassBuilder Extends Ens.BusinessOperation
{
Parameter INVOCATION = "Queue";
Parameter SETTINGS = "PackageName:MTConnect,suffixClass:MTConnect,Kind:MTConnect,ClearData:MTConnect,SuperClasses:MTConnect,GenerateDataTypes:MTConnectDataTypes,DataTypesPackage:MTConnectDataTypes,GenerateIsValid:MTConnectDataTypes,GenerateNormalize:MTConnectDataTypes,GenerateLogicalToDisplay:MTConnectDataTypes,GenerateDisplayToLogical:MTConnectDataTypes,Log:LOG,LogFile:LOG";
// MTConnect
/// The Name of the Package where the data gets insert
Property PackageName As %String(MAXLEN = 100);
/// The suffix of the className
Property suffixClass As %String(MAXLEN = 100);
/// The devicename from the probe file
Property deviceName As %String(MAXLEN = 100);
/// Comma seperated String for the super classes of the built class
Property SuperClasses As %String(MAXLEN = 100);
/// Specify if the ID or Name Attribute is used.
Property Kind As %String(MAXLEN = 10, VALUELIST = ",ID, Name") [ InitialExpression = "ID" ];
/// If set the table gets cleared when a log clear received
Property ClearData As %Boolean;
// MTConnectDataTypes
/// When activated the MTConnect Datatypes will be generated atomatically
Property GenerateDataTypes As %Boolean;
/// The Packagename of the MTConnect datatypes package
Property DataTypesPackage As %String(MAXLEN = 100) [ InitialExpression = "MTConnect.DataTypes" ];
/// If activated generates a IsValid Method for the DataTypes
Property GenerateIsValid As %Boolean [ InitialExpression = 1 ];
/// If activated generates a Normalize Method for the DataTypes
Property GenerateNormalize As %Boolean [ InitialExpression = 1 ];
/// If activated generates a LogicalToDisplay Method for the DataTypes
Property GenerateLogicalToDisplay As %Boolean [ InitialExpression = 1 ];
/// If activated generates a DisplayToLogical Method for the DataTypes
Property GenerateDisplayToLogical As %Boolean [ InitialExpression = 1 ];
// LOG
/// Active the Logger
Property Log As %Boolean;
/// Path to LogFile
Property LogFile As %String(MAXLEN = 1000);
/// A Logger to write the log
Property Logger As MTConnect.Logger [ Private ];
/// Builds the class if it does not exists and inserts current data
/// <li>pRequest: The Request</li>
/// <li>pResponse: The Response</li>
/// <li><b>returns</b>: If the class could be build</li>
Method Execute(pRequest As MTConnect.MSG.MTConnectRequest, Output pResponse As MTConnect.MSG.MTConnectResponse) As %Status
{
//Setup Logger
If ..Log{
Set ..Logger = ##class(MTConnect.Logger).%New(..LogFile, .logSc)
If $$$ISERR(logSc){
Set ..Log = 0
}
}
//Write request to log
Do ..WriteToLog("REQUEST:"_pRequest.ToString())
//Get DeviceName
If ..deviceName = ""{
Set ..deviceName = ..GetDeviceName(pRequest.probe, pRequest.probeFromFile)
If $F(..deviceName,"-") '= 0{
Set ..deviceName = $REPLACE(..deviceName,"-","")
}
}
//CLEAR LOG
If pRequest.recievedLine = "***CL***" {
If ..ClearData{
Set stmt = ##class(%SQL.Statement).%New()
Set sql = "DELETE FROM "_..ConvertClassName(..GetClassName())
Do stmt.%Prepare(sql)
Do stmt.%Execute()
}
Set pResponse = pRequest.toResponse()
Set pResponse.className = ..GetClassName()
Do ..WriteToLog("Data cleared!")
Return $$$OK
}
//Build Class
Set tSc = ..BuildClass(pRequest.probe,pRequest.probeFromFile)
If $$$ISERR(tSc){
Do ..WriteErrorToLog("Class could not be Built"_$SYSTEM.Status.GetErrorText(tSc))
Return tSc
}
//Set timestamp
If pRequest.recievedLine '= ""{
Set timestamp = $P(pRequest.recievedLine,"|")
}
Else{
Set timestamp = $REPLACE(..GetCreationTime(pRequest.current,pRequest.currentToFile),"Z","")
}
//Insert current in table
Set tSc = ..InsertCurrent(pRequest.current,timestamp,pRequest.currentToFile)
//Set response
Set pResponse = pRequest.toResponse()
Set pResponse.className = ..GetClassName()
Do ..WriteToLog("RESPONSE:"_pResponse.ToString())
//Close Logger
If ..Log{
Do ..Logger.Close()
}
Return tSc
}
/// Build the class based on probe if it does not exists
/// <li>probe: The path to the probe file</li>
/// <li>fromFile(optional): if 1: reads probe from file; if 0: provide the probe data in the probe parameter</li>
/// <li><b>returns</b>: If the class could be built</li>
/// <EXAMPLE> Do instance.BuildClass("/path/to/probe.xml")</EXAMPLE>
/// <EXAMPLE> Do instance.BuildClass("<xml>probe</xml>",0)</EXAMPLE>
Method BuildClass(probe As %String, fromFile As %Boolean = 1) As %Status
{
Set className = ..GetClassName()
//IF class already exists return $$$OK
If ..CheckIfClassExists(className){
Return $$$OK
}
//Get the dataitems from probe file
Set l = ..GetDataItems(probe,fromFile)
//Build the class based on name or id
If ..Kind = "Name"{
Set sc = ..BuildClassHelper(l, className, "name")
}
ElseIf ..Kind = "ID"{
Set sc = ..BuildClassHelper(l, className, "id")
}
//write to log
If sc{
Do ..WriteToLog("Class built:"_..GetClassName())
}
Else{
Do ..WriteErrorToLog("Something went wrong building the class:"_$SYSTEM.Status.GetErrorText(sc))
}
Return sc
}
/// reads the attributes from the DataItems specified in the probe file
/// <li>probe: The path to the probe file</li>
/// <li>(optional)fromFile: if 1: reads probe from file; if 0: provide the probe data in the probe parameter</li>
/// <li><b>returns</b>: </li>
/// <EXAMPLE> Do ##class(MTConnect.BO.ClassBuilder).GetDataItems()</EXAMPLE>
Method GetDataItems(probe As %String, fromFile As %Boolean = 1) As %ListOfObjects [ Private ]
{
If fromFile{
Set status=##class(%XML.TextReader).ParseFile(probe,.textreader)
}
Else{
Set status=##class(%XML.TextReader).ParseString(probe,.textreader)
}
//check status
If $$$ISERR(status) {Do $SYSTEM.Status.DisplayError(status) Quit}
Set myList = ##class(%ListOfObjects).%New()
//iterate through document, node by node
While textreader.Read()
{
If textreader.Name ="DataItem"
{
If textreader.HasAttributes = 0{
Continue
}
Set obj = ##class(%Library.DynamicObject).%New()
For a = 1:1:textreader.AttributeCount {
Do textreader.MoveToAttributeIndex(a)
Do obj.%Set(textreader.LocalName, textreader.Value)
}
Do myList.Insert(obj)
}
}
Return myList
}
/// Builds the class based on the Name Attribute
/// <li>listOfDataItems: list of dataitems from the probe file</li>
/// <li>className: The name of the class to build</li>
/// <li>kind: "name" or "id"</li>
/// <li><b>returns</b>: If the class could be built</li>
Method BuildClassHelper(listOfDataItems As %ListOfObjects, className As %String, kind As %String) As %Status [ Private ]
{
#dim tSc as %Status = $$$OK
//Define Class
Set cdef = ##class(%Dictionary.ClassDefinition).%New(className)
If $SYSTEM.Status.IsError(cdef) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Return Err
}
Set cdef.ProcedureBlock = 1
//Set cdef.DdlAllowed = 1
//Add superclasses
If ..SuperClasses '= ""{
Set cdef.Super = "%Persistent,"_..SuperClasses
}
Else{
Set cdef.Super = "%Persistent"
}
//Add TimeStamp
Set pdef = ##class(%Dictionary.PropertyDefinition).%New(className_":timestamp")
If $SYSTEM.Status.IsError(pdef) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Throw Err
}
Do cdef.Properties.Insert(pdef)
Set pdef.Type = "%Library.TimeStamp"
Set type = "%String"
//Generate NONETYPE
If '##class(%Dictionary.CompiledClass).%ExistsId(..DataTypesPackage_".NONETYPE"){
Set sc = ..GenerateNoneType()
If $$$ISERR(sc){
Do ..WriteErrorToLog("Could not generate NONETYPE: "_$SYSTEM.Status.GetErrorText(sc))
}
Else{
Set type = ..DataTypesPackage_".NONETYPE"
Do ..WriteToLog(type_" created")
}
}
//iterate through list
For i = 1:1:listOfDataItems.Count(){
Set dataItem = listOfDataItems.GetAt(i)
//skip if no name is defined
If 'dataItem.%IsDefined(kind){
Continue
}
Set pdef = ##class(%Dictionary.PropertyDefinition).%New(className_":"_dataItem.%Get(kind))
If $SYSTEM.Status.IsError(pdef) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Do ..WriteErrorToLog("Could not define property "_dataItem.%Get(kind)_": "_$SYSTEM.Status.GetErrorText(Err))
Return Err
}
//d pdef.Parameters.SetAt("AGE()", "POPSEC")
Do cdef.Properties.Insert(pdef)
Set pdef.Type = type
}
//Save class
Do cdef.%Save()
//Compile class
Try{
$$$ThrowOnError($SYSTEM.OBJ.Compile(className, "/Display=none"))
}
Catch tEx {
Do ..WriteErrorToLog("Could not compile class: "_$SYSTEM.Status.GetErrorText(tEx))
Set tSc = tEx.AsStatus()
}
Return tSc
}
/// Inserts data from current
/// <li>current: The path to the current file</li>
/// <li>timestamp: The timestamp</li>
/// <li>fromFile(optional): if 1: reads current from file; if 0: provide the current data in the current parameter</li>
/// <li><b>returns</b>: If the current could be inserted</li>
/// <EXAMPLE> Set tSc = instance.InsertCurrent("path/to/current.xml",timestamp)</EXAMPLE>
/// <EXAMPLE> Set tSc = instance.InsertCurrent("<xml>current<xml>", timestamp,0)</EXAMPLE>
Method InsertCurrent(current As %String, timestamp As %String, fromFile As %Boolean = 1) As %Status
{
If ..Kind = "Name"{
Set l = ..ReadCurrentFile(current,"name",fromFile)
}
ElseIf ..Kind = "ID"{
Set l = ..ReadCurrentFile(current,"dataItemId",fromFile)
}
//Set types
Set tSc = ..SetTypes(l,..GetClassName())
If $$$ISERR(tSc){
Do ..WriteErrorToLog("Could not set types: "_$SYSTEM.Status.GetErrorText(tSc))
}
//insert
Set sc = ..InsertCurrentHelper(l, ..GetClassName(), timestamp)
Return sc
}
/// Reads the Values from the current file
/// <li>current: path to current file</li>
/// <li>kind: "name" or "dataItemId"</li>
/// <li>(optional)fromFile: if 1: reads current from file; if 0: provide the current data in the current parameter</li>
/// <li><b>returns</b>: A list of objects with all values from the current file</li>
Method ReadCurrentFile(current As %String, kind As %String, fromFile As %Boolean = 1) As %ListOfObjects [ Private ]
{
If fromFile{
Set status=##class(%XML.TextReader).ParseFile(current,.textreader)
}
Else{
Set status=##class(%XML.TextReader).ParseString(current,.textreader)
}
//check status
If $$$ISERR(status) {Do $SYSTEM.Status.DisplayError(status) Quit}
Set myList = ##class(%ListOfObjects).%New()
//iterate through document, node by node
While textreader.Read()
{
Set name = 0
For a = 1:1:textreader.AttributeCount {
Do textreader.MoveToAttributeIndex(a)
If textreader.LocalName = kind{
Set name = textreader.Value
}
}
If name '= 0{
Do textreader.Read()
If textreader.HasValue{
Set obj = ##class(%Library.DynamicObject).%New()
Do obj.%Set("name", name)
Do obj.%Set("value", textreader.Value)
Do obj.%Set("type", $REPLACE($P(textreader.Path,"/",*),"x:",""))
Do myList.Insert(obj)
}
}
}
Return myList
}
/// Inserts the current file to the table
/// <li>lst: The list of objects from <METHOD>ReadCurrentFile</METHOD></li>
/// <li>className: The class name </li>
/// <li>timestamp: a timestamp</li>
/// <li><b>returns</b>: If the data could be added</li>
Method InsertCurrentHelper(lst As %ListOfObjects, className As %String, timestamp As %String) As %Status [ Private ]
{
// make new instance
Set c = $SYSTEM.OBJ.New(className)
//iterate through objects
For i = 1:1:lst.Count(){
Set obj = lst.GetAt(i)
//if data is UNAVAILABLE skip
If obj.%Get("value") = "UNAVAILABLE"{
Continue
}
//Set the property
Try{
Set $PROPERTY(c, obj.%Get("name")) = obj.%Get("value")
Do ..WriteToLog( obj.%Get("name")_" set to value: "_obj.%Get("value"))
}
Catch{
Do ..WriteErrorToLog( obj.%Get("name")_" could not be set to value: "_obj.%Get("value"))
}
}
//Add timestamp
Set c.timestamp = ##class(%Library.TimeStamp).DisplayToLogical((timestamp))
//Save
Set tSc = c.%Save()
If $$$ISERR(tSc){
Do ..WriteErrorToLog("Could not save current:"_$SYSTEM.Status.GetErrorText(tSc))
}
Return tSc
}
/// Set the types based on the current file
/// <li>lst: The list of objects from <METHOD>ReadCurrentFile</METHOD></li>
/// <li>className: The classname</li>
/// <li><b>returns</b>: If the Types could be set</li>
Method SetTypes(lst As %ListOfObjects, className As %String) As %Status [ Private ]
{
#dim tSc as %Status = $$$OK
//iterate through objects
For i = 1:1:lst.Count(){
Set obj = lst.GetAt(i)
//Check if there is a Objectscript-MTConnect-Datatype that fits to the current datatype
If ##class(%Dictionary.CompiledClass).%ExistsId(..DataTypesPackage_"."_$ZCVT(obj.%Get("type"),"U")){
Set type = ..DataTypesPackage_"."_$ZCVT(obj.%Get("type"),"U")
}
//if not the the type based on the value
Else{
If '..GenerateDataTypes{
Do ..WriteErrorToLog("Could not find type: "_obj.%Get("type"))
}
//if data is UNAVAILABLE skip
If obj.%Get("value") = "UNAVAILABLE"{
Continue
}
Set type = "%String"
If $ISVALIDDOUBLE(obj.%Get("value")){
Set type = "%Double"
}
If ..GenerateDataTypes{
Set dataTypesRequest = ##class(MTConnect.MSG.CreateDataTypeRequest).%New()
Set dataTypesRequest.DataType = type
Set dataTypesRequest.Name = $ZCVT(obj.%Get("type"),"U")
Set sc = ##class(MTConnect.DataTypesBuilder).Execute(dataTypesRequest,
..DataTypesPackage,
..GenerateIsValid,
..GenerateNormalize,
..GenerateDisplayToLogical,
..GenerateLogicalToDisplay)
If $$$ISERR(sc){
Do ..WriteErrorToLog("Could not generate type: "_$ZCVT(obj.%Get("type"),"U")_" ("_$SYSTEM.Status.GetErrorText(sc)_")")
Continue
}
Do ..WriteToLog($ZCVT(obj.%Get("type"),"U")_" DataType created")
Set type = ..DataTypesPackage_"."_$ZCVT(obj.%Get("type"),"U")
}
}
//Create PropertyDefinition
Set pdef = ##class(%Dictionary.PropertyDefinition).%OpenId(className_"||"_obj.%Get("name"),,.pSc)
If $$$ISERR(pSc){
Do ..WriteErrorToLog("Could not create property definition: "_$SYSTEM.Status.GetErrorText(pSc))
Continue
}
//If pdef = ""{Continue}
//Set new type if oldtype is differnt
If type '= pdef.Type{
Set oldType = pdef.Type
Try{
/* Set sql = "ALTER TABLE "_..ConvertClassName(className)_" ALTER COLUMN "_obj.%Get("name")_" "_type
Set tStatement = ##class(%SQL.Statement).%New()
Set qStatus = tStatement.%Prepare(sql)
If qStatus '= 1{Write "%Prepare failed:" Do $SYSTEM.Status.DisplayError(qStatus) Quit}
Set resultSet = tStatement.%Execute() */
Set pdef.Type = type
Do pdef.%Save()
Do ..WriteToLog(obj.%Get("name")_" set from "_oldType_" to "_type)
}
Catch tEx{
Do ..WriteErrorToLog(obj.%Get("name")_" could not be set to "_type)
Set tSc = tEx.AsStatus()
}
}
}
//Compile class
Try{
$$$ThrowOnError($SYSTEM.OBJ.Compile(className, "/Display=none"))
}
Catch tEx {
Do ..WriteErrorToLog("Could not compile class: "_$SYSTEM.Status.GetErrorText(tEx))
Set tSc = tEx.AsStatus()
}
Return tSc
}
/// Generates a NONETYPE Datatype
/// <li><b>returns</b>: If the Datatype could be generated</li>
/// <EXAMPLE> Set sc = instance.GenerateNoneType()</EXAMPLE>
Method GenerateNoneType() As %Status [ Private ]
{
#dim tSc as %Status = $$$OK
Set className = ..DataTypesPackage_".NONETYPE"
//Define Class
Set cdef = ##class(%Dictionary.ClassDefinition).%New(className)
If $SYSTEM.Status.IsError(cdef) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Throw Err
}
Set cdef.ProcedureBlock = 1
Set cdef.Abstract = 1
Set cdef.ClassType = "datatype"
//DisplayToLogical
Set mdefDTL = ##class(%Dictionary.MethodDefinition).%New(className_":DisplayToLogical")
If $SYSTEM.Status.IsError(mdefDTL) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Throw Err
}
Do cdef.Methods.Insert(mdefDTL)
Do mdefDTL.FormalSpecSet("%val:%String")
Set mdefDTL.ReturnType = className
Set mdefDTL.ClassMethod = 1
Set mdefDTL.Implementation.LineTerminator = $C(13,10)
Do mdefDTL.Implementation.WriteLine(" Return """"")
//LogicalToDisplay
Set mdefLTD = ##class(%Dictionary.MethodDefinition).%New(className_":LogicalToDisplay")
If $SYSTEM.Status.IsError(mdefLTD) {
Do $SYSTEM.Status.DecomposeStatus(%objlasterror,.Err)
Throw Err
}
Do cdef.Methods.Insert(mdefLTD)
Do mdefLTD.FormalSpecSet("%val:"_className)
Set mdefLTD.ReturnType = "%String"
Set mdefLTD.ClassMethod = 1
Set mdefLTD.Implementation.LineTerminator = $C(13,10)
Do mdefLTD.Implementation.WriteLine(" Return ""UNAVAILABLE""")
Do cdef.%Save()
//Compile class
Try{
$$$ThrowOnError($SYSTEM.OBJ.Compile(className, "/Display=none"))
}
Catch tEx {
Set tSc = tEx.AsStatus()
}
Return tSc
}
/// Ckecks if the class exists
/// <li>className: The className of the class</li>
/// <li><b>returns</b>: If the class exists</li>
/// <EXAMPLE> Set exist = ##class(MTConnect.BO.ClassBuilder).CheckIfClassExists("Pkg.ClassName")</EXAMPLE>
ClassMethod CheckIfClassExists(className As %String) As %Boolean
{
Return ##class(%Dictionary.CompiledClass).%ExistsId(className)
}
/// Returns the complete className
/// <li><b>returns</b>: The complete className</li>
/// <EXAMPLE> Set className = instance.GetClassName()</EXAMPLE>
Method GetClassName() As %String
{
Return ..PackageName_"."_..deviceName_..Kind_..suffixClass
}
/// Reads the Creationtime from the current file
/// <li>current: The current file or data</li>
/// <li>(optional)fromFile: if 1: reads current from file; if 0: reads current from the current parameter</li>
/// <li><b>returns</b>: The creation time</li>
Method GetCreationTime(current As %String, fromFile As %Boolean = 1) As %String [ Private ]
{
If fromFile{
Set status=##class(%XML.TextReader).ParseFile(current,.textreader)
}
Else{
Set status=##class(%XML.TextReader).ParseString(current,.textreader)
}
//check status
If $$$ISERR(status) {Do $SYSTEM.Status.DisplayError(status) Quit}
//iterate through document, node by node
While textreader.Read()
{
If textreader.Name ="Header"
{
For a = 1:1:textreader.AttributeCount {
Do textreader.MoveToAttributeIndex(a)
If textreader.LocalName = "creationTime"{
Return textreader.Value
}
}
}
}
Return $$$ERROR("creationTime not found")
}
/// Reads the device name from the probe file
/// <li>probe: The probe file</li>
/// <li>(optional)fromFile: if 1: reads probe from file; if 0: reads probe from the probe parameter</li>
/// <li><b>returns</b>: The devicename</li>
Method GetDeviceName(probe As %String, fromFile As %Boolean = 1) As %String [ Private ]
{
If fromFile{
Set status=##class(%XML.TextReader).ParseFile(probe,.textreader)
}
Else{
Set status=##class(%XML.TextReader).ParseString(probe,.textreader)
}
//check status
If $$$ISERR(status) {Do $SYSTEM.Status.DisplayError(status) Quit}
//iterate through document, node by node
While textreader.Read()
{
If textreader.Name ="Device"
{
For a = 1:1:textreader.AttributeCount {
Do textreader.MoveToAttributeIndex(a)
If textreader.LocalName = "name"{
Return textreader.Value
}
}
}
}
Return $$$ERROR("Name not found")
}
/// Converts the classname for SQL by replacing the package dots with underscores.
/// <li>className: The original classname</li>
/// <li><b>returns</b>: The converted classname</li>
/// <EXAMPLE> Set sqlClassName = ##class(MTConnect.BO.ClassBuilder).ConvertClassName("Package1.Package2.ClassName")</EXAMPLE>
ClassMethod ConvertClassName(className As %String) As %String
{
Set dotCount = $L(className,".")
Set dotCount = dotCount - 2
Return $REPLACE(className,".","_",,dotCount)
}
/// Writes a line to the logfile
/// <li>line: The line to log</li>
/// <EXAMPLE> Do instance.WriteToLog("text")</EXAMPLE>
Method WriteToLog(line As %String) [ Private ]
{
If ..Log{
Do ..Logger.WriteLine(line)
}
}
/// Writes a error line to the logfile
/// <li>line: The error line to log</li>
/// <EXAMPLE> Do instance.WriteErrorToLog("errorText")</EXAMPLE>
Method WriteErrorToLog(line As %String) [ Private ]
{
If ..Log{
Do ..Logger.WriteErrorLine(line)
}
}
XData MessageMap
{
<MapItems>
<MapItem MessageType="MTConnect.MSG.MTConnectRequest">
<Method>Execute</Method>
</MapItem>
</MapItems>
}
// OLD ---------------------------------------------------------------------------------------------------------------------------------------------------
/* <MapItem MessageType="MTConnect.MSG.FromFileRequest">
<Method>FromFile</Method>
</MapItem>
<MapItem MessageType="MTConnect.MSG.FromStringRequest">
<Method>FromString</Method>
</MapItem> */
/* /// OLD
Method FromString(
pRequest As MTConnect.MSG.FromStringRequest,
Output pResponse As Ens.StringResponse) As %Status
{
Set tSc = ##class(MTConnect.BO.ClassBuilder).BuildClass(pRequest.probeValue,0)
If $$$ISERR(tSc){
Return tSc
}
Set pResponse = ##class(Ens.StringResponse).%New()
Set pResponse.StringValue = $REPLACE(##class(MTConnect.BO.ClassBuilder).GetCreationTime(pRequest.currentValue,0),"Z","")
Set timestamp = pResponse.StringValue
Set tSc = ##class(MTConnect.BO.ClassBuilder).InsertCurrent(pRequest.currentValue,timestamp,0)
Return tSc
}
/// OLD
Method FromFile(
pRequest As MTConnect.MSG.FromFileRequest,
Output pResponse As Ens.StringResponse) As %Status
{
Set tSc = ##class(MTConnect.BO.ClassBuilder).BuildClass(pRequest.probePath)
If $$$ISERR(tSc){
Return tSc
}
Set tSc = ##class(MTConnect.BO.ClassBuilder).InsertCurrent(pRequest.currentPath,$P(pRequest.recievedLine,"|"))
Return tSc
} */
}