278 lines
7.8 KiB
C#
278 lines
7.8 KiB
C#
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.Globalization;
|
|||
|
using CsvHelper.Configuration.Attributes;
|
|||
|
|
|||
|
namespace StarsAssistant.CSV;
|
|||
|
|
|||
|
public class Planet
|
|||
|
{
|
|||
|
[Index(0)]
|
|||
|
public required string Name { get; set; }
|
|||
|
|
|||
|
[Index(1)]
|
|||
|
public string? Owner { get; set; }
|
|||
|
|
|||
|
[Index(2)]
|
|||
|
public string? StarbaseType { get; set; }
|
|||
|
|
|||
|
[Index(3)]
|
|||
|
public int ReportAge { get; set; } = 0;
|
|||
|
|
|||
|
[Index(4)]
|
|||
|
public int? Population { get; set; }
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public int? Value { get; private set; }
|
|||
|
|
|||
|
[Index(5)]
|
|||
|
public string CSVValue {
|
|||
|
set {
|
|||
|
if ( value.Length >= 2
|
|||
|
&& int.TryParse(value[..^1], out int result))
|
|||
|
{
|
|||
|
Value = result;
|
|||
|
} else {
|
|||
|
Value = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Index(7)]
|
|||
|
public int? Mines { get; set; }
|
|||
|
|
|||
|
[Index(8)]
|
|||
|
public int? Factories { get; set; }
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? DefPercent { get; private set; }
|
|||
|
|
|||
|
[Index(9)]
|
|||
|
public string CSVDefPercent {
|
|||
|
set {
|
|||
|
if ( value.Length >= 2
|
|||
|
&& Decimal.TryParse(value[..^1], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
DefPercent = result;
|
|||
|
} else {
|
|||
|
DefPercent = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Index(10)]
|
|||
|
public int? SurfaceIronium { get; set; }
|
|||
|
|
|||
|
[Index(11)]
|
|||
|
public int? SurfaceBoranium { get; set; }
|
|||
|
|
|||
|
[Index(12)]
|
|||
|
public int? SurfaceGermanium { get; set; }
|
|||
|
|
|||
|
[Index(13)]
|
|||
|
public int? MRIronium { get; set; }
|
|||
|
|
|||
|
[Index(14)]
|
|||
|
public int? MRBoranium { get; set; }
|
|||
|
|
|||
|
[Index(15)]
|
|||
|
public int? MRGermanium { get; set; }
|
|||
|
|
|||
|
[Index(16)]
|
|||
|
public int? MCIronium { get; set; }
|
|||
|
|
|||
|
[Index(17)]
|
|||
|
public int? MCBoranium { get; set; }
|
|||
|
|
|||
|
[Index(18)]
|
|||
|
public int? MCGermanium { get; set; }
|
|||
|
|
|||
|
[Index(19)]
|
|||
|
public int? Resources { get; set; }
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? Gravity { get; private set; }
|
|||
|
|
|||
|
[Index(20)]
|
|||
|
public string CSVGravity {
|
|||
|
set {
|
|||
|
if ( value.Length >= 2
|
|||
|
&& Decimal.TryParse(value[..^1], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
Gravity = result;
|
|||
|
} else {
|
|||
|
Gravity = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? Temperature { get; private set; }
|
|||
|
|
|||
|
[Index(21)]
|
|||
|
public string CSVTemperature {
|
|||
|
set {
|
|||
|
if ( value.Length >= 3
|
|||
|
&& Decimal.TryParse(value[..^2], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
Temperature = result;
|
|||
|
} else {
|
|||
|
Temperature = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? Radiation { get; private set; }
|
|||
|
|
|||
|
[Index(22)]
|
|||
|
public string CSVRadiation {
|
|||
|
set {
|
|||
|
if ( value.Length >= 3
|
|||
|
&& Decimal.TryParse(value[..^2], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
Radiation = result;
|
|||
|
} else {
|
|||
|
Radiation = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? GravityOrig { get; private set; }
|
|||
|
|
|||
|
[Index(20)]
|
|||
|
public string CSVGravityOrig {
|
|||
|
set {
|
|||
|
if ( value.Length >= 2
|
|||
|
&& Decimal.TryParse(value[..^1], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
GravityOrig = result;
|
|||
|
} else {
|
|||
|
GravityOrig = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
[Ignore()]
|
|||
|
public decimal? TemperatureOrig { get; private set; }
|
|||
|
|
|||
|
[Index(24)]
|
|||
|
public string CSVTemperatureOrig {
|
|||
|
set {
|
|||
|
if ( value.Length >= 3
|
|||
|
&& Decimal.TryParse(value[..^2], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
TemperatureOrig = result;
|
|||
|
} else {
|
|||
|
TemperatureOrig = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public decimal? RadiationOrig { get; private set; }
|
|||
|
|
|||
|
[Index(25)]
|
|||
|
public string CSVRadiationOrig {
|
|||
|
set {
|
|||
|
if ( value.Length >= 3
|
|||
|
&& Decimal.TryParse(value[..^2], NumberStyles.Float, CultureInfo.InvariantCulture, out decimal result))
|
|||
|
{
|
|||
|
RadiationOrig = result;
|
|||
|
} else {
|
|||
|
RadiationOrig = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Ignore()]
|
|||
|
public int? MaxTerraforming { get; private set; }
|
|||
|
|
|||
|
[Index(26)]
|
|||
|
public string CSVMaxTerraforming {
|
|||
|
set {
|
|||
|
if ( value.Length >= 2
|
|||
|
&& int.TryParse(value[..^1], out int result))
|
|||
|
{
|
|||
|
MaxTerraforming = result;
|
|||
|
} else {
|
|||
|
MaxTerraforming = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[Index(27)]
|
|||
|
public int? CapacityPercent { get; set; }
|
|||
|
|
|||
|
[Index(28)]
|
|||
|
public int? ScanRange { get; set; }
|
|||
|
|
|||
|
[Index(29)]
|
|||
|
public int? PenScanRange { get; set; }
|
|||
|
|
|||
|
[Index(30)]
|
|||
|
public int? Driver { get; set; }
|
|||
|
|
|||
|
[Index(31)]
|
|||
|
public int? DriverWarp { get; set; }
|
|||
|
|
|||
|
[Index(32)]
|
|||
|
public string? RouteTarget { get; set; }
|
|||
|
|
|||
|
[Index(33)]
|
|||
|
public int? GateRange { get; set; }
|
|||
|
|
|||
|
[Index(34)]
|
|||
|
public int? GateMass { get; set; }
|
|||
|
|
|||
|
[Index(35)]
|
|||
|
public int? PctDamage { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// This will update a DB Planet recrod with this CSV Data. The PK (Planet Name)
|
|||
|
/// must already be set, DB/EF Handling has to be done by the caller, we'll take
|
|||
|
/// care of none PK properties only.
|
|||
|
/// </summary>
|
|||
|
/// <param name="dbPlanet"></param>
|
|||
|
public void UpdateDbPlanet(Model.Planet dbPlanet)
|
|||
|
{
|
|||
|
if (dbPlanet == null)
|
|||
|
throw new InvalidOperationException("Cannot update a null DB Planet instance");
|
|||
|
if (dbPlanet.Name != Name)
|
|||
|
throw new InvalidOperationException($"DB Planet Name {dbPlanet.Name} does not macth the CSV Planet Name {Name}");
|
|||
|
|
|||
|
dbPlanet.Owner = Owner;
|
|||
|
dbPlanet.StarbaseType = StarbaseType;
|
|||
|
dbPlanet.ReportAge = ReportAge;
|
|||
|
dbPlanet.Population = Population;
|
|||
|
dbPlanet.Value = Value;
|
|||
|
dbPlanet.Mines = Mines;
|
|||
|
dbPlanet.Factories = Factories;
|
|||
|
dbPlanet.DefPercent = DefPercent;
|
|||
|
dbPlanet.SurfaceIronium = SurfaceIronium;
|
|||
|
dbPlanet.SurfaceBoranium = SurfaceBoranium;
|
|||
|
dbPlanet.SurfaceGermanium = SurfaceGermanium;
|
|||
|
dbPlanet.MRIronium = MRIronium;
|
|||
|
dbPlanet.MRBoranium = MRBoranium;
|
|||
|
dbPlanet.MRGermanium = MRGermanium;
|
|||
|
dbPlanet.MCIronium = MCIronium;
|
|||
|
dbPlanet.MCBoranium = MCBoranium;
|
|||
|
dbPlanet.MCGermanium = MCGermanium;
|
|||
|
dbPlanet.Resources = Resources;
|
|||
|
dbPlanet.Gravity = Gravity;
|
|||
|
dbPlanet.Radiation = Radiation;
|
|||
|
dbPlanet.Temperature = Temperature;
|
|||
|
dbPlanet.GravityOrig = GravityOrig;
|
|||
|
dbPlanet.TemperatureOrig = TemperatureOrig;
|
|||
|
dbPlanet.RadiationOrig = RadiationOrig;
|
|||
|
dbPlanet.MaxTerraforming = MaxTerraforming;
|
|||
|
dbPlanet.CapacityPercent = CapacityPercent;
|
|||
|
dbPlanet.ScanRange = ScanRange;
|
|||
|
dbPlanet.PenScanRange = PenScanRange;
|
|||
|
dbPlanet.Driver = Driver;
|
|||
|
dbPlanet.DriverWarp = DriverWarp;
|
|||
|
dbPlanet.RouteTarget = RouteTarget;
|
|||
|
dbPlanet.GateRange = GateRange;
|
|||
|
dbPlanet.GateMass = GateMass;
|
|||
|
dbPlanet.PctDamage = PctDamage;
|
|||
|
}
|
|||
|
}
|