Skip to content

Commit

Permalink
Add string format provider arguments to StartsWith and Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ludwig authored and Dan Ludwig committed Feb 28, 2013
1 parent 276295d commit c0aca0b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 43 deletions.
60 changes: 30 additions & 30 deletions NGeo/GeoNames/GeoNamesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class GeoNamesClient : ClientBase<IInvokeGeoNamesServices>, IConsumeGeoNa
private const string ClosedConnectionMessage = "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.";

/// <summary>
/// Find nearby populated place / reverse geocoding. See
/// <seealso cref="http://www.geonames.org/export/web-services.html#findNearbyPlaceName">Official
/// Find nearby populated place / reverse geocoding. See
/// <seealso cref="http://www.geonames.org/export/web-services.html#findNearbyPlaceName">Official
/// GeoNames findNearbyPlaceName Documentation</seealso> for more information.
/// </summary>
/// <param name="finder">Arguments sent to the GeoNames service.</param>
/// <returns>The closest populated place for the lat/lng query as xml document. The unit of the
/// <returns>The closest populated place for the lat/lng query as xml document. The unit of the
/// distance element is 'km'.</returns>
public ReadOnlyCollection<Toponym> FindNearbyPlaceName(NearbyPlaceNameFinder finder)
{
Expand All @@ -50,19 +50,19 @@ private Results<Toponym> ChannelFindNearbyPlaceName(NearbyPlaceNameFinder finder
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelFindNearbyPlaceName(finder, ++retry);
throw;
}
}

/// <summary>
/// Lookup a place by postal code. See
/// <seealso cref="http://www.geonames.org/export/web-services.html#postalCodeLookupJSON">Official
/// Lookup a place by postal code. See
/// <seealso cref="http://www.geonames.org/export/web-services.html#postalCodeLookupJSON">Official
/// GeoNames postalCodeLookup Documentation</seealso> for more information.
/// </summary>
/// <param name="lookup">Arguments sent to the GeoNames service.</param>
/// <returns>The closest populated place for the postal code/country query. The unit of the
/// <returns>The closest populated place for the postal code/country query. The unit of the
/// distance element is 'km'.</returns>
public ReadOnlyCollection<PostalCode> LookupPostalCode(PostalCodeLookup lookup)
{
Expand All @@ -82,15 +82,15 @@ private PostalCodeResults ChannelLookupPostalCode(PostalCodeLookup lookup, int r
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelLookupPostalCode(lookup, ++retry);
throw;
}
}

/// <summary>
/// Postal Code Country Info (countries available with min & max postal codes). See
/// <seealso cref="http://www.geonames.org/export/web-services.html#postalCodeCountryInfo">Official
/// Postal Code Country Info (countries available with min & max postal codes). See
/// <seealso cref="http://www.geonames.org/export/web-services.html#postalCodeCountryInfo">Official
/// GeoNames postalCodeCountryInfo Documentation</seealso> for more information.
/// </summary>
/// <param name="userName">Your user name.</param>
Expand All @@ -110,7 +110,7 @@ private Results<PostalCodedCountry> ChannelPostalCodeCountryInfo(string userName
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelPostalCodeCountryInfo(userName, ++retry);
throw;
}
Expand All @@ -136,27 +136,27 @@ private Toponym ChannelGet(int geoNameId, string userName, int retry = 0)
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelGet(geoNameId, userName, ++retry);
throw;
}
}

/// <summary>
/// Returns the children (admin divisions and populated places) for a given geonameId. The children are the
/// administrative divisions within an other administrative division, like the counties (ADM2) in a state (ADM1)
/// or also the countries in a continent. The leafs are populated places, other feature classes like spots,
/// mountains etc are not included in this service. Use
/// the <seealso cref="http://www.geonames.org/export/geonames-search.html">search service</seealso> if you need
/// other feature classes as well. See
/// <seealso cref="http://www.geonames.org/export/place-hierarchy.html#children">Official GeoNames children
/// Returns the children (admin divisions and populated places) for a given geonameId. The children are the
/// administrative divisions within an other administrative division, like the counties (ADM2) in a state (ADM1)
/// or also the countries in a continent. The leafs are populated places, other feature classes like spots,
/// mountains etc are not included in this service. Use
/// the <seealso cref="http://www.geonames.org/export/geonames-search.html">search service</seealso> if you need
/// other feature classes as well. See
/// <seealso cref="http://www.geonames.org/export/place-hierarchy.html#children">Official GeoNames children
/// Documentation</seealso> for more information.
/// </summary>
/// <param name="geoNameId">The GeoName ID of the parent.</param>
/// <param name="userName">Your user name.</param>
/// <param name="resultStyle">Amount of detail returned by the GeoNames service.
/// <param name="resultStyle">Amount of detail returned by the GeoNames service.
/// Default value is full.</param>
/// <param name="maxRows">Maximum results returned by the service.
/// <param name="maxRows">Maximum results returned by the service.
/// Default value is 200.</param>
/// <returns>The children (admin divisions and populated places) for a given geonameId.</returns>
public ReadOnlyCollection<Toponym> Children(int geoNameId, string userName,
Expand All @@ -175,19 +175,19 @@ private Results<Toponym> ChannelChildren(int geoNameId, string userName, ResultS
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelChildren(geoNameId, userName, resultStyle, maxRows, ++retry);
throw;
}
}

/// <summary>
/// Country Info (Bounding Box, Capital, Area in square km, Population). See
/// <seealso cref="http://www.geonames.org/export/web-services.html#countryInfo">Official
/// Country Info (Bounding Box, Capital, Area in square km, Population). See
/// <seealso cref="http://www.geonames.org/export/web-services.html#countryInfo">Official
/// GeoNames countryInfo Documentation</seealso> for more information.
/// </summary>
/// <param name="userName">Your user name.</param>
/// <returns>Country information : Capital, Population, Area in square km,
/// <returns>Country information : Capital, Population, Area in square km,
/// Bounding Box of mainland (excluding offshore islands).</returns>
public ReadOnlyCollection<Country> Countries(string userName)
{
Expand All @@ -204,20 +204,20 @@ private Results<Country> ChannelCountries(string userName, int retry = 0)
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelCountries(userName, ++retry);
throw;
}
}

/// <summary>
/// Returns all GeoNames higher up in the hierarchy of a place name. See
/// <seealso cref="http://www.geonames.org/export/place-hierarchy.html#hierarchy">Official GeoNames
/// Returns all GeoNames higher up in the hierarchy of a place name. See
/// <seealso cref="http://www.geonames.org/export/place-hierarchy.html#hierarchy">Official GeoNames
/// hierarchy Documentation</seealso> for more information.
/// </summary>
/// <param name="geoNameId">The GeoName ID of the child toponym.</param>
/// <param name="userName">Your user name.</param>
/// <param name="resultStyle">Amount of detail returned by the GeoNames service.
/// <param name="resultStyle">Amount of detail returned by the GeoNames service.
/// Default value is full.</param>
/// <returns>All GeoNames higher up in the hierarchy of a place name.</returns>
public Hierarchy Hierarchy(int geoNameId, string userName, ResultStyle resultStyle = ResultStyle.Medium)
Expand All @@ -234,7 +234,7 @@ private Hierarchy ChannelHierarchy(int geoNameId, string userName, ResultStyle r
}
catch (WebException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage))
if (retry < RetryLimit && ex.Message.StartsWith(ClosedConnectionMessage, StringComparison.Ordinal))
return ChannelHierarchy(geoNameId, userName, resultStyle, ++retry);
throw;
}
Expand Down
5 changes: 3 additions & 2 deletions NGeo/GeoNames/PostalCodedCountry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using System.Globalization;
using System.Runtime.Serialization;

namespace NGeo.GeoNames
{
Expand All @@ -22,7 +23,7 @@ public class PostalCodedCountry

public override string ToString()
{
return string.Format("{0} ({1}): {2} - {3} ({4} total)",
return string.Format(CultureInfo.InvariantCulture, "{0} ({1}): {2} - {3} ({4} total)",
CountryCode, CountryName, MinPostalCode, MaxPostalCode, NumberOfPostalCodes);
}

Expand Down
23 changes: 12 additions & 11 deletions NGeo/Yahoo/GeoPlanet/GeoPlanetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace NGeo.Yahoo.GeoPlanet
public sealed class GeoPlanetClient : ClientBase<IInvokeGeoPlanetServices>, IConsumeGeoPlanet
{
private const int RetryLimit = 5;
private const string XmlDeserializeMessage = "Unable to deserialize XML body";

public Place Place(int woeId, string appId, RequestView view = RequestView.Long)
{
Expand Down Expand Up @@ -41,7 +42,7 @@ private PlaceResponse ChannelPlace(int woeId, string appId, RequestView view, in
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelPlace(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -81,7 +82,7 @@ private PlacesResponse ChannelPlaces(string query, string appId, RequestView vie
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelPlaces(query, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ private PlaceResponse ChannelParent(int woeId, string appId, RequestView view, i
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelParent(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -150,7 +151,7 @@ private PlacesResponse ChannelAncestors(int woeId, string appId, RequestView vie
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelAncestors(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -186,7 +187,7 @@ private PlacesResponse ChannelBelongTos(int woeId, string appId, RequestView vie
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelBelongTos(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -215,7 +216,7 @@ private PlaceTypesResponse ChannelTypes(string appId, RequestView view, int retr
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelTypes(appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -250,7 +251,7 @@ private PlacesResponse ChannelContinents(string appId, RequestView view, int ret
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelContinents(appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -279,7 +280,7 @@ private PlacesResponse ChannelCountries(string appId, RequestView view, int retr
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelCountries(appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -315,7 +316,7 @@ private PlacesResponse ChannelStates(int woeId, string appId, RequestView view,
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelStates(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -356,7 +357,7 @@ private PlacesResponse ChannelCounties(int woeId, string appId, RequestView view
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelCounties(woeId, appId, view, ++retry);
throw;
}
Expand Down Expand Up @@ -400,7 +401,7 @@ private ConcordanceResponse ChannelConcordance(ConcordanceNamespace nameSpace, s
}
catch (SerializationException ex)
{
if (retry < RetryLimit && ex.Message.StartsWith("Unable to deserialize XML body"))
if (retry < RetryLimit && ex.Message.StartsWith(XmlDeserializeMessage, StringComparison.Ordinal))
return ChannelConcordance(nameSpace, id, appId, ++retry);
throw;
}
Expand Down

0 comments on commit c0aca0b

Please sign in to comment.