extract CSV code to independant class, so that we don't pollute the EF classes with CSV stuff.
This commit is contained in:
		@@ -1,229 +1,78 @@
 | 
			
		||||
using System.ComponentModel.DataAnnotations;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using CSV = CsvHelper.Configuration.Attributes;
 | 
			
		||||
 | 
			
		||||
namespace StarsAssistant.Model;
 | 
			
		||||
 | 
			
		||||
public class Planet
 | 
			
		||||
{
 | 
			
		||||
    [Key, CSV.Index(0)]
 | 
			
		||||
    [Key]
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    [CSV.Index(1)]
 | 
			
		||||
    public string? Owner { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(2)]
 | 
			
		||||
    public string? StarbaseType { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(3)]
 | 
			
		||||
    public int ReportAge { get; set; } = 0;
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(4)]
 | 
			
		||||
    public int? Population { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public int? Value { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(5)]
 | 
			
		||||
    public string CSVValue {
 | 
			
		||||
        set {
 | 
			
		||||
            if (   value.Length >= 2
 | 
			
		||||
                && int.TryParse(value[..^1], out int result))
 | 
			
		||||
            {
 | 
			
		||||
                Value = result;
 | 
			
		||||
            } else {
 | 
			
		||||
                Value = null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Index(7)]
 | 
			
		||||
    public int? Mines { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(8)]
 | 
			
		||||
    public int? Factories { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? DefPercent { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Index(10)]
 | 
			
		||||
    public int? SurfaceIronium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(11)]
 | 
			
		||||
    public int? SurfaceBoranium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(12)]
 | 
			
		||||
    public int? SurfaceGermanium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(13)]
 | 
			
		||||
    public int? MRIronium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(14)]
 | 
			
		||||
    public int? MRBoranium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(15)]
 | 
			
		||||
    public int? MRGermanium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(16)]
 | 
			
		||||
    public int? MCIronium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(17)]
 | 
			
		||||
    public int? MCBoranium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(18)]
 | 
			
		||||
    public int? MCGrmanium { get; set; }
 | 
			
		||||
    public int? MCGermanium { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(19)]
 | 
			
		||||
    public int? Resources { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? Gravity { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? Temperature { get; set; }
 | 
			
		||||
        
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? Radiation { get; set; }
 | 
			
		||||
        
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? GravityOrig { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }    
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? TemperatureOrig { get; set; }
 | 
			
		||||
            
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public decimal? RadiationOrig { get; set; }
 | 
			
		||||
        
 | 
			
		||||
    [CSV.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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [CSV.Ignore()]
 | 
			
		||||
    public int? MaxTerraforming { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(26)]
 | 
			
		||||
    public string CSVMaxTerraforming {
 | 
			
		||||
        set {
 | 
			
		||||
            if (   value.Length >= 2
 | 
			
		||||
                && int.TryParse(value[..^1], out int result))
 | 
			
		||||
            {
 | 
			
		||||
                MaxTerraforming = result;
 | 
			
		||||
            } else {
 | 
			
		||||
                MaxTerraforming = null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(27)]
 | 
			
		||||
    public int? CapacityPercent { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(28)]
 | 
			
		||||
    public int? ScanRange { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(29)]
 | 
			
		||||
    public int? PenScanRange { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(30)]
 | 
			
		||||
    public int? Driver { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(31)]
 | 
			
		||||
    public int? DriverWarp { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(32)]
 | 
			
		||||
    public string? RouteTarget { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(33)]
 | 
			
		||||
    public int? GateRange { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(34)]
 | 
			
		||||
    public int? GateMass { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    [CSV.Index(35)]
 | 
			
		||||
    public int? PctDamage { get; set; }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user