@@ -1790,35 +1790,14 @@ private AssetExt MapAsset(CIMIdentifiedObject cimObj, AssetExt asset, bool force
17901790 asset . lifecycle . installationDate = Convert . ToDateTime ( cimObj . GetPropertyValueAsString ( "cim.asset.installationdate" ) ) ;
17911791 }
17921792
1793- if ( cimObj . ContainsPropertyValue ( "cim.ref.organisationroles" ) )
1793+ asset . OrganisationRoles = MapRelation ( cimObj , "cim.ref.organisationroles" , ( string referenceType , string @ref ) =>
17941794 {
1795- string roleRef = cimObj . GetPropertyValueAsString ( "cim.ref.organisationroles" ) ;
1796-
1797- if ( roleRef != null )
1795+ return new AssetOrganisationRole ( )
17981796 {
1799- string [ ] roles = roleRef . Split ( "," ) ;
1800-
1801- List < AssetOrganisationRole > orgRoles = new ( ) ;
1802-
1803- foreach ( var role in roles )
1804- {
1805- string [ ] refTypeAndRef = role . Split ( ":" ) ;
1806-
1807- if ( refTypeAndRef . Length == 2 )
1808- {
1809- AssetOrganisationRole assetOrganisationRole = new AssetOrganisationRole ( )
1810- {
1811- referenceType = refTypeAndRef [ 0 ] ,
1812- @ref = refTypeAndRef [ 1 ]
1813- } ;
1814-
1815- orgRoles . Add ( assetOrganisationRole ) ;
1816- }
1817- }
1818-
1819- asset . OrganisationRoles = orgRoles . ToArray ( ) ;
1820- }
1821- }
1797+ referenceType = referenceType ,
1798+ @ref = @ref
1799+ } ;
1800+ } ) ;
18221801
18231802
18241803 if ( cimObj . ContainsPropertyValue ( "cim.asset.productmodel" ) )
@@ -1834,10 +1813,16 @@ private AssetExt MapAsset(CIMIdentifiedObject cimObj, AssetExt asset, bool force
18341813 return asset ;
18351814 }
18361815
1837-
18381816 private AssetExt MapIdentifiedObjectAssetRef ( CIMIdentifiedObject cimObj , PowerSystemResource xmlObj , bool forceAssetRecord = false )
18391817 {
1840- xmlObj . Assets = new PowerSystemResourceAssets ( ) { @ref = "hest" } ;
1818+ xmlObj . Assets = MapRelation ( cimObj , "cim.ref.assets" , ( string referenceType , string @ref ) =>
1819+ {
1820+ return new PowerSystemResourceAssets ( )
1821+ {
1822+ referenceType = referenceType ,
1823+ @ref = @ref
1824+ } ;
1825+ } ) . FirstOrDefault ( ) ;
18411826
18421827 return null ;
18431828 }
@@ -2230,7 +2215,42 @@ private IEnumerable<IdentifiedObject> MapTerminals(CIMConductingEquipment cimObj
22302215 }
22312216 }
22322217 }
2233-
2218+
2219+ private T [ ] MapRelation < T > ( CIMIdentifiedObject cimObj , string propertyName , Func < string , string , T > f )
2220+ {
2221+ if ( cimObj . ContainsPropertyValue ( propertyName ) )
2222+ {
2223+ string roleRef = cimObj . GetPropertyValueAsString ( propertyName ) ;
2224+
2225+ if ( roleRef != null )
2226+ {
2227+ string [ ] roles = roleRef . Split ( "," ) ;
2228+
2229+ List < T > orgRoles = new ( ) ;
2230+
2231+ foreach ( var role in roles )
2232+ {
2233+ string [ ] refTypeAndRef = role . Split ( ":" ) ;
2234+
2235+ if ( refTypeAndRef . Length == 1 )
2236+ {
2237+ T assetOrganisationRole = f ( null , refTypeAndRef [ 0 ] ) ;
2238+ orgRoles . Add ( assetOrganisationRole ) ;
2239+ }
2240+ else if ( refTypeAndRef . Length == 2 )
2241+ {
2242+ T assetOrganisationRole = f ( refTypeAndRef [ 0 ] , refTypeAndRef [ 1 ] ) ;
2243+ orgRoles . Add ( assetOrganisationRole ) ;
2244+ }
2245+ }
2246+
2247+ return orgRoles . ToArray ( ) ;
2248+ }
2249+ }
2250+
2251+ return [ ] ;
2252+ }
2253+
22342254 private Location CreateLocation ( double [ ] coords , CIMIdentifiedObject cimObj )
22352255 {
22362256 Location loc = null ;
0 commit comments