|
|
@ -18,6 +18,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
|
@ -28,7 +29,7 @@ namespace Routeguide |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public static class RouteGuideUtil |
|
|
|
public static class RouteGuideUtil |
|
|
|
{ |
|
|
|
{ |
|
|
|
public const string DefaultFeaturesFile = "route_guide_db.json"; |
|
|
|
public const string DefaultFeaturesResourceName = "RouteGuide.route_guide_db.json"; |
|
|
|
|
|
|
|
|
|
|
|
private const double CoordFactor = 1e7; |
|
|
|
private const double CoordFactor = 1e7; |
|
|
|
|
|
|
|
|
|
|
@ -90,12 +91,12 @@ namespace Routeguide |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Parses features from a JSON file. |
|
|
|
/// Parses features from an embedded resource. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public static List<Feature> ParseFeatures(string filename) |
|
|
|
public static List<Feature> LoadFeatures() |
|
|
|
{ |
|
|
|
{ |
|
|
|
var features = new List<Feature>(); |
|
|
|
var features = new List<Feature>(); |
|
|
|
var jsonFeatures = JsonConvert.DeserializeObject<List<JsonFeature>>(File.ReadAllText(filename)); |
|
|
|
var jsonFeatures = JsonConvert.DeserializeObject<List<JsonFeature>>(ReadFeaturesFromResource()); |
|
|
|
|
|
|
|
|
|
|
|
foreach(var jsonFeature in jsonFeatures) |
|
|
|
foreach(var jsonFeature in jsonFeatures) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -108,6 +109,19 @@ namespace Routeguide |
|
|
|
return features; |
|
|
|
return features; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static string ReadFeaturesFromResource() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var stream = typeof(RouteGuideUtil).GetTypeInfo().Assembly.GetManifestResourceStream(DefaultFeaturesResourceName); |
|
|
|
|
|
|
|
if (stream == null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new IOException(string.Format("Error loading the embedded resource \"{0}\"", DefaultFeaturesResourceName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
using (var streamReader = new StreamReader(stream)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return streamReader.ReadToEnd(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#pragma warning disable 0649 // Suppresses "Field 'x' is never assigned to". |
|
|
|
#pragma warning disable 0649 // Suppresses "Field 'x' is never assigned to". |
|
|
|
private class JsonFeature |
|
|
|
private class JsonFeature |
|
|
|
{ |
|
|
|
{ |
|
|
|