@@ -257,7 +257,7 @@ public static async Task<IReadOnlyDictionary<Dtmi, DTEntityInfo>> GetAndParseDTD
257
257
}
258
258
else
259
259
return null ;
260
-
260
+
261
261
}
262
262
263
263
#endregion
@@ -380,6 +380,23 @@ private static DTDLContainer BuildDynamicContent(JObject dtdl)
380
380
result . DTDLGeneratedData . Telemetries = telemetries ;
381
381
}
382
382
383
+ telemetries = ExtractTelemetriesWithUnit ( contents ) ;
384
+ if ( telemetries != null && telemetries . Any ( ) )
385
+ {
386
+ if ( result . DTDLGeneratedData == null )
387
+ result . DTDLGeneratedData = new DTDLGeneratedData ( ) ;
388
+
389
+ if ( result . DTDLGeneratedData . Telemetries == null )
390
+ result . DTDLGeneratedData . Telemetries = telemetries ;
391
+ else
392
+ {
393
+ foreach ( var item in telemetries )
394
+ {
395
+ result . DTDLGeneratedData . Telemetries . Add ( item ) ;
396
+ }
397
+ }
398
+ }
399
+
383
400
//Look for properties (JSON)
384
401
JArray readableProperties = ExtractReadableProperties ( contents ) ;
385
402
if ( readableProperties != null && readableProperties . Any ( ) )
@@ -390,6 +407,23 @@ private static DTDLContainer BuildDynamicContent(JObject dtdl)
390
407
result . DTDLGeneratedData . ReadableProperties = readableProperties ;
391
408
}
392
409
410
+ readableProperties = ExtractReadablePropertiesWithUnit ( contents ) ;
411
+ if ( readableProperties != null && readableProperties . Any ( ) )
412
+ {
413
+ if ( result . DTDLGeneratedData == null )
414
+ result . DTDLGeneratedData = new DTDLGeneratedData ( ) ;
415
+
416
+ if ( result . DTDLGeneratedData . ReadableProperties == null )
417
+ result . DTDLGeneratedData . ReadableProperties = readableProperties ;
418
+ else
419
+ {
420
+ foreach ( var item in readableProperties )
421
+ {
422
+ result . DTDLGeneratedData . ReadableProperties . Add ( item ) ;
423
+ }
424
+ }
425
+ }
426
+
393
427
JArray writableProperties = ExtractWritableProperties ( contents ) ;
394
428
if ( writableProperties != null && writableProperties . Any ( ) )
395
429
{
@@ -399,6 +433,23 @@ private static DTDLContainer BuildDynamicContent(JObject dtdl)
399
433
result . DTDLGeneratedData . WritableProperties = writableProperties ;
400
434
}
401
435
436
+ writableProperties = ExtractWritablePropertiesWithUnit ( contents ) ;
437
+ if ( writableProperties != null && writableProperties . Any ( ) )
438
+ {
439
+ if ( result . DTDLGeneratedData == null )
440
+ result . DTDLGeneratedData = new DTDLGeneratedData ( ) ;
441
+
442
+ if ( result . DTDLGeneratedData . WritableProperties == null )
443
+ result . DTDLGeneratedData . WritableProperties = writableProperties ;
444
+ else
445
+ {
446
+ foreach ( var item in writableProperties )
447
+ {
448
+ result . DTDLGeneratedData . WritableProperties . Add ( item ) ;
449
+ }
450
+ }
451
+ }
452
+
402
453
//Commands
403
454
JArray commands = ExtractCommands ( contents ) ;
404
455
if ( commands != null && commands . Any ( ) )
@@ -414,7 +465,37 @@ private static DTDLContainer BuildDynamicContent(JObject dtdl)
414
465
private static JArray ExtractTelemetries ( JArray contents )
415
466
{
416
467
JArray result = null ;
417
- var telemetries = contents . Where ( i => i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "telemetry" ) ;
468
+ var telemetries = contents . Where ( i => i [ "@type" ] is not JArray && i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "telemetry" ) ;
469
+ if ( telemetries != null && telemetries . Any ( ) )
470
+ {
471
+ result = new JArray ( ) ;
472
+
473
+ JObject tmp = null ;
474
+ string tmpPropertyName = string . Empty ;
475
+
476
+ Random random = new Random ( DateTime . Now . Millisecond ) ;
477
+ foreach ( var item in telemetries )
478
+ {
479
+ tmpPropertyName = item [ "name" ] . Value < string > ( ) ;
480
+
481
+ tmp = new JObject ( ) ;
482
+
483
+ JProperty jProperty = AddCreatedProperties ( tmpPropertyName , item [ "schema" ] . Value < string > ( ) , random ) ;
484
+
485
+ if ( jProperty != null )
486
+ tmp . Add ( jProperty ) ;
487
+
488
+ result . Add ( tmp ) ;
489
+ }
490
+ }
491
+
492
+ return result ;
493
+ }
494
+
495
+ private static JArray ExtractTelemetriesWithUnit ( JArray contents )
496
+ {
497
+ JArray result = null ;
498
+ var telemetries = contents . Where ( i => i [ "@type" ] is JArray && ( ( JArray ) i [ "@type" ] ) [ 0 ] . Value < string > ( ) . ToLower ( ) == "telemetry" ) ;
418
499
if ( telemetries != null && telemetries . Any ( ) )
419
500
{
420
501
result = new JArray ( ) ;
@@ -449,6 +530,8 @@ private static JArray ExtractWritableProperties(JArray contents)
449
530
i =>
450
531
( i is JObject )
451
532
&&
533
+ ( i [ "@type" ] is not JArray )
534
+ &&
452
535
i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "property"
453
536
&&
454
537
( ( JObject ) i ) . ContainsKey ( "writable" ) && i [ "writable" ] . Value < bool > ( )
@@ -481,13 +564,57 @@ private static JArray ExtractWritableProperties(JArray contents)
481
564
return result ;
482
565
}
483
566
567
+ private static JArray ExtractWritablePropertiesWithUnit ( JArray contents )
568
+ {
569
+ JArray result = null ;
570
+
571
+ var properties = contents . Where (
572
+ i =>
573
+ ( i is JObject )
574
+ &&
575
+ ( i [ "@type" ] is JArray )
576
+ &&
577
+ ( ( JArray ) i [ "@type" ] ) [ 0 ] . Value < string > ( ) . ToLower ( ) == "property"
578
+ &&
579
+ ( ( JObject ) i ) . ContainsKey ( "writable" ) && i [ "writable" ] . Value < bool > ( )
580
+ ) ;
581
+
582
+
583
+ if ( properties != null && properties . Any ( ) )
584
+ {
585
+ result = new JArray ( ) ;
586
+
587
+ JObject tmp = null ;
588
+ string tmpPropertyName = string . Empty ;
589
+
590
+ Random random = new Random ( DateTime . Now . Millisecond ) ;
591
+ foreach ( var item in properties )
592
+ {
593
+ tmpPropertyName = item [ "name" ] . Value < string > ( ) ;
594
+
595
+ tmp = new JObject ( ) ;
596
+
597
+ JProperty jProperty = AddCreatedProperties ( tmpPropertyName , item [ "schema" ] . Value < string > ( ) , random ) ;
598
+
599
+ if ( jProperty != null )
600
+ tmp . Add ( jProperty ) ;
601
+
602
+ result . Add ( tmp ) ;
603
+ }
604
+ }
605
+
606
+ return result ;
607
+ }
608
+
484
609
private static JArray ExtractReadableProperties ( JArray contents )
485
610
{
486
611
JArray result = null ;
487
612
var properties = contents . Where (
488
613
i =>
489
614
( i is JObject )
490
615
&&
616
+ i [ "@type" ] is not JArray
617
+ &&
491
618
i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "property"
492
619
&&
493
620
(
@@ -522,10 +649,53 @@ private static JArray ExtractReadableProperties(JArray contents)
522
649
return result ;
523
650
}
524
651
652
+ private static JArray ExtractReadablePropertiesWithUnit ( JArray contents )
653
+ {
654
+ JArray result = null ;
655
+ var properties = contents . Where (
656
+ i =>
657
+ ( i is JObject )
658
+ &&
659
+ i [ "@type" ] is JArray
660
+ &&
661
+ ( ( JArray ) i [ "@type" ] ) [ 0 ] . Value < string > ( ) . ToLower ( ) == "property"
662
+ &&
663
+ (
664
+ ! ( ( JObject ) i ) . ContainsKey ( "writable" )
665
+ |
666
+ ( ( ( JObject ) i ) . ContainsKey ( "writable" ) && ! i [ "writable" ] . Value < bool > ( ) )
667
+ )
668
+ ) ;
669
+
670
+ if ( properties != null && properties . Any ( ) )
671
+ {
672
+ result = new JArray ( ) ;
673
+ JObject tmp = null ;
674
+ string tmpPropertyName = string . Empty ;
675
+
676
+ Random random = new Random ( DateTime . Now . Millisecond ) ;
677
+ foreach ( var item in properties )
678
+ {
679
+ tmpPropertyName = item [ "name" ] . Value < string > ( ) ;
680
+
681
+ tmp = new JObject ( ) ;
682
+
683
+ JProperty jProperty = AddCreatedProperties ( tmpPropertyName , item [ "schema" ] . Value < string > ( ) , random ) ;
684
+
685
+ if ( jProperty != null )
686
+ tmp . Add ( jProperty ) ;
687
+
688
+ result . Add ( tmp ) ;
689
+ }
690
+ }
691
+
692
+ return result ;
693
+ }
694
+
525
695
private static JArray ExtractCommands ( JArray contents )
526
696
{
527
697
JArray result = null ;
528
- var commands = contents . Where ( i => i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "command" ) ;
698
+ var commands = contents . Where ( i => i [ "@type" ] is not JArray && i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "command" ) ;
529
699
if ( commands != null && commands . Any ( ) )
530
700
{
531
701
result = new JArray ( ) ;
@@ -589,7 +759,7 @@ private static JArray ExtractCommands(JArray contents)
589
759
private static JArray ExtractComponents ( JArray contents )
590
760
{
591
761
JArray result = null ;
592
- var properties = contents . Where ( i => i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "component" ) ;
762
+ var properties = contents . Where ( i => i [ "@type" ] is not JArray && i [ "@type" ] . Value < string > ( ) . ToLower ( ) == "component" ) ;
593
763
if ( properties != null && properties . Any ( ) )
594
764
result = JArray . FromObject ( properties ) ;
595
765
0 commit comments