-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from dyatlov-a/hotfix-269
Stabilization of the main scenarios
- Loading branch information
Showing
102 changed files
with
1,264 additions
and
939 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Text.Json; | ||
using Inc.TeamAssistant.CheckIn.Application.Contracts; | ||
using Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
namespace Inc.TeamAssistant.CheckIn.Geo; | ||
|
||
internal sealed class GeoParser | ||
{ | ||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
TypeInfoResolver = new GeometryResolver() | ||
}; | ||
|
||
public IEnumerable<Region> Parse(IEnumerable<string> json) | ||
{ | ||
ArgumentNullException.ThrowIfNull(json); | ||
|
||
foreach (var line in json) | ||
{ | ||
var item = JsonSerializer.Deserialize<GeoItem>(line, JsonSerializerOptions); | ||
|
||
if (item is not null) | ||
yield return new Region( | ||
item.Properties.Name, | ||
item.Id, | ||
item.Properties.Type == "country" ? RegionType.Country : RegionType.Ocean, | ||
item.Geometry.GetCoordinates().ToArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization.Metadata; | ||
using Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
namespace Inc.TeamAssistant.CheckIn.Geo; | ||
|
||
internal sealed class GeometryResolver : DefaultJsonTypeInfoResolver | ||
{ | ||
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(type); | ||
ArgumentNullException.ThrowIfNull(options); | ||
|
||
var jsonTypeInfo = base.GetTypeInfo(type, options); | ||
|
||
if (jsonTypeInfo.Type == typeof(IGeometry)) | ||
{ | ||
jsonTypeInfo.PolymorphismOptions = new JsonPolymorphismOptions | ||
{ | ||
TypeDiscriminatorPropertyName = "type", | ||
IgnoreUnrecognizedTypeDiscriminators = false, | ||
UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization, | ||
DerivedTypes = | ||
{ | ||
new JsonDerivedType(typeof(PolygonGeometry), "Polygon"), | ||
new JsonDerivedType(typeof(MultiPolygonGeometry), "MultiPolygon"), | ||
} | ||
}; | ||
} | ||
|
||
return jsonTypeInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal sealed record GeoItem( | ||
string Id, | ||
GeoProperties Properties, | ||
IGeometry Geometry); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal sealed record GeoProperties(string Type, string Name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal interface IGeometry | ||
{ | ||
IEnumerable<float[]> GetCoordinates(); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Inc.TeamAssistant.CheckIn.Geo/Models/MultiPolygonGeometry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal sealed record MultiPolygonGeometry(float[][][][] Coordinates) | ||
: IGeometry | ||
{ | ||
public IEnumerable<float[]> GetCoordinates() | ||
{ | ||
foreach (var coordinate in Coordinates) | ||
foreach (var item in coordinate[0]) | ||
yield return [item[0], item[1]]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal sealed record Point(float Lng, float Lat); |
11 changes: 11 additions & 0 deletions
11
src/Inc.TeamAssistant.CheckIn.Geo/Models/PolygonGeometry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Inc.TeamAssistant.CheckIn.Geo.Models; | ||
|
||
internal sealed record PolygonGeometry(float[][][] Coordinates) | ||
: IGeometry | ||
{ | ||
public IEnumerable<float[]> GetCoordinates() | ||
{ | ||
foreach (var item in Coordinates[0]) | ||
yield return [item[0], item[1]]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.