@@ -57,8 +57,18 @@ private string GetCountryCodeFromISO3(string srcISO)
5757 /// <returns></returns>
5858 public IEnumerable < OCM . API . Common . Model . ChargePoint > FromOCPI ( IEnumerable < OCM . Model . OCPI . Location > source , int dataProviderId , Dictionary < string , int > operatorMappings = null , int ? defaultOperatorId = null , HashSet < string > excludedLocations = null )
5959 {
60+ if ( source == null )
61+ {
62+ yield break ;
63+ }
64+
6065 foreach ( var i in source )
6166 {
67+ if ( i == null )
68+ {
69+ System . Diagnostics . Debug . WriteLine ( "Skipping null OCPI location entry." ) ;
70+ continue ;
71+ }
6272
6373 // Country_Code is the CPO owner country code, not the location country code
6474 // Country is the specified country code for the location but we fall back to the CPO owner country code if not specified
@@ -100,8 +110,8 @@ private string GetCountryCodeFromISO3(string srcISO)
100110 AddressLine1 = i . Address ,
101111 Town = i . City ,
102112 Postcode = i . Postal_code ,
103- Latitude = double . Parse ( i . Coordinates . Latitude ) ,
104- Longitude = double . Parse ( i . Coordinates . Longitude ) ,
113+ Latitude = double . Parse ( i . Coordinates ? . Latitude ?? throw new InvalidOperationException ( "Location coordinates latitude is missing." ) , CultureInfo . InvariantCulture ) ,
114+ Longitude = double . Parse ( i . Coordinates ? . Longitude ?? throw new InvalidOperationException ( "Location coordinates longitude is missing." ) , CultureInfo . InvariantCulture ) ,
105115 CountryID = _coreReferenceData . Countries . FirstOrDefault ( c => c . ISOCode == iso2Code ) ? . ID ,
106116 AccessComments = i . Directions ? . Any ( ) == true ? string . Join ( " " , i . Directions . Select ( f => f . Text ) . ToArray ( ) ) : null
107117 } ,
@@ -114,7 +124,7 @@ private string GetCountryCodeFromISO3(string srcISO)
114124 {
115125 evse = new List < Evse > ( i . Evses ) ;
116126 }
117- else if ( i . AdditionalProperties . ContainsKey ( "evses" ) )
127+ else if ( i . AdditionalProperties ? . ContainsKey ( "evses" ) == true )
118128 {
119129 // Older OCPI has EVSE list as an additional property
120130 evse = ( List < OCM . Model . OCPI . Evse > ) ( i . AdditionalProperties [ "evses" ] ) ;
@@ -124,12 +134,21 @@ private string GetCountryCodeFromISO3(string srcISO)
124134
125135 foreach ( var e in evse )
126136 {
137+ if ( e == null )
138+ {
139+ continue ;
140+ }
141+
127142 cp . StatusTypeID = MapOCMStatusTypeFromStatus ( e . Status , _useLiveStatus ) ;
128143
129144 if ( cp . StatusTypeID != ( int ) StandardStatusTypes . RemovedDecomissioned )
130145 {
131- foreach ( var c in e . Connectors )
146+ foreach ( var c in e . Connectors ?? Enumerable . Empty < Connector > ( ) )
132147 {
148+ if ( c == null )
149+ {
150+ continue ;
151+ }
133152
134153 var connectionInfo = new ConnectionInfo
135154 {
0 commit comments