diff --git a/Geo.Raven.Silverlight4/Geo.Raven.Silverlight4.csproj b/Geo.Raven.Silverlight4/Geo.Raven.Silverlight4.csproj new file mode 100644 index 0000000..56e3f8d --- /dev/null +++ b/Geo.Raven.Silverlight4/Geo.Raven.Silverlight4.csproj @@ -0,0 +1,107 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {88367AA2-A54F-4C50-9264-BB2AFCA23C5C} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Geo.Raven.Silverlight4 + Geo.Raven.Silverlight4 + Silverlight + v4.0 + $(TargetFrameworkVersion) + false + true + true + ..\ + true + + + + v3.5 + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + ..\packages\RavenDB.Client.1.2.2078-Unstable\lib\sl40\AsyncCtpLibrary_Silverlight.dll + + + + ..\packages\RavenDB.Client.1.2.2078-Unstable\lib\sl40\Raven.Client.Silverlight-4.dll + + + + + $(TargetFrameworkDirectory)System.Core.dll + + + + + + + + GeoContractResolver.cs + + + GeoIndexCreationTask.cs + + + GeoRavenExtensions.cs + + + GeoValueProvider.cs + + + + + + + + + {b2e32781-a0ae-4803-8de0-92a95f218363} + Geo + + + + + + + + + + + + + \ No newline at end of file diff --git a/Geo.Raven.Silverlight4/Properties/AssemblyInfo.cs b/Geo.Raven.Silverlight4/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..32c67ad --- /dev/null +++ b/Geo.Raven.Silverlight4/Properties/AssemblyInfo.cs @@ -0,0 +1,34 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Geo.Raven.Silverlight")] +[assembly: AssemblyDescription("RavenDB Integration for Geo")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Geo.Raven.Silverlight")] +[assembly: AssemblyCopyright("Copyright © Simon Bartlett 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("88367aa2-a54f-4c50-9264-bb2afca23c5c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/Geo.Raven.Silverlight4/packages.config b/Geo.Raven.Silverlight4/packages.config new file mode 100644 index 0000000..0a6f5b7 --- /dev/null +++ b/Geo.Raven.Silverlight4/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Geo.Raven.Silverlight5/Geo.Raven.Silverlight5.csproj b/Geo.Raven.Silverlight5/Geo.Raven.Silverlight5.csproj new file mode 100644 index 0000000..1e42af7 --- /dev/null +++ b/Geo.Raven.Silverlight5/Geo.Raven.Silverlight5.csproj @@ -0,0 +1,107 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {A3B76D9C-E0EF-4B8F-8477-00F406C11A3D} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Geo.Raven.Silverlight5 + Geo.Raven.Silverlight5 + Silverlight + v5.0 + $(TargetFrameworkVersion) + false + true + true + ..\ + true + + + + v3.5 + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + ..\packages\RavenDB.Client.1.2.2078-Unstable\lib\sl50\AsyncCtpLibrary_Silverlight5.dll + + + + ..\packages\RavenDB.Client.1.2.2078-Unstable\lib\sl50\Raven.Client.Silverlight.dll + + + + + $(TargetFrameworkDirectory)System.Core.dll + + + + + + + + GeoContractResolver.cs + + + GeoIndexCreationTask.cs + + + GeoRavenExtensions.cs + + + GeoValueProvider.cs + + + + + + {b2e32781-a0ae-4803-8de0-92a95f218363} + Geo + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Geo.Raven.Silverlight5/Properties/AssemblyInfo.cs b/Geo.Raven.Silverlight5/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ffefb0b --- /dev/null +++ b/Geo.Raven.Silverlight5/Properties/AssemblyInfo.cs @@ -0,0 +1,34 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Geo.Raven.Silverlight5")] +[assembly: AssemblyDescription("RavenDB Integration for Geo")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Geo.Raven.Silverlight5")] +[assembly: AssemblyCopyright("Copyright © Simon Bartlett 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a3b76d9c-e0ef-4b8f-8477-00f406c11a3d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/Geo.Raven.Silverlight5/packages.config b/Geo.Raven.Silverlight5/packages.config new file mode 100644 index 0000000..8ef0431 --- /dev/null +++ b/Geo.Raven.Silverlight5/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Geo.Raven/Geo.Raven.csproj b/Geo.Raven/Geo.Raven.csproj index 1bb266e..673fdda 100644 --- a/Geo.Raven/Geo.Raven.csproj +++ b/Geo.Raven/Geo.Raven.csproj @@ -9,10 +9,11 @@ Properties Geo.Raven Geo.Raven - v4.5 + v4.0 512 ..\ true + Client true diff --git a/Geo.Raven/Geo.Raven.nuspec b/Geo.Raven/Geo.Raven.nuspec index 4659cb3..3a9e17d 100644 Binary files a/Geo.Raven/Geo.Raven.nuspec and b/Geo.Raven/Geo.Raven.nuspec differ diff --git a/Geo.Raven/Properties/AssemblyInfo.cs b/Geo.Raven/Properties/AssemblyInfo.cs index 864002d..a71f2ba 100644 --- a/Geo.Raven/Properties/AssemblyInfo.cs +++ b/Geo.Raven/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.0.0")] -[assembly: AssemblyFileVersion("0.2.0.0")] +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/Geo.Tests/Geo.Tests.csproj b/Geo.Tests/Geo.Tests.csproj index e8f2ffd..77863f8 100644 --- a/Geo.Tests/Geo.Tests.csproj +++ b/Geo.Tests/Geo.Tests.csproj @@ -9,7 +9,7 @@ Properties Geo.Tests Geo.Tests - v4.5 + v4.0 512 diff --git a/Geo.Tests/Gps/Serialization/GpxSerializerTests.cs b/Geo.Tests/Gps/Serialization/GpxSerializerTests.cs index b41cc1c..e077102 100644 --- a/Geo.Tests/Gps/Serialization/GpxSerializerTests.cs +++ b/Geo.Tests/Gps/Serialization/GpxSerializerTests.cs @@ -17,15 +17,16 @@ public void CanParseAll() { using (var stream = new FileStream(fileInfo.FullName, FileMode.Open)) { - if (gpx10.CanDeSerialize(stream)) + var streamWrapper = new StreamWrapper(stream); + if (gpx10.CanDeSerialize(streamWrapper)) { - var data = gpx10.DeSerialize(stream); + var data = gpx10.DeSerialize(streamWrapper); data.ToGpx(); data.ToGpx(1); } - else if (gpx11.CanDeSerialize(stream)) + else if (gpx11.CanDeSerialize(streamWrapper)) { - var data = gpx11.DeSerialize(stream); + var data = gpx11.DeSerialize(streamWrapper); data.ToGpx(); data.ToGpx(1); } diff --git a/Geo.Tests/Gps/Serialization/IgcDeSerializerTests.cs b/Geo.Tests/Gps/Serialization/IgcDeSerializerTests.cs index 5d3d6bf..c516b1f 100644 --- a/Geo.Tests/Gps/Serialization/IgcDeSerializerTests.cs +++ b/Geo.Tests/Gps/Serialization/IgcDeSerializerTests.cs @@ -14,9 +14,10 @@ public void igc2() var file = GetReferenceFileDirectory("igc").GetFiles().First(x => x.Name == "igc2.igc"); using (var stream = new FileStream(file.FullName, FileMode.Open)) { + var streamWrapper = new StreamWrapper(stream); var parser = new IgcDeSerializer(); - var canParse = parser.CanDeSerialize(stream); - var result = parser.DeSerialize(stream); + var canParse = parser.CanDeSerialize(streamWrapper); + var result = parser.DeSerialize(streamWrapper); Assert.That(canParse, Is.EqualTo(true)); Assert.That(result.Waypoints.Count, Is.EqualTo(0)); diff --git a/Geo.Tests/Gps/Serialization/NmeaDeSerializerTests.cs b/Geo.Tests/Gps/Serialization/NmeaDeSerializerTests.cs index 67147dd..623f225 100644 --- a/Geo.Tests/Gps/Serialization/NmeaDeSerializerTests.cs +++ b/Geo.Tests/Gps/Serialization/NmeaDeSerializerTests.cs @@ -14,9 +14,10 @@ public void Stockholm_Walk() var file = GetReferenceFileDirectory("nmea").GetFiles().First(x => x.Name == "Stockholm_Walk.nmea"); using (var stream = new FileStream(file.FullName, FileMode.Open)) { + var streamWrapper = new StreamWrapper(stream); var parser = new NmeaDeSerializer(); - var canParse = parser.CanDeSerialize(stream); - var result = parser.DeSerialize(stream); + var canParse = parser.CanDeSerialize(streamWrapper); + var result = parser.DeSerialize(streamWrapper); Assert.That(canParse, Is.EqualTo(true)); Assert.That(result.Waypoints.Count, Is.EqualTo(0)); diff --git a/Geo.sln b/Geo.sln index b1c54b2..a0a4bd4 100644 --- a/Geo.sln +++ b/Geo.sln @@ -14,6 +14,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D0D0BB .nuget\NuGet.targets = .nuget\NuGet.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geo.Raven.Silverlight4", "Geo.Raven.Silverlight4\Geo.Raven.Silverlight4.csproj", "{88367AA2-A54F-4C50-9264-BB2AFCA23C5C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Geo.Raven.Silverlight5", "Geo.Raven.Silverlight5\Geo.Raven.Silverlight5.csproj", "{A3B76D9C-E0EF-4B8F-8477-00F406C11A3D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -32,6 +36,14 @@ Global {DEB5E2DA-E260-4D7C-9B91-476534521DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU {DEB5E2DA-E260-4D7C-9B91-476534521DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEB5E2DA-E260-4D7C-9B91-476534521DEC}.Release|Any CPU.Build.0 = Release|Any CPU + {88367AA2-A54F-4C50-9264-BB2AFCA23C5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88367AA2-A54F-4C50-9264-BB2AFCA23C5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88367AA2-A54F-4C50-9264-BB2AFCA23C5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88367AA2-A54F-4C50-9264-BB2AFCA23C5C}.Release|Any CPU.Build.0 = Release|Any CPU + {A3B76D9C-E0EF-4B8F-8477-00F406C11A3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3B76D9C-E0EF-4B8F-8477-00F406C11A3D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3B76D9C-E0EF-4B8F-8477-00F406C11A3D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3B76D9C-E0EF-4B8F-8477-00F406C11A3D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Geo/Geo.csproj b/Geo/Geo.csproj index 7b75eaa..e3c1f90 100644 --- a/Geo/Geo.csproj +++ b/Geo/Geo.csproj @@ -2,7 +2,7 @@ - 11.0 + 10.0 Debug AnyCPU {B2E32781-A0AE-4803-8DE0-92A95F218363} @@ -10,8 +10,8 @@ Properties Geo Geo - v4.5 - Profile7 + v4.0 + Profile2 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -64,6 +64,7 @@ + diff --git a/Geo/Geo.nuspec b/Geo/Geo.nuspec index b58c21d..e9d10df 100644 Binary files a/Geo/Geo.nuspec and b/Geo/Geo.nuspec differ diff --git a/Geo/GeoUtil.cs b/Geo/GeoUtil.cs index bdda213..715bcd5 100644 --- a/Geo/GeoUtil.cs +++ b/Geo/GeoUtil.cs @@ -10,7 +10,7 @@ internal static class GeoUtil internal static bool TryParseOrdinateInternal(string ordinateString, OrdinateType type, out double ordinate) { ordinate = default(double); - if (string.IsNullOrWhiteSpace(ordinateString)) + if (ordinateString.IsNullOrWhitespace()) return false; ordinateString = ordinateString.Trim(); @@ -103,9 +103,9 @@ internal enum OrdinateType Longitude, } - public static Tuple SplitCoordinateString(string coordinate) + public static string[] SplitCoordinateString(string coordinate) { - if(string.IsNullOrWhiteSpace(coordinate)) + if (coordinate.IsNullOrWhitespace()) return null; coordinate = coordinate.Trim(); @@ -139,9 +139,7 @@ internal enum OrdinateType if (ordinates == null) return null; - return new Tuple( - ordinates[0].Trim(), ordinates[1].Trim() - ); + return new[] {ordinates[0].Trim(), ordinates[1].Trim()}; } } } diff --git a/Geo/Geometries/IGeometry.cs b/Geo/Geometries/IGeometry.cs index f9f6033..548e1dc 100644 --- a/Geo/Geometries/IGeometry.cs +++ b/Geo/Geometries/IGeometry.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Geo.Geometries +namespace Geo.Geometries { public interface IGeometry { diff --git a/Geo/Geometries/LatLngCoordinate.cs b/Geo/Geometries/LatLngCoordinate.cs index ba1445c..1dbc408 100644 --- a/Geo/Geometries/LatLngCoordinate.cs +++ b/Geo/Geometries/LatLngCoordinate.cs @@ -68,7 +68,7 @@ public static LatLngCoordinate Parse(string coordinate) if (coordinate == null) throw new ArgumentNullException("coordinate"); - if (string.IsNullOrWhiteSpace(coordinate)) + if (coordinate.IsNullOrWhitespace()) throw new ArgumentException("Value was empty", "coordinate"); LatLngCoordinate result; @@ -92,8 +92,8 @@ public static bool TryParse(string coordinate, out LatLngCoordinate result) { double lat; double lon; - if (GeoUtil.TryParseOrdinateInternal(a.Item1, GeoUtil.OrdinateType.Latitude, out lat)) - if (GeoUtil.TryParseOrdinateInternal(a.Item2, GeoUtil.OrdinateType.Longitude, out lon)) + if (GeoUtil.TryParseOrdinateInternal(a[0], GeoUtil.OrdinateType.Latitude, out lat)) + if (GeoUtil.TryParseOrdinateInternal(a[1], GeoUtil.OrdinateType.Longitude, out lon)) { result = new LatLngCoordinate(lat, lon); return true; diff --git a/Geo/Gps/GpsData.cs b/Geo/Gps/GpsData.cs index f282ef3..cb0913e 100644 --- a/Geo/Gps/GpsData.cs +++ b/Geo/Gps/GpsData.cs @@ -19,7 +19,7 @@ static GpsData() new Gpx10Serializer(), new Gpx11Serializer(), }; - FileParsers = new List(FileSerializers) + FileParsers = new List(FileSerializers.OfType()) { new IgcDeSerializer(), new NmeaDeSerializer(), @@ -57,8 +57,9 @@ public static IEnumerable SupportedGpsLogFileExtensions public static GpsData Parse(Stream stream) { - var parser = FileParsers.FirstOrDefault(x => x.CanDeSerialize(stream)); - return parser == null ? null : parser.DeSerialize(stream); + var gpsStream = new StreamWrapper(stream); + var parser = FileParsers.FirstOrDefault(x => x.CanDeSerialize(gpsStream)); + return parser == null ? null : parser.DeSerialize(gpsStream); } //public static GpsData Parse(string path) diff --git a/Geo/Gps/Metadata/Metadata.cs b/Geo/Gps/Metadata/Metadata.cs index 19af229..cd86860 100644 --- a/Geo/Gps/Metadata/Metadata.cs +++ b/Geo/Gps/Metadata/Metadata.cs @@ -22,7 +22,7 @@ public string Attribute(Func attribute) public void Attribute(Func attribute, string value) { - if (!string.IsNullOrWhiteSpace(value)) + if (!value.IsNullOrWhitespace()) { var key = attribute(_metadataKeys); this[key] = value.Trim(); diff --git a/Geo/Gps/Serialization/IGpsFileDeSerializer.cs b/Geo/Gps/Serialization/IGpsFileDeSerializer.cs index b91e722..4725fbd 100644 --- a/Geo/Gps/Serialization/IGpsFileDeSerializer.cs +++ b/Geo/Gps/Serialization/IGpsFileDeSerializer.cs @@ -7,8 +7,8 @@ public interface IGpsFileDeSerializer { string[] FileExtensions { get; } Uri FileFormatSpecificationUri { get; } - bool CanDeSerialize(Stream stream); - GpsData DeSerialize(Stream stream); + bool CanDeSerialize(StreamWrapper streamWrapper); + GpsData DeSerialize(StreamWrapper streamWrapper); } public interface IGpsFileSerializer : IGpsFileDeSerializer diff --git a/Geo/Gps/Serialization/IgcDeSerializer.cs b/Geo/Gps/Serialization/IgcDeSerializer.cs index d0b680f..3513d10 100644 --- a/Geo/Gps/Serialization/IgcDeSerializer.cs +++ b/Geo/Gps/Serialization/IgcDeSerializer.cs @@ -20,10 +20,10 @@ public class IgcDeSerializer : IGpsFileDeSerializer public Uri FileFormatSpecificationUri { get { return new Uri("http://carrier.csi.cam.ac.uk/forsterlewis/soaring/igc_file_format/"); } } - public bool CanDeSerialize(Stream stream) + public bool CanDeSerialize(StreamWrapper streamWrapper) { - stream.Position = 0; - using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) + streamWrapper.Position = 0; + using (var reader = new StreamReader(streamWrapper)) { string line; while ((line = reader.ReadLine()) != null) @@ -46,14 +46,14 @@ private bool ParseMetadata(GpsData data, Func return false; } - public GpsData DeSerialize(Stream stream) + public GpsData DeSerialize(StreamWrapper streamWrapper) { var data = new GpsData(); DateTime date = default(DateTime); var track = new LineString(); - stream.Position = 0; - using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) + streamWrapper.Position = 0; + using (var reader = new StreamReader(streamWrapper)) { string line; while ((line = reader.ReadLine()) != null) @@ -103,7 +103,7 @@ public GpsData DeSerialize(Stream stream) private bool ParseFix(string line, LineString data, DateTime date) { - if (string.IsNullOrWhiteSpace(line)) + if (line.IsNullOrWhitespace()) return false; var match = Regex.Match(line, B_LINE_REGEX); diff --git a/Geo/Gps/Serialization/NmeaDeSerializer.cs b/Geo/Gps/Serialization/NmeaDeSerializer.cs index 89fc93d..5f73ba9 100644 --- a/Geo/Gps/Serialization/NmeaDeSerializer.cs +++ b/Geo/Gps/Serialization/NmeaDeSerializer.cs @@ -15,10 +15,10 @@ public class NmeaDeSerializer : IGpsFileDeSerializer public Uri FileFormatSpecificationUri { get { return null; } } - public bool CanDeSerialize(Stream stream) + public bool CanDeSerialize(StreamWrapper streamWrapper) { - stream.Position = 0; - using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) + streamWrapper.Position = 0; + using (var reader = new StreamReader(streamWrapper)) { string line; while ((line = reader.ReadLine()) != null) @@ -28,12 +28,12 @@ public bool CanDeSerialize(Stream stream) return false; } - public GpsData DeSerialize(Stream stream) + public GpsData DeSerialize(StreamWrapper streamWrapper) { var data = new GpsData(); var track = new LineString(); - stream.Position = 0; - using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) + streamWrapper.Position = 0; + using (var reader = new StreamReader(streamWrapper)) { string line; while ((line = reader.ReadLine()) != null) @@ -55,7 +55,7 @@ public GpsData DeSerialize(Stream stream) private bool ParseFix(string line, LineString data) { - if (string.IsNullOrWhiteSpace(line)) + if (line.IsNullOrWhitespace()) return false; var match = Regex.Match(line, FIX_SENTENCE); @@ -78,7 +78,7 @@ private bool ParseFix(string line, LineString data) private bool ParseWaypoint(string line, GpsData data) { - if (string.IsNullOrWhiteSpace(line)) + if (line.IsNullOrWhitespace()) return false; var match = Regex.Match(line, WPT_SENTENCE); diff --git a/Geo/Gps/Serialization/StreamWrapper.cs b/Geo/Gps/Serialization/StreamWrapper.cs new file mode 100644 index 0000000..98c32cc --- /dev/null +++ b/Geo/Gps/Serialization/StreamWrapper.cs @@ -0,0 +1,64 @@ +using System.IO; + +namespace Geo.Gps.Serialization +{ + public class StreamWrapper : Stream + { + private readonly Stream _stream; + + public StreamWrapper(Stream stream) + { + _stream = stream; + } + + public override void Flush() + { + _stream.Flush(); + } + + public override int Read(byte[] buffer, int offset, int count) + { + return _stream.Read(buffer, offset, count); + } + + public override long Seek(long offset, SeekOrigin origin) + { + return _stream.Seek(offset, origin); + } + + public override void SetLength(long value) + { + _stream.SetLength(value); + } + + public override void Write(byte[] buffer, int offset, int count) + { + _stream.Write(buffer, offset, count); + } + + public override bool CanRead + { + get { return _stream.CanRead; } + } + + public override bool CanSeek + { + get { return _stream.CanSeek; } + } + + public override bool CanWrite + { + get { return _stream.CanWrite; } + } + + public override long Length + { + get { return _stream.Length; } + } + + public override long Position { + get { return _stream.Position; } + set{ _stream.Position= value; } + } + } +} diff --git a/Geo/Gps/Serialization/Xml/GpsXmlSerializer.cs b/Geo/Gps/Serialization/Xml/GpsXmlSerializer.cs index e978f0c..1f8ad33 100644 --- a/Geo/Gps/Serialization/Xml/GpsXmlSerializer.cs +++ b/Geo/Gps/Serialization/Xml/GpsXmlSerializer.cs @@ -12,18 +12,18 @@ public abstract class GpsXmlSerializer : IGpsFileSerializer public abstract string[] FileExtensions { get; } public abstract Uri FileFormatSpecificationUri { get; } - public bool CanDeSerialize(Stream stream) + public bool CanDeSerialize(StreamWrapper streamWrapper) { - stream.Position = 0; - using (var reader = XmlReader.Create(stream, new XmlReaderSettings {CloseInput = false})) + streamWrapper.Position = 0; + using (var reader = XmlReader.Create(streamWrapper, new XmlReaderSettings {CloseInput = false})) return _xmlSerializer.CanDeserialize(reader); } - public GpsData DeSerialize(Stream stream) + public GpsData DeSerialize(StreamWrapper streamWrapper) { - stream.Position = 0; + streamWrapper.Position = 0; T doc; - using (var reader = XmlReader.Create(stream, new XmlReaderSettings { CloseInput = false })) + using (var reader = XmlReader.Create(streamWrapper, new XmlReaderSettings { CloseInput = false })) doc = (T)_xmlSerializer.Deserialize(reader); return DeSerialize(doc); @@ -47,21 +47,21 @@ public string SerializeToString(GpsData data) protected void SerializeMetadata(GpsData data, T xml, Func attribute, Action action) { var value = data.Metadata.Attribute(attribute); - if (!string.IsNullOrWhiteSpace(value)) + if (!value.IsNullOrWhitespace()) action(xml, value); } protected void SerializeTrackMetadata(Track data, TTrack xml, Func attribute, Action action) { var value = data.Metadata.Attribute(attribute); - if (!string.IsNullOrWhiteSpace(value)) + if (!value.IsNullOrWhitespace()) action(xml, value); } protected void SerializeRouteMetadata(Route data, TRoute xml, Func attribute, Action action) { var value = data.Metadata.Attribute(attribute); - if (!string.IsNullOrWhiteSpace(value)) + if (!value.IsNullOrWhitespace()) action(xml, value); } } diff --git a/Geo/Helpers.cs b/Geo/Helpers.cs index c391eff..46a4700 100644 --- a/Geo/Helpers.cs +++ b/Geo/Helpers.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; namespace Geo { @@ -13,5 +16,18 @@ internal static double ToDegrees(this double radians) { return radians*180/Math.PI; } + + public static IEnumerable GetEnumValues() + { + var type = typeof(T); + return type + .GetFields(BindingFlags.Static | BindingFlags.Public) + .Select(fi => (T) Enum.Parse(type, fi.Name, false)); + } + + public static bool IsNullOrWhitespace(this string value) + { + return value == null || value.Trim().Length == 0; + } } } diff --git a/Geo/Measure/UnitMetadata.cs b/Geo/Measure/UnitMetadata.cs index 275f032..76acf4e 100644 --- a/Geo/Measure/UnitMetadata.cs +++ b/Geo/Measure/UnitMetadata.cs @@ -8,8 +8,8 @@ namespace Geo.Measure { public class UnitMetadata { - private static readonly ReadOnlyDictionary DistanceCache; - private static readonly ReadOnlyDictionary SpeedCache; + private static readonly Dictionary DistanceCache; + private static readonly Dictionary SpeedCache; static UnitMetadata() { @@ -27,15 +27,15 @@ internal static UnitAttribute For(SpeedUnit unit) return SpeedCache[unit]; } - private static ReadOnlyDictionary Init() + private static Dictionary Init() { var type = typeof(T); var a = new Dictionary(); - foreach (T unit in Enum.GetValues(type)) + foreach (T unit in Helpers.GetEnumValues()) { var name = Enum.GetName(type, unit); - var attr = type.GetTypeInfo().GetDeclaredField(name) + var attr = type.GetField(name) .GetCustomAttributes(typeof(UnitAttribute), false) .Cast() .FirstOrDefault(); @@ -44,7 +44,9 @@ internal static UnitAttribute For(SpeedUnit unit) a.Add(unit, attr); } - return new ReadOnlyDictionary(a); + return new Dictionary(a); } } + + } diff --git a/Geo/Properties/AssemblyInfo.cs b/Geo/Properties/AssemblyInfo.cs index 6f837d6..7afa300 100644 --- a/Geo/Properties/AssemblyInfo.cs +++ b/Geo/Properties/AssemblyInfo.cs @@ -24,5 +24,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.0.0")] -[assembly: AssemblyFileVersion("0.2.0.0")] +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/Geo/web.config.transform b/Geo/web.config.transform deleted file mode 100644 index a33e039..0000000 --- a/Geo/web.config.transform +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/readme.md b/readme.md index edc006d..87630a1 100644 --- a/readme.md +++ b/readme.md @@ -1,36 +1,28 @@ # Geo - a simple geospatial library for .NET -#### NuGet Packages - -* [Geo](https://nuget.org/packages/Geo) -* [Geo.Raven](https://nuget.org/packages/Geo.Raven) - -#### Why Geo? - Geo is a spatial library that: * is made specfically for geographic data * uses geographic terminology * is simple -#### What does Geo do? - -* Provides geographic data types -* Performs geodesic calculations, such as calculating great circle lines and rhumb lines -* Reads GPS files/streams (GPX, IGC, NMEA) -* Writes GPX files/streams -* Integrates with RavenDB client (using the Geo.Raven package) - -#### Geo doesn't have the features I need? +#### NuGet Packages -I add features when I need them, or when I have the time. +__Geo__ - _[NuGet](https://nuget.org/packages/Geo)_ -I am taking contributions, but would appreciate discussing your idea(s) first. Please raise a ticket to kick off a discussion. +* Features: + * Provides geographic data types (Point, LineString, Polygon, Circle, etc.) + * Performs geodesic calculations, such as calculating great circle lines and rhumb lines + * Read GPS data from a .NET Stream (GPX, IGC, NMEA) + * Write GPX file to a .NET Stream +* .NET 4.0+, Windows 8 Store applications, Windows Phone 7.0+, Silverlight 4 & 5 -If Geo does not meet your needs then you should checkout the following libraries: +__Geo.Raven__ - _[NuGet](https://nuget.org/packages/Geo.Raven)_ -* NetTopologySuite ([Homepage](http://code.google.com/p/nettopologysuite/), [NuGet](http://nuget.org/profiles/nettopologysuite%20-%20team)) -* DotSpatial ([Homepage](http://dotspatial.codeplex.com/), [NuGet](http://nuget.org/profiles/mudnug)) +* Features: + * Define RavenDB indexes against Geo geometries + * Use Geo geometries in RavenDB spatial queries +* .NET 4.0+, Silverlight 4 & 5 #### Useful Information