//----------------------------------------------------------------------- // // Copyright (c) 2016 Mapbox. All rights reserved. // //----------------------------------------------------------------------- namespace Mapbox.MapMatching { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Mapbox.Json; /// Base geocode response. #if !WINDOWS_UWP //http://stackoverflow.com/a/12903628 [Serializable] #endif public class MapMatchingResponse { /// Simple constructor for deserialization public MapMatchingResponse() { } [JsonProperty("code")] public string Code; [JsonProperty("message")] public string Message; [JsonProperty("tracepoints")] public Tracepoint[] Tracepoints; [JsonProperty("matchings")] public MatchObject[] Matchings; #if !WINDOWS_UWP /// Error occured during matching public bool HasMatchingError { get { return !"ok".Equals(Code, StringComparison.InvariantCultureIgnoreCase); } } #else /// Error occured during matching public bool HasMatchingError { get { return !"ok".Equals(Code, StringComparison.OrdinalIgnoreCase); } } #endif public string MatchingError { get { string matchCode = Code.ToLower(); switch (matchCode) { case "ok": return ""; case "nomatch": return "The input did not produce any matches. features will be an empty array."; case "toomanycoordinates": return "There are to many points in the request."; case "InvalidInput": return "Invalid input: 'message' will hold an explanation of the invalid input."; case "ProfileNotFound": return "Invalid profile."; case "nosegment": return "Could not find a matching segment for input coordinates."; default: return "Unexpected error: check 'message'"; } } } /// Errors occured during web request public bool HasRequestError { get { return _requestExceptions.Count > 0; } } private ReadOnlyCollection _requestExceptions = new List().AsReadOnly(); /// Errors of underlying web request public ReadOnlyCollection RequestExceptions { get { return _requestExceptions; } } /// Assign errors of underlying web request public void SetRequestExceptions(ReadOnlyCollection exceptions) { _requestExceptions = exceptions; } } }