2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 08:23:42 -04:00

Add Startup Events to Database

Now emit startup events on conneciton
Some events still to add
This commit is contained in:
2024-05-25 19:41:38 +10:00
parent 579b2b115d
commit 68eff73dbd
80 changed files with 586 additions and 229 deletions

View File

@ -9,9 +9,9 @@ namespace Observatory.Framework.Files.Converters;
/// The format used for materials changed from an object with a key for each material to an array of objects containing "name" and "percent".
/// Need to handle both if we're going to read historical data. This reads the old format into a class reflecting the new structure.
/// </summary>
public class MaterialCompositionConverter : JsonConverter<ImmutableList<MaterialComposition>>
public class MaterialCompositionConverter : JsonConverter<IReadOnlyCollection<MaterialComposition>>
{
public override ImmutableList<MaterialComposition> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override IReadOnlyCollection<MaterialComposition> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.StartObject)
{
@ -38,13 +38,14 @@ public class MaterialCompositionConverter : JsonConverter<ImmutableList<Material
break;
}
}
return materialComposition.ToImmutableList();
return materialComposition;
}
return JsonSerializer.Deserialize<ImmutableList<MaterialComposition>>(ref reader, options)!;
return JsonSerializer.Deserialize<IReadOnlyCollection<MaterialComposition>>(ref reader, options)!;
}
public override void Write(Utf8JsonWriter writer, ImmutableList<MaterialComposition> value,
public override void Write(Utf8JsonWriter writer, IReadOnlyCollection<MaterialComposition> value,
JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);

View File

@ -9,9 +9,9 @@ namespace Observatory.Framework.Files.Converters;
/// The format used for materials changed from an object with a key for each material to an array of objects containing "name" and "percent".
/// Need to handle both if we're going to read historical data. This reads the old format into a class reflecting the new structure.
/// </summary>
public class MaterialConverter : JsonConverter<ImmutableList<Material>>
public class MaterialConverter : JsonConverter<IReadOnlyCollection<Material>>
{
public override ImmutableList<Material> Read(ref Utf8JsonReader reader, Type typeToConvert,
public override IReadOnlyCollection<Material> Read(ref Utf8JsonReader reader, Type typeToConvert,
JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.StartObject)
@ -41,13 +41,13 @@ public class MaterialConverter : JsonConverter<ImmutableList<Material>>
}
}
return materialComposition.ToImmutableList();
return materialComposition;
}
return JsonSerializer.Deserialize<ImmutableList<Material>>(ref reader, options)!;
return JsonSerializer.Deserialize<IReadOnlyCollection<Material>>(ref reader, options)!;
}
public override void Write(Utf8JsonWriter writer, ImmutableList<Material> value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, IReadOnlyCollection<Material> value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}

View File

@ -1,22 +0,0 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters;
class MutableStringDoubleConverter : JsonConverter<object>
{
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return reader.GetString();
return reader.GetDouble();
}
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
{
if (value.GetType() == typeof(string))
writer.WriteStringValue((string)value);
else
writer.WriteNumberValue((double)value);
}
}

View File

@ -0,0 +1,21 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters;
class NumberOrStringConverter : JsonConverter<NumberOrString>
{
public override NumberOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TokenType == JsonTokenType.String ? new NumberOrString(reader.GetString()) : new NumberOrString(reader.GetDouble());
}
public override void Write(Utf8JsonWriter writer, NumberOrString value, JsonSerializerOptions options)
{
if (value.IsString)
writer.WriteStringValue(value.StringValue!);
else
writer.WriteNumberValue(value.DoubleValue!.Value);
}
}

View File

@ -1,21 +1,22 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.Journal.Travel;
namespace Observatory.Framework.Files.Converters;
/// <summary>
/// Converting the ordered array of coordinates from the journal to a named tuple for clarity.
/// </summary>
public class StarPosConverter : JsonConverter<(double x, double y, double z)>
public class StarPosConverter : JsonConverter<StarPos>
{
public override (double x, double y, double z) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override StarPos Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var values = (double[])JsonSerializer.Deserialize(ref reader, typeof(double[]));
var values = JsonSerializer.Deserialize<double[]>(ref reader, options)!;
return (x: values[0], y: values[1], z: values[2]);
return new StarPos { X = values[0], Y = values[1], Z = values[2] };
}
public override void Write(Utf8JsonWriter writer, (double x, double y, double z) value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, StarPos value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}