@@ -9,6 +9,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
99
1010using AasxIntegrationBase ;
1111using AdminShellNS ;
12+ using AdminShellNS . Extensions ;
1213using AngleSharp . Dom ;
1314using AnyUi ;
1415using Extensions ;
@@ -303,14 +304,14 @@ public static bool IsValidUriForRegistryAasByAssetIds(string location)
303304
304305 public static bool IsValidUriForRegOfRegAasByAssetId ( string location )
305306 {
306- var m = Regex . Match ( location , @"^(http(|s))://(.*?)/registry-descriptors/([-A-Za-z0-9_]{1,999})$" ,
307+ var m = Regex . Match ( location , @"^(http(|s))://(.*?)/(?: registry-descriptors/|companies\?asset_id=) ([-A-Za-z0-9_]{1,999})$" ,
307308 RegexOptions . IgnoreCase | RegexOptions . IgnorePatternWhitespace ) ;
308309 return m . Success ;
309310 }
310311
311312 public static string IsValidAndDecodeUriForRegOfRegAasByAssetId ( string location )
312313 {
313- var m = Regex . Match ( location , @"^(http(|s))://(.*?)/registry-descriptors/([-A-Za-z0-9_]{1,999})$" ,
314+ var m = Regex . Match ( location , @"^(http(|s))://(.*?)/(?: registry-descriptors/|companies\?asset_id=) ([-A-Za-z0-9_]{1,999})$" ,
314315 RegexOptions . IgnoreCase | RegexOptions . IgnorePatternWhitespace ) ;
315316 if ( ! m . Success )
316317 return null ;
@@ -353,7 +354,7 @@ public static Uri GetBaseUri(string location)
353354 // try an explicit search for known parts of ressources
354355 // (preserves scheme, host and leading pathes)
355356 var m = Regex . Match ( location , @"^(.*?)(/shells|/submodel|/concept-description|/lookup|/description"
356- + "|/shell-descriptor|/submodel-descriptor|/bulk|/serialization|/package)" ) ;
357+ + "|/shell-descriptor|/submodel-descriptor|/bulk|/serialization|/package|/registry-descriptors|/companies )" ) ;
357358 if ( m . Success )
358359 return new Uri ( m . Groups [ 1 ] . ToString ( ) + "/" ) ;
359360
@@ -366,6 +367,10 @@ public static Uri GetBaseUri(string location)
366367 {
367368 return new Uri ( location . Substring ( 0 , p ) + "/" ) ;
368369 }
370+ else
371+ {
372+ return new Uri ( location ) ;
373+ }
369374 }
370375
371376 // go to error
@@ -732,10 +737,17 @@ public static Uri BuildUriForRegOfRegAasByAssetId(Uri baseUri, string id, bool e
732737 // access
733738 if ( id ? . HasContent ( ) != true )
734739 return null ;
740+ var route = "registry-descriptors/" ;
735741
736- // try combine
737742 var assenc = encryptIds ? AdminShellUtil . Base64UrlEncode ( id ) : id ;
738- return CombineUri ( baseUri , $ "registry-descriptors/{ assenc } ") ;
743+
744+ if ( baseUri . Host . Contains ( "leo-discovery" ) )
745+ {
746+ route = "companies" ;
747+ assenc = $ "?asset_id={ assenc } ";
748+ }
749+
750+ return CombineUri ( baseUri , $ "{ route } { assenc } ") ;
739751 }
740752
741753 //
@@ -819,7 +831,10 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
819831 {
820832 // strictly check IFC
821833 var aasIfc = "" + ep [ "interface" ] ;
822- if ( aasIfc != "AAS-1.0" )
834+ if ( ! ( aasIfc == "AAS-1.0"
835+ || aasIfc == "AAS-2.0"
836+ || aasIfc == "AAS-3.0"
837+ || aasIfc == "AAS-3.1" ) )
823838 continue ;
824839
825840 // direct access HREF
@@ -843,8 +858,11 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
843858 {
844859 // strictly check IFC
845860 var smIfc = "" + smep [ "interface" ] ;
846- if ( smIfc != "SUBMODEL-1.0" )
847- continue ;
861+ if ( ! ( aasIfc == "SUBMODEL-1.0"
862+ || aasIfc == "SUBMODEL-2.0"
863+ || aasIfc == "SUBMODEL-3.0"
864+ || aasIfc == "SUBMODEL-3.1" ) )
865+ continue ;
848866
849867 // ok
850868 string href = smep . protocolInformation . href ;
@@ -969,7 +987,7 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
969987 return true ;
970988 }
971989
972- private static async Task < bool > FromRegOfRegGetAasAndSubmodels (
990+ private static async Task FromRegOfRegGetAasAndSubmodels (
973991 OnDemandListIdentifiable < IAssetAdministrationShell > prepAas ,
974992 OnDemandListIdentifiable < ISubmodel > prepSM ,
975993 ConnectExtendedRecord record ,
@@ -980,82 +998,141 @@ private static async Task<bool> FromRegOfRegGetAasAndSubmodels(
980998 List < Aas . IIdentifiable > trackNewIdentifiables = null ,
981999 List < Aas . IIdentifiable > trackLoadedIdentifiables = null ,
9821000 Action < int , int , int , int > lambdaReportProgress = null ,
983- bool compatOldAasxServer = false )
1001+ bool compatOldAasxServer = false ,
1002+ bool isLeoDiscoveryServer = false )
9841003 {
9851004 // access
9861005 if ( record == null || regDescriptor == null || assetId ? . HasContent ( ) != true )
987- return false ;
1006+ return ;
9881007
989- // The format is:
990- // {
991- // "Url": "http://example.com/6789",
992- // "Security": "",
993- // "Match": "LIKE",
994- // "Pattern": "%6789%",
995- // "Domain": "example.com",
996- // "Id": "xxx",
997- // "Info": "xxx"
998- // }
999- // However, only Url and Id are currently useful
1000-
1001- string regUrl = "" + regDescriptor [ "url" ] ;
1002- string regInfo = "" + regDescriptor [ "info" ] ;
1003- if ( regInfo == "" )
1004- regInfo = "<Unknown>" ;
10051008
1006- // valid url?
1007- if ( regUrl == "" )
1008- return false ;
10091009
1010- var basicUri = GetBaseUri ( regUrl ) ;
1011- if ( basicUri == null )
1012- return false ;
1010+ List < string > regUrls = new List < string > ( ) ;
10131011
1014- // build again a set of baseUris, but only one pattern set
1015- var baseUris = new BaseUriDict ( key : "AAS-REG" , value : basicUri . ToString ( ) ) ;
1012+ if ( isLeoDiscoveryServer )
1013+ {
1014+ //See: https://leo-discovery.admin-shell-io.com/
10161015
1017- // translate to a list of AAS-Ids ..
1018- var uriGetListOfAids = BuildUriForRegistryAasByAssetId ( baseUris . GetBaseUriForAasReg ( ) , assetId ) ;
1019- if ( compatOldAasxServer )
1020- uriGetListOfAids = BuildUriForRegistryAasByAssetLinkDeprecated ( baseUris . GetBaseUriForAasReg ( ) , assetId ) ;
1021- var listOfAids = await PackageHttpDownloadUtil . DownloadEntityToDynamicObject (
1022- uriGetListOfAids , runtimeOptions , allowFakeResponses ) ;
1016+ var endpoints = regDescriptor ? . endpoints ;
10231017
1024- if ( listOfAids == null || ! ( listOfAids is JArray ) || ( listOfAids as JArray ) . Count < 1 )
1018+ if ( endpoints != null )
1019+ {
1020+ foreach ( var endpoint in endpoints )
1021+ {
1022+ if ( endpoint [ "interface" ] == "AAS-REGISTRY-3.1"
1023+ || endpoint [ "interface" ] == "AAS-REGISTRY-3.0" )
1024+ {
1025+ var regUrl = endpoint . protocolInformation [ "href" ] ;
1026+ regUrls . Add ( "" + regUrl ) ;
1027+ }
1028+ }
1029+ }
1030+ }
1031+ else
1032+ {
1033+ // The format is:
1034+ // {
1035+ // "Url": "http://example.com/6789",
1036+ // "Security": "",
1037+ // "Match": "LIKE",
1038+ // "Pattern": "%6789%",
1039+ // "Domain": "example.com",
1040+ // "Id": "xxx",
1041+ // "Info": "xxx"
1042+ // }
1043+ // However, only Url and Id are currently useful
1044+
1045+ regUrls . Add ( "" + regDescriptor [ "url" ] ) ;
1046+ }
1047+
1048+
1049+ // valid url?
1050+ if ( regUrls . IsNullOrEmpty ( ) )
1051+ return ;
1052+
1053+ List < Uri > basicUris = new List < Uri > ( ) ;
1054+
1055+ foreach ( var regUrl in regUrls )
10251056 {
1026- runtimeOptions ? . Log ? . Info ( "Registry {0} did not translate glopbalAssetId={1} to any AAS Ids. " +
1027- "Aborting! URi was: {2}" ,
1028- basicUri , assetId , uriGetListOfAids ) ;
1029- return false ;
1057+ var basicUri = GetBaseUri ( regUrl ) ;
1058+ if ( basicUri != null )
1059+ {
1060+ basicUris . Add ( basicUri ) ;
1061+ }
1062+ }
1063+
1064+ if ( basicUris . IsNullOrEmpty ( ) )
1065+ {
1066+ return ;
10301067 }
10311068
1032- // take the individual AAS ids
1033- foreach ( var aid in listOfAids )
1069+ foreach ( var basicUri in basicUris )
10341070 {
1035- // prepare receiving the descriptor
1036- var uriGetAasDescr = BuildUriForRegistrySingleAAS ( baseUris . GetBaseUriForAasReg ( ) , aid . ToString ( ) ) ;
1037- var resAasDescr = await PackageHttpDownloadUtil . DownloadEntityToDynamicObject (
1038- uriGetAasDescr , runtimeOptions , allowFakeResponses ) ;
1071+ // build again a set of baseUris, but only one pattern set
1072+ var baseUris = new BaseUriDict ( key : "AAS-REG" , value : basicUri . ToString ( ) ) ;
10391073
1040- // have directly a single descriptor?!
1041- if ( ! ( resAasDescr is JObject ) )
1074+ // translate to a list of AAS-Ids ..
1075+ var uriGetListOfAids = BuildUriForRegistryAasByAssetId ( baseUris . GetBaseUriForAasReg ( ) , assetId ) ;
1076+ if ( compatOldAasxServer )
1077+ uriGetListOfAids = BuildUriForRegistryAasByAssetLinkDeprecated ( baseUris . GetBaseUriForAasReg ( ) , assetId ) ;
1078+
1079+ try
10421080 {
1043- runtimeOptions ? . Log ? . Info ( "Registry did not return a single AAS descriptor! Aborting. URI was: {0}" ,
1044- uriGetAasDescr ) ;
1045- return false ;
1046- }
1081+ var listOfAids = await PackageHttpDownloadUtil . DownloadEntityToDynamicObject (
1082+ uriGetListOfAids , runtimeOptions , allowFakeResponses ) ;
10471083
1048- lambdaReportProgress ? . Invoke ( 0 , 0 , 0 , 1 ) ;
1084+ if ( listOfAids == null || ! ( listOfAids is JArray ) || ( listOfAids as JArray ) . Count < 1 )
1085+ {
1086+ runtimeOptions ? . Log ? . Info ( "Registry {0} did not translate globalAssetId={1} to any AAS Ids. " +
1087+ "Aborting! URi was: {2}" ,
1088+ basicUri , assetId , uriGetListOfAids ) ;
1089+ }
1090+ else
1091+ {
1092+ // take the individual AAS ids
1093+ foreach ( var aid in listOfAids )
1094+ {
1095+ // prepare receiving the descriptor
1096+ var uriGetAasDescr = BuildUriForRegistrySingleAAS ( baseUris . GetBaseUriForAasReg ( ) , aid . ToString ( ) ) ;
1097+ var resAasDescr = await PackageHttpDownloadUtil . DownloadEntityToDynamicObject (
1098+ uriGetAasDescr , runtimeOptions , allowFakeResponses ) ;
1099+
1100+ // have directly a single descriptor?!
1101+ if ( ! ( resAasDescr is JObject ) )
1102+ {
1103+ runtimeOptions ? . Log ? . Info ( "Registry did not return a single AAS descriptor! Aborting. URI was: {0}" ,
1104+ uriGetAasDescr ) ;
1105+ }
10491106
1050- // refer to dedicated function
1051- await FromRegistryGetAasAndSubmodels (
1052- prepAas , prepSM , record , runtimeOptions , allowFakeResponses , resAasDescr ,
1053- trackNewIdentifiables , trackLoadedIdentifiables ,
1054- lambdaReportProgress : lambdaReportProgress ) ;
1107+ lambdaReportProgress ? . Invoke ( 0 , 0 , 0 , 1 ) ;
1108+
1109+ try
1110+ {
1111+ // refer to dedicated function
1112+ await FromRegistryGetAasAndSubmodels (
1113+ prepAas , prepSM , record , runtimeOptions , allowFakeResponses , resAasDescr ,
1114+ trackNewIdentifiables , trackLoadedIdentifiables ,
1115+ lambdaReportProgress : lambdaReportProgress ) ;
1116+ }
1117+ catch ( Exception e )
1118+ {
1119+ runtimeOptions ? . Log ? . Info ( "Download aas and submodels from registry {0} failed globalAssetId={1} to any AAS Ids. " +
1120+ "Aborting! AAS id was: {2}, message was {3}" ,
1121+ basicUri , assetId , aid , e . Message ) ;
1122+ }
1123+
1124+ }
1125+ }
1126+ }
1127+ catch ( Exception e )
1128+ {
1129+ runtimeOptions ? . Log ? . Info ( "Download descriptors from registry {0} failed globalAssetId={1} to any AAS Ids. " +
1130+ "Aborting! URi was: {2}, message was {3}" ,
1131+ basicUri , assetId , uriGetListOfAids , e . Message ) ;
1132+ }
10551133 }
10561134
1057- // OK?
1058- return true ;
1135+ return ;
10591136 }
10601137
10611138 public override async Task < bool > LoadFromSourceAsync (
@@ -1221,6 +1298,12 @@ protected static async Task<AdminShellPackageEnvBase> LoadFromSourceInternalAsyn
12211298 }
12221299 else
12231300 {
1301+ bool isFXLeoDiscoveryServer = fullItemLocation . Contains ( "leo-discovery" ) ;
1302+ if ( isFXLeoDiscoveryServer )
1303+ {
1304+ resObj = resObj [ "data" ] ;
1305+ }
1306+
12241307 foreach ( var res in resObj )
12251308 {
12261309 // refer to dedicated function
@@ -1230,7 +1313,8 @@ await FromRegOfRegGetAasAndSubmodels(
12301313 trackNewIdentifiables , trackLoadedIdentifiables ,
12311314 lambdaReportProgress : lambdaReportAasSm ,
12321315 // TODO: check!!
1233- compatOldAasxServer : true ) ;
1316+ compatOldAasxServer : isFXLeoDiscoveryServer ? false : true ,
1317+ isLeoDiscoveryServer : isFXLeoDiscoveryServer ) ;
12341318 }
12351319 }
12361320 }
0 commit comments