From 7d67d0e449ea15bed6be2a6256a90acf24be01ec Mon Sep 17 00:00:00 2001 From: Aydar Shamsutdinov Date: Sat, 5 Oct 2013 19:09:26 +0400 Subject: [PATCH] Added 'Status' property for request results. Now, it is possible to handle the reason of empty response --- NGeo/GeoNames/GeoNamesClient.cs | 10 ++++++++++ NGeo/GeoNames/Results.cs | 7 +++++-- NGeo/GeoNames/Status.cs | 14 ++++++++++++++ NGeo/NGeo.csproj | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 NGeo/GeoNames/Status.cs diff --git a/NGeo/GeoNames/GeoNamesClient.cs b/NGeo/GeoNames/GeoNamesClient.cs index 3ec1693..55227e8 100644 --- a/NGeo/GeoNames/GeoNamesClient.cs +++ b/NGeo/GeoNames/GeoNamesClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Net; using System.ServiceModel; @@ -164,6 +165,15 @@ public ReadOnlyCollection Children(int geoNameId, string userName, { var response = ChannelChildren(geoNameId, userName, resultStyle, maxRows); var results = response.Items; + if (response.Status != null) + { + switch (response.Status.Value) + { + case 15: + return new ReadOnlyCollection(new List()); + //TODO: Add another statuses processing + } + } return results != null ? new ReadOnlyCollection(results) : null; } diff --git a/NGeo/GeoNames/Results.cs b/NGeo/GeoNames/Results.cs index 886c3c3..06ee7c2 100644 --- a/NGeo/GeoNames/Results.cs +++ b/NGeo/GeoNames/Results.cs @@ -7,12 +7,15 @@ namespace NGeo.GeoNames [DataContract] public sealed class Results : IEnumerable { - [DataMember(Name = "geonames")] + [DataMember(Name = "geonames", IsRequired = false)] internal List Items { get; set; } - [DataMember(Name = "totalResultsCount")] + [DataMember(Name = "totalResultsCount", IsRequired = false)] public int? Size { get; internal set; } + [DataMember(Name="status", IsRequired = false)] + public Status Status { get; set; } + public IEnumerator GetEnumerator() { return Items.GetEnumerator(); diff --git a/NGeo/GeoNames/Status.cs b/NGeo/GeoNames/Status.cs new file mode 100644 index 0000000..512862a --- /dev/null +++ b/NGeo/GeoNames/Status.cs @@ -0,0 +1,14 @@ +using System.Runtime.Serialization; + +namespace NGeo.GeoNames +{ + [DataContract] + public sealed class Status + { + [DataMember(Name = "message")] + public string Message { get; set; } + + [DataMember(Name = "value")] + public int Value { get; set; } + } +} \ No newline at end of file diff --git a/NGeo/NGeo.csproj b/NGeo/NGeo.csproj index 002aa97..fccff89 100644 --- a/NGeo/NGeo.csproj +++ b/NGeo/NGeo.csproj @@ -80,6 +80,7 @@ +