Skip to content

Commit

Permalink
Main commit - moved to STJ, there are still open issues...
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jan 29, 2023
1 parent b6806ed commit 08e559f
Show file tree
Hide file tree
Showing 26 changed files with 421 additions and 143 deletions.
5 changes: 3 additions & 2 deletions IsraelHiking.API/Controllers/UpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using IsraelHiking.Common.Api;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Net;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -73,7 +74,7 @@ public async Task<IActionResult> PostUpdateData(UpdateRequest request)
};
_logger.LogInformation("No specific filters were applied, updating all databases.");
}
_logger.LogInformation("Starting updating site's databases according to request: " + JsonConvert.SerializeObject(request));
_logger.LogInformation("Starting updating site's databases according to request: " + JsonSerializer.Serialize(request));
await _databasesUpdaterService.Rebuild(request);
_logger.LogInformation("Finished updating site's databases according to request");
return Ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetTopologySuite.Features;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml.Serialization;

Expand Down Expand Up @@ -128,10 +127,7 @@ public void CreateOfflinePoisFile(List<Feature> features)
chunkSize = 200;
while (list.Count > 0)
{
var imageItemsString = JsonConvert.SerializeObject(list.Take(chunkSize).ToList(), new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
var imageItemsString = JsonSerializer.Serialize(list.Take(chunkSize).ToList());
zipStream.PutNextEntry(new ZipEntry($"images/images{index:000}.json") { DateTime = DateTime.Now });
StreamUtils.Copy(new MemoryStream(Encoding.UTF8.GetBytes(imageItemsString)), zipStream, new byte[4096]);
zipStream.CloseEntry();
Expand Down
24 changes: 11 additions & 13 deletions IsraelHiking.API/Gpx/SerializarionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
using NetTopologySuite.IO.Converters;

namespace IsraelHiking.API.Gpx
{
Expand Down Expand Up @@ -77,13 +79,10 @@ public static class SerializarionExtensions
/// <returns>The <see cref="byte"/> array</returns>
public static byte[] ToBytes(this FeatureCollection featureCollection)
{
using var outputStream = new MemoryStream();
var writer = new StreamWriter(outputStream);
var jsonWriter = new JsonTextWriter(writer);
var serializer = GeoJsonSerializer.Create(new GeometryFactory(), 3);
serializer.Serialize(jsonWriter, featureCollection);
jsonWriter.Flush();
return outputStream.ToArray();
var options = new JsonSerializerOptions();
options.Converters.Add(new GeoJsonConverterFactory());
var serialized = JsonSerializer.Serialize(featureCollection, options);
return Encoding.UTF8.GetBytes(serialized);
}

/// <summary>
Expand All @@ -93,11 +92,10 @@ public static byte[] ToBytes(this FeatureCollection featureCollection)
/// <returns>The <see cref="FeatureCollection"/></returns>
public static FeatureCollection ToFeatureCollection(this byte[] featureCollectionContent)
{
using var stream = new MemoryStream(featureCollectionContent);
var serializer = GeoJsonSerializer.Create(new GeometryFactory(), 3);
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
return serializer.Deserialize<FeatureCollection>(jsonTextReader);
var stringJson = Encoding.UTF8.GetString(featureCollectionContent);
var options = new JsonSerializerOptions();
options.Converters.Add(new GeoJsonConverterFactory());
return JsonSerializer.Deserialize<FeatureCollection>(stringJson, options);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion IsraelHiking.API/IsraelHiking.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="NetTopologySuite" Version="2.5.0" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="3.0.0" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON4STJ" Version="3.0.0" />
<PackageReference Include="NetTopologySuite.IO.GPX" Version="1.1.1" />
<PackageReference Include="OsmSharp.IO.API" Version="1.0.4" />
<PackageReference Include="ProjNet" Version="2.0.0" />
Expand Down
14 changes: 6 additions & 8 deletions IsraelHiking.API/Swagger/FeatureCollectionExampleFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.OpenApi.Models;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using NetTopologySuite.IO.Converters;

namespace IsraelHiking.API.Swagger
{
Expand All @@ -30,11 +30,9 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
return;
}
var writer = new GeoJsonWriter
{
SerializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }
};
var exampleFeatureCollectionString = writer.Write(
var options = new JsonSerializerOptions();
options.Converters.Add(new GeoJsonConverterFactory());
var exampleFeatureCollectionString = JsonSerializer.Serialize(
new FeatureCollection
{
new Feature(new LineString(new[]
Expand All @@ -43,7 +41,7 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
new Coordinate(3, 4),
}),
new AttributesTable { {"key", "value" } })
});
}, options);
schema.Example = new OpenApiString(exampleFeatureCollectionString);
schema.Default = new OpenApiString(exampleFeatureCollectionString);
}
Expand Down
14 changes: 6 additions & 8 deletions IsraelHiking.API/Swagger/FeatureExampleFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.OpenApi.Models;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using NetTopologySuite.IO.Converters;

namespace IsraelHiking.API.Swagger
{
Expand All @@ -30,18 +30,16 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
return;
}
var writer = new GeoJsonWriter
{
SerializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }
};
var exampleFeatureString = writer.Write(
var options = new JsonSerializerOptions();
options.Converters.Add(new GeoJsonConverterFactory());
var exampleFeatureString = JsonSerializer.Serialize(
new Feature(new LineString(new[]
{
new Coordinate(1, 2),
new Coordinate(3, 4),
}),
new AttributesTable { { "key", "value" } })
);
, options);
schema.Example = new OpenApiString(exampleFeatureString);
schema.Default = new OpenApiString(exampleFeatureString);
}
Expand Down
14 changes: 7 additions & 7 deletions IsraelHiking.Common/DataContainer/DataContainerPoco.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace IsraelHiking.Common.DataContainer
{
public class DataContainerPoco
{
[JsonProperty("routes")]
[JsonPropertyName("routes")]
public List<RouteData> Routes { get; set; }
[JsonProperty("northEast")]
[JsonPropertyName("northEast")]
public LatLng NorthEast { get; set; }
[JsonProperty("southWest")]
[JsonPropertyName("southWest")]
public LatLng SouthWest { get; set; }
[JsonProperty("baseLayer")]
[JsonPropertyName("baseLayer")]
public LayerData BaseLayer { get; set; }
[JsonProperty("overlays")]
[JsonPropertyName("overlays")]
public List<LayerData> Overlays { get; set; }

public DataContainerPoco()
Expand Down
12 changes: 6 additions & 6 deletions IsraelHiking.Common/DataContainer/LayerData.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IsraelHiking.Common.DataContainer
{
public class LayerData
{
[JsonProperty("key")]
[JsonPropertyName("key")]
public string Key { get; set; }
[JsonProperty("address")]
[JsonPropertyName("address")]
public string Address { get; set; }
[JsonProperty("minZoom")]
[JsonPropertyName("minZoom")]
public int? MinZoom { get; set; }
[JsonProperty("maxZoom")]
[JsonPropertyName("maxZoom")]
public int? MaxZoom { get; set; }
[JsonProperty("opacity")]
[JsonPropertyName("opacity")]
public double? Opacity { get; set; }
}
}
8 changes: 4 additions & 4 deletions IsraelHiking.Common/DataContainer/LinkData.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IsraelHiking.Common.DataContainer
{
public class LinkData
{
[JsonProperty("url")]
[JsonPropertyName("url")]
public string Url { get; set; }
[JsonProperty("text")]
[JsonPropertyName("text")]
public string Text { get; set; }
[JsonProperty("mimeType")]
[JsonPropertyName("mimeType")]
public string MimeType { get; set; }
}
}
12 changes: 6 additions & 6 deletions IsraelHiking.Common/DataContainer/MarkerData.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;

namespace IsraelHiking.Common.DataContainer
{
public class MarkerData
{
[JsonProperty("latlng")]
[JsonPropertyName("latlng")]
public LatLng Latlng { get; set; }
[JsonProperty("title")]
[JsonPropertyName("title")]
public string Title { get; set; }
[JsonProperty("description")]
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonProperty("type")]
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonProperty("urls")]
[JsonPropertyName("urls")]
public List<LinkData> Urls { get; set; }

public MarkerData()
Expand Down
18 changes: 9 additions & 9 deletions IsraelHiking.Common/DataContainer/RouteData.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;

namespace IsraelHiking.Common.DataContainer
{
public class RouteData
{
[JsonProperty("id")]
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonProperty("description")]
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonProperty("color")]
[JsonPropertyName("color")]
public string Color { get; set; }
[JsonProperty("opacity")]
[JsonPropertyName("opacity")]
public double? Opacity { get; set; }
[JsonProperty("weight")]
[JsonPropertyName("weight")]
public int? Weight { get; set; }
[JsonProperty("markers")]
[JsonPropertyName("markers")]
public List<MarkerData> Markers { get; set; }
[JsonProperty("segments")]
[JsonPropertyName("segments")]
public List<RouteSegmentData> Segments { get; set; }

public RouteData()
Expand Down
8 changes: 4 additions & 4 deletions IsraelHiking.Common/DataContainer/RouteSegmentData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;

namespace IsraelHiking.Common.DataContainer
Expand All @@ -14,11 +14,11 @@ public static class RoutingType

public class RouteSegmentData
{
[JsonProperty("routingType")]
[JsonPropertyName("routingType")]
public string RoutingType { get; set; }
[JsonProperty("routePoint")]
[JsonPropertyName("routePoint")]
public LatLng RoutePoint { get; set; }
[JsonProperty("latlngs")]
[JsonPropertyName("latlngs")]
public List<LatLngTime> Latlngs { get; set; }

public RouteSegmentData()
Expand Down
4 changes: 4 additions & 0 deletions IsraelHiking.Common/ImageItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace IsraelHiking.Common
{
Expand All @@ -7,8 +8,11 @@ public class ImageItem
/// <summary>
/// Used as a key
/// </summary>
[JsonPropertyName("hash")]
public string Hash { get; set; }
[JsonPropertyName("imageUrls")]
public List<string> ImageUrls { get; set; }
[JsonPropertyName("thumbnail")]
public string Thumbnail { get; set; }

}
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.Common/IsraelHiking.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="NetTopologySuite" Version="2.5.0" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON4STJ" Version="3.0.0" />
<PackageReference Include="OsmSharp" Version="7.0.0-pre022" />
<PackageReference Include="ProjNet" Version="2.0.0" />
</ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions IsraelHiking.Common/LatLng.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace IsraelHiking.Common
{
public class LatLng : IEquatable<LatLng>
{
[JsonProperty("lat")]
[JsonPropertyName("lat")]
public double Lat { get; set; }
[JsonProperty("lng")]
[JsonPropertyName("lng")]
public double Lng { get; set; }
[JsonProperty("alt")]
[JsonPropertyName("alt")]
public double? Alt { get; set; }

public bool Equals(LatLng other)
Expand Down Expand Up @@ -58,7 +58,7 @@ public LatLng(string latlngString) : this()

public class LatLngTime : LatLng
{
[JsonProperty("timestamp")]
[JsonPropertyName("timestamp")]
public DateTime? Timestamp { get; set; }

public LatLngTime()
Expand Down

0 comments on commit 08e559f

Please sign in to comment.