a
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -5,6 +6,7 @@ namespace View_by_Distance.Instance.Models;
|
||||
|
||||
public record AppSettings(string Company,
|
||||
int MaxDegreeOfParallelism,
|
||||
ReadOnlyCollection<Place> Places,
|
||||
string WorkingDirectoryName)
|
||||
{
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -9,6 +10,7 @@ public class AppSettings
|
||||
|
||||
public string? Company { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string[]? Places { get; set; }
|
||||
public string? WorkingDirectoryName { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
@ -22,10 +24,13 @@ public class AppSettings
|
||||
Models.AppSettings result;
|
||||
if (appSettings?.Company is null) throw new NullReferenceException(nameof(appSettings.Company));
|
||||
if (appSettings?.MaxDegreeOfParallelism is null) throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
// if (appSettings?.Places is null) throw new NullReferenceException(nameof(appSettings.Places));
|
||||
if (appSettings?.WorkingDirectoryName is null) throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
||||
ReadOnlyCollection<Models.Place> places = Place.GetPlaces(appSettings.Places);
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
places,
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
return result;
|
||||
|
25
Instance/Models/Binder/DegreesMinutesSeconds.cs
Normal file
25
Instance/Models/Binder/DegreesMinutesSeconds.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Instance.Models.Binder;
|
||||
|
||||
public class DegreesMinutesSeconds
|
||||
{
|
||||
|
||||
public float? Degrees { get; set; }
|
||||
public float? Minutes { get; set; }
|
||||
public float? Seconds { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderDegreesMinutesSecondsSourceGenerationContext.Default.DegreesMinutesSeconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(DegreesMinutesSeconds))]
|
||||
internal partial class BinderDegreesMinutesSecondsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
66
Instance/Models/Binder/Place.cs
Normal file
66
Instance/Models/Binder/Place.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Instance.Models.Binder;
|
||||
|
||||
public class Place
|
||||
{
|
||||
|
||||
public string? Title { get; set; }
|
||||
public DegreesMinutesSeconds? Latitude { get; set; }
|
||||
public DegreesMinutesSeconds? Longitude { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, BinderPlaceSourceGenerationContext.Default.Place);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Models.Place Get(Place? Place)
|
||||
{
|
||||
Models.Place result;
|
||||
Models.DegreesMinutesSeconds latitude;
|
||||
Models.DegreesMinutesSeconds longitude;
|
||||
if (Place is null) throw new NullReferenceException(nameof(Place));
|
||||
if (Place.Title is null) throw new NullReferenceException(nameof(Place.Title));
|
||||
if (Place.Latitude is null) throw new NullReferenceException(nameof(Place.Latitude));
|
||||
if (Place.Latitude.Degrees is null) throw new NullReferenceException(nameof(Place.Latitude.Degrees));
|
||||
if (Place.Latitude.Minutes is null) throw new NullReferenceException(nameof(Place.Latitude.Minutes));
|
||||
if (Place.Latitude.Seconds is null) throw new NullReferenceException(nameof(Place.Latitude.Seconds));
|
||||
if (Place.Longitude is null) throw new NullReferenceException(nameof(Place.Longitude));
|
||||
latitude = new(Place.Latitude.Degrees.Value, Place.Latitude.Minutes.Value, Place.Latitude.Seconds.Value);
|
||||
if (Place.Longitude.Degrees is null) throw new NullReferenceException(nameof(Place.Longitude.Degrees));
|
||||
if (Place.Longitude.Minutes is null) throw new NullReferenceException(nameof(Place.Longitude.Minutes));
|
||||
if (Place.Longitude.Seconds is null) throw new NullReferenceException(nameof(Place.Longitude.Seconds));
|
||||
longitude = new(Place.Longitude.Degrees.Value, Place.Longitude.Minutes.Value, Place.Longitude.Seconds.Value);
|
||||
result = new(
|
||||
Place.Title,
|
||||
latitude,
|
||||
longitude
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static ReadOnlyCollection<Models.Place> GetPlaces(string[]? places)
|
||||
{
|
||||
List<Models.Place> results = new();
|
||||
if (places is not null)
|
||||
{
|
||||
Place? place;
|
||||
foreach (string jsonElement in places)
|
||||
{
|
||||
place = JsonSerializer.Deserialize(jsonElement, BinderPlaceSourceGenerationContext.Default.Place);
|
||||
results.Add(Get(place));
|
||||
}
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Place))]
|
||||
internal partial class BinderPlaceSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
23
Instance/Models/DegreesMinutesSeconds.cs
Normal file
23
Instance/Models/DegreesMinutesSeconds.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
public record DegreesMinutesSeconds(float Degrees,
|
||||
float Minutes,
|
||||
float Seconds)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, DegreesMinutesSecondsSourceGenerationContext.Default.DegreesMinutesSeconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(DegreesMinutesSeconds))]
|
||||
internal partial class DegreesMinutesSecondsSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
23
Instance/Models/Place.cs
Normal file
23
Instance/Models/Place.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Instance.Models;
|
||||
|
||||
public record Place(string Title,
|
||||
DegreesMinutesSeconds Latitude,
|
||||
DegreesMinutesSeconds Longitude)
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, PlaceSourceGenerationContext.Default.Place);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Place))]
|
||||
internal partial class PlaceSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user