Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core + Framework] Polymorphic Journal Deserialization #155

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ObservatoryCore/LogMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.RegularExpressions;
using Observatory.Framework;
using Observatory.Framework.Files;
using Observatory.Framework.Files.Journal;

namespace Observatory
{
Expand Down Expand Up @@ -307,14 +309,18 @@ private DirectoryInfo GetJournalFolder(string path = "")
return readErrors;
}

private JsonSerializerOptions options = new()
{
AllowOutOfOrderMetadataProperties = true,
};

private JournalEventArgs DeserializeToEventArgs(string eventType, string line)
{

var eventClass = journalTypes[eventType];
MethodInfo journalRead = typeof(JournalReader).GetMethod(nameof(JournalReader.ObservatoryDeserializer));
MethodInfo journalGeneric = journalRead.MakeGenericMethod(eventClass);
object entry = journalGeneric.Invoke(null, new object[] { line });
return new JournalEventArgs() { journalType = eventClass, journalEvent = entry };
var journal = JsonSerializer.Deserialize<JournalBase>(line, options);
// journal.GetType should be specific journal
return new JournalEventArgs() { journalType = eventClass, journalEvent = journal };
}

private void DeserializeAndInvoke(string line)
Expand Down
1 change: 1 addition & 0 deletions ObservatoryCore/ObservatoryCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<PackageReference Include="MessageBox.Avalonia" Version="2.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Speech" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0-preview.4.24266.19" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion ObservatoryFramework/EventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Observatory.Framework.Files.Journal;

namespace Observatory.Framework
{
Expand All @@ -16,7 +17,7 @@ public class JournalEventArgs : EventArgs
/// <para>Elite Dangerous journal event, deserialized into a .NET object of the type specified by JournalEventArgs.journalType.</para>
/// <para>Unhandled json values within a journal entry type will be contained in member property:<br/>Dictionary&lt;string, object&gt; AdditionalProperties.</para>
/// </summary>
public object journalEvent;
public JournalBase journalEvent;
}

/// <summary>
Expand Down
253 changes: 253 additions & 0 deletions ObservatoryFramework/Files/Journal/JournalBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,259 @@

namespace Observatory.Framework.Files.Journal
{
[JsonPolymorphic(TypeDiscriminatorPropertyName = "event", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FailSerialization)]
[JsonDerivedType(typeof(Bounty), "Bounty")]
[JsonDerivedType(typeof(CapShipBound), "CapShipBound")]
[JsonDerivedType(typeof(Died), "Died")]
[JsonDerivedType(typeof(EscapeInterdiction), "EscapeInterdiction")]
[JsonDerivedType(typeof(FactionKillBond), "FactionKillBond")]
[JsonDerivedType(typeof(FighterDestroyed), "FighterDestroyed")]
[JsonDerivedType(typeof(HeatDamage), "HeatDamage")]
[JsonDerivedType(typeof(HeatWarning), "HeatWarning")]
[JsonDerivedType(typeof(HullDamage), "HullDamage")]
[JsonDerivedType(typeof(Interdicted), "Interdicted")]
[JsonDerivedType(typeof(Interdiction), "Interdiction")]
[JsonDerivedType(typeof(PVPKill), "PVPKill")]
[JsonDerivedType(typeof(SRVDestroyed), "SRVDestroyed")]
[JsonDerivedType(typeof(ShieldState), "ShieldState")]
[JsonDerivedType(typeof(ShipTargeted), "ShipTargeted")]
[JsonDerivedType(typeof(UnderAttack), "UnderAttack")]
[JsonDerivedType(typeof(BuyExplorationData), "BuyExplorationData")]
[JsonDerivedType(typeof(CodexEntry), "CodexEntry")]
[JsonDerivedType(typeof(DiscoveryScan), "DiscoveryScan")]
[JsonDerivedType(typeof(FSSAllBodiesFound), "FSSAllBodiesFound")]
[JsonDerivedType(typeof(FSSBodySignals), "FSSBodySignals")]
[JsonDerivedType(typeof(FSSDiscoveryScan), "FSSDiscoveryScan")]
[JsonDerivedType(typeof(FSSSignalDiscovered), "FSSSignalDiscovered")]
[JsonDerivedType(typeof(MaterialCollected), "MaterialCollected")]
[JsonDerivedType(typeof(MaterialDiscarded), "MaterialDiscarded")]
[JsonDerivedType(typeof(MaterialDiscovered), "MaterialDiscovered")]
[JsonDerivedType(typeof(MultiSellExplorationData), "MultiSellExplorationData")]
[JsonDerivedType(typeof(NavBeaconScan), "NavBeaconScan")]
[JsonDerivedType(typeof(SAAScanComplete), "SAAScanComplete")]
[JsonDerivedType(typeof(SAASignalsFound), "SAASignalsFound")]
[JsonDerivedType(typeof(Scan), "Scan")]
[JsonDerivedType(typeof(ScanBaryCentre), "ScanBaryCentre")]
[JsonDerivedType(typeof(Screenshot), "Screenshot")]
[JsonDerivedType(typeof(SellExplorationData), "SellExplorationData")]
[JsonDerivedType(typeof(CarrierBankTransfer), "CarrierBankTransfer")]
[JsonDerivedType(typeof(CarrierBuy), "CarrierBuy")]
[JsonDerivedType(typeof(CarrierCancelDecommission), "CarrierCancelDecommission")]
[JsonDerivedType(typeof(CarrierCrewServices), "CarrierCrewServices")]
[JsonDerivedType(typeof(CarrierDecommission), "CarrierDecommission")]
[JsonDerivedType(typeof(CarrierDepositFuel), "CarrierDepositFuel")]
[JsonDerivedType(typeof(CarrierDockingPermission), "CarrierDockingPermission")]
[JsonDerivedType(typeof(CarrierFinance), "CarrierFinance")]
[JsonDerivedType(typeof(CarrierJump), "CarrierJump")]
[JsonDerivedType(typeof(CarrierJumpCancelled), "CarrierJumpCancelled")]
[JsonDerivedType(typeof(CarrierJumpRequest), "CarrierJumpRequest")]
[JsonDerivedType(typeof(CarrierModulePack), "CarrierModulePack")]
[JsonDerivedType(typeof(CarrierShipPack), "CarrierShipPack")]
[JsonDerivedType(typeof(CarrierStats), "CarrierStats")]
[JsonDerivedType(typeof(CarrierTradeOrder), "CarrierTradeOrder")]
[JsonDerivedType(typeof(FCMaterials), "FCMaterlas")]
[JsonDerivedType(typeof(BackpackChange), "BackpackChange")]
[JsonDerivedType(typeof(BackpackMaterials), "Backpack")]
[JsonDerivedType(typeof(BookDropship), "BookDropship")]
[JsonDerivedType(typeof(BookTaxi), "BookTaxi")]
[JsonDerivedType(typeof(BuyMicroResources), "BuyMicroResources")]
[JsonDerivedType(typeof(BuySuit), "BuySuit")]
[JsonDerivedType(typeof(BuyWeapon), "BuyWeapon")]
[JsonDerivedType(typeof(CancelDropship), "CancelDropship")]
[JsonDerivedType(typeof(CancelTaxi), "CancelTaxi")]
[JsonDerivedType(typeof(CollectItems), "CollectItems")]
[JsonDerivedType(typeof(CreateSuitLoadout), "CreateSuitLoadout")]
[JsonDerivedType(typeof(DeleteSuitLoadout), "DeleteSuitLoadout")]
[JsonDerivedType(typeof(Disembark), "Disembark")]
[JsonDerivedType(typeof(DropItems), "DropItems")]
[JsonDerivedType(typeof(DropShipDeploy), "DropShipDeploy")]
[JsonDerivedType(typeof(Embark), "Embark")]
[JsonDerivedType(typeof(FCMaterials), "FCMaterials")]
[JsonDerivedType(typeof(LoadoutEquipModule), "LoadoutEquipModule")]
[JsonDerivedType(typeof(LoadoutRemoveModule), "LoadoutRemoveModule")]
[JsonDerivedType(typeof(RenameSuitLoadout), "RenameSuitLoadout")]
[JsonDerivedType(typeof(ScanOrganic), "ScanOrganic")]
[JsonDerivedType(typeof(SellMicroResources), "SellMicroResources")]
[JsonDerivedType(typeof(SellOrganicData), "SellOrganicData")]
[JsonDerivedType(typeof(SellSuit), "SellSuit")]
[JsonDerivedType(typeof(SellWeapon), "SellWeapon")]
[JsonDerivedType(typeof(ShipLockerMaterials), "ShipLocker")]
[JsonDerivedType(typeof(SuitLoadout), "SuitLoadout")]
[JsonDerivedType(typeof(SwitchSuitLoadout) , "SwitchSuitLoadout")]
[JsonDerivedType(typeof(TradeMicroResources), "TradeMicroResources")]
[JsonDerivedType(typeof(TransferMicroResources), "TransferMicroResources")]
[JsonDerivedType(typeof(UpgradeSuit), "UpgradeSuit")]
[JsonDerivedType(typeof(UpgradeWeapon), "UpgradeWeapon")]
[JsonDerivedType(typeof(UseConsumable), "UseConsumable")]
[JsonDerivedType(typeof(AfmuRepairs), "AfmuRepairs")]
[JsonDerivedType(typeof(ApproachSettlement), "ApproachSettlement")]
[JsonDerivedType(typeof(CargoTransfer), "CargoTransfer")]
[JsonDerivedType(typeof(ChangeCrewRole), "ChangeCrewRole")]
[JsonDerivedType(typeof(CockpitBreached), "CockpitBreached")]
[JsonDerivedType(typeof(CommitCrime), "CommitCrime")]
[JsonDerivedType(typeof(Continued), "Continued")]
[JsonDerivedType(typeof(CrewLaunchFighter), "CrewLaunchFighter")]
[JsonDerivedType(typeof(CrewMemberJoins), "CrewMemberJoins")]
[JsonDerivedType(typeof(CrewMemberQuits), "CrewMemberQuits")]
[JsonDerivedType(typeof(CrewMemberRoleChange), "CrewMemberRoleChange")]
[JsonDerivedType(typeof(CrimeVictim), "CrimeVictim")]
[JsonDerivedType(typeof(DataScanned), "DataScanned")]
[JsonDerivedType(typeof(DatalinkScan), "DatalinkScan")]
[JsonDerivedType(typeof(DatalinkVoucher), "DatalinkVoucher")]
[JsonDerivedType(typeof(DockFighter), "DockFighter")]
[JsonDerivedType(typeof(DockSRV), "DockSRV")]
[JsonDerivedType(typeof(EndCrewSession), "EndCrewSession")]
[JsonDerivedType(typeof(FighterRebuilt), "FighterRebuilt")]
[JsonDerivedType(typeof(Friends), "Friends")]
[JsonDerivedType(typeof(FuelScoop), "FuelScoop")]
[JsonDerivedType(typeof(JetConeBoost), "JetConeBoost")]
[JsonDerivedType(typeof(JetConeDamage), "JetConeDamage")]
[JsonDerivedType(typeof(JoinACrew), "JoinACrew")]
[JsonDerivedType(typeof(KickCrewMember), "KickCrewMember")]
[JsonDerivedType(typeof(LaunchDrone), "LaunchDrone")]
[JsonDerivedType(typeof(LaunchFighter), "LaunchFighter")]
[JsonDerivedType(typeof(LaunchSRV), "LaunchSRV")]
[JsonDerivedType(typeof(ModuleInfo), "ModuleInfo")]
[JsonDerivedType(typeof(Music), "Music")]
[JsonDerivedType(typeof(NpcCrewPaidWage), "NpcCrewPaidWage")]
[JsonDerivedType(typeof(NpcCrewRank), "NpcCrewRank")]
[JsonDerivedType(typeof(Promotion), "Promotion")]
[JsonDerivedType(typeof(ProspectedAsteroid), "ProspectedAsteroid")]
[JsonDerivedType(typeof(QuitACrew), "QuitACrew")]
[JsonDerivedType(typeof(RebootRepair), "RebootRepair")]
[JsonDerivedType(typeof(ReceiveText), "ReceiveText")]
[JsonDerivedType(typeof(RepairDrone), "RepairDrone")]
[JsonDerivedType(typeof(ReservoirReplenished), "ReservoirReplenished")]
[JsonDerivedType(typeof(Resurrect), "Resurrect")]
[JsonDerivedType(typeof(Scanned), "Scanned")]
[JsonDerivedType(typeof(SelfDestruct), "SelfDestruct")]
[JsonDerivedType(typeof(SendText), "SendText")]
[JsonDerivedType(typeof(Shutdown), "Shutdown")]
[JsonDerivedType(typeof(Synthesis), "Synthesis")]
[JsonDerivedType(typeof(SystemsShutdown), "SystemsShutdown")]
[JsonDerivedType(typeof(USSDrop), "USSDrop")]
[JsonDerivedType(typeof(VehicleSwitch), "VehicleSwitch")]
[JsonDerivedType(typeof(WingAdd), "WingAdd")]
[JsonDerivedType(typeof(WingInvite), "WingInvite")]
[JsonDerivedType(typeof(WingJoin), "WingJoin")]
[JsonDerivedType(typeof(WingLeave), "WingLeave")]
[JsonDerivedType(typeof(PowerplayCollect), "PowerplayCollect")]
[JsonDerivedType(typeof(PowerplayDefect), "PowerplayDefect")]
[JsonDerivedType(typeof(PowerplayDeliver), "PowerplayDeliver")]
[JsonDerivedType(typeof(PowerplayFastTrack), "PowerplayFastTrack")]
[JsonDerivedType(typeof(PowerplayJoin), "PowerplayJoin")]
[JsonDerivedType(typeof(PowerplayLeave), "PowerplayLeave")]
[JsonDerivedType(typeof(PowerplaySalary), "PowerplaySalary")]
[JsonDerivedType(typeof(PowerplayVote), "PowerplayVote")]
[JsonDerivedType(typeof(PowerplayVoucher), "PowerplayVoucher")]
[JsonDerivedType(typeof(AppliedToSquadron), "AppliedToSquadron")]
[JsonDerivedType(typeof(DisbandedSquadron), "DisbandedSquadron")]
[JsonDerivedType(typeof(InvitedToSquadron), "InvitedToSquadron")]
[JsonDerivedType(typeof(JoinedSquadron), "JoinedSquadron")]
[JsonDerivedType(typeof(KickedFromSquadron), "KickedFromSquadron")]
[JsonDerivedType(typeof(LeftSquadron), "LeftSquadron")]
[JsonDerivedType(typeof(SharedBookmarkToSquadron), "SharedBookmarkToSquadron")]
[JsonDerivedType(typeof(SquadronCreated), "SquadronCreated")]
[JsonDerivedType(typeof(SquadronDemotion), "SquadronDemotion")]
[JsonDerivedType(typeof(SquadronPromotion), "SquadronPromotion")]
[JsonDerivedType(typeof(SquadronStartup), "SquadronStartup")]
[JsonDerivedType(typeof(WonATrophyForSquadron), "WonATrophyForSquadron")]
[JsonDerivedType(typeof(Cargo), "Cargo")]
[JsonDerivedType(typeof(ClearSavedGame), "ClearSavedGame")]
[JsonDerivedType(typeof(Commander), "Commander")]
[JsonDerivedType(typeof(FileHeader), "Fileheader")]
[JsonDerivedType(typeof(LoadGame), "LoadGame")]
[JsonDerivedType(typeof(Loadout), "Loadout")]
[JsonDerivedType(typeof(Materials), "Materials")]
[JsonDerivedType(typeof(Missions), "Missions")]
[JsonDerivedType(typeof(NewCommander), "NewCommander")]
[JsonDerivedType(typeof(Passengers), "Passengers")]
[JsonDerivedType(typeof(Powerplay), "Powerplay")]
[JsonDerivedType(typeof(Progress), "Progress")]
[JsonDerivedType(typeof(Rank), "Rank")]
[JsonDerivedType(typeof(Reputation), "Reputation")]
[JsonDerivedType(typeof(Statistics), "Statistics")]
[JsonDerivedType(typeof(BuyAmmo), "BuyAmmo")]
[JsonDerivedType(typeof(BuyDrones), "BuyDrones")]
[JsonDerivedType(typeof(CargoDepot), "CargoDepot")]
[JsonDerivedType(typeof(CommunityGoal), "CommunityGoal")]
[JsonDerivedType(typeof(CommunityGoalDiscard), "CommunityGoalDiscard")]
[JsonDerivedType(typeof(CommunityGoalJoin), "CommunityGoalJoin")]
[JsonDerivedType(typeof(CommunityGoalReward), "CommunityGoalReward")]
[JsonDerivedType(typeof(CrewAssign), "CrewAssign")]
[JsonDerivedType(typeof(CrewFire), "CrewFire")]
[JsonDerivedType(typeof(CrewHire), "CrewHire")]
[JsonDerivedType(typeof(EngineerApply), "EngineerApply")]
[JsonDerivedType(typeof(EngineerContribution), "EngineerContribution")]
[JsonDerivedType(typeof(EngineerCraft), "EngineerCraft")]
[JsonDerivedType(typeof(EngineerLegacyConvert), "EngineerLegacyConvert")]
[JsonDerivedType(typeof(EngineerProgress), "EngineerProgress")]
[JsonDerivedType(typeof(FetchRemoteModule), "FetchRemoteModule")]
[JsonDerivedType(typeof(Market), "Market")]
[JsonDerivedType(typeof(MassModuleStore), "MassModuleStore")]
[JsonDerivedType(typeof(MaterialTrade), "MaterialTrade")]
[JsonDerivedType(typeof(MissionAbandoned), "MissionAbandoned")]
[JsonDerivedType(typeof(MissionAccepted), "MissionAccepted")]
[JsonDerivedType(typeof(MissionCompleted), "MissionCompleted")]
[JsonDerivedType(typeof(MissionFailed), "MissionFailed")]
[JsonDerivedType(typeof(MissionRedirected), "MissionRedirected")]
[JsonDerivedType(typeof(ModuleBuy), "ModuleBuy")]
[JsonDerivedType(typeof(ModuleRetrieve), "ModuleRetrieve")]
[JsonDerivedType(typeof(ModuleSell), "ModuleSell")]
[JsonDerivedType(typeof(ModuleSellRemote), "ModuleSellRemote")]
[JsonDerivedType(typeof(ModuleStore), "ModuleStore")]
[JsonDerivedType(typeof(ModuleSwap), "ModuleSwap")]
[JsonDerivedType(typeof(Outfitting), "Outfitting")]
[JsonDerivedType(typeof(PayBounties), "PayBounties")]
[JsonDerivedType(typeof(PayFines), "PayFines")]
[JsonDerivedType(typeof(PayLegacyFines), "PayLegacyFines")]
[JsonDerivedType(typeof(RedeemVoucher), "RedeemVoucher")]
[JsonDerivedType(typeof(RefuelAll), "RefuelAll")]
[JsonDerivedType(typeof(RefuelPartial), "RefuelPartial")]
[JsonDerivedType(typeof(Repair), "Repair")]
[JsonDerivedType(typeof(RepairAll), "RepairAll")]
[JsonDerivedType(typeof(RestockVehicle), "RestockVehicle")]
[JsonDerivedType(typeof(ScientificResearch), "ScientificResearch")]
[JsonDerivedType(typeof(SearchAndRescue), "SearchAndRescue")]
[JsonDerivedType(typeof(SellDrones), "SellDrones")]
[JsonDerivedType(typeof(SellShipOnRebuy), "SellShipOnRebuy")]
[JsonDerivedType(typeof(SetUserShipName), "SetUserShipName")]
[JsonDerivedType(typeof(Shipyard), "Shipyard")]
[JsonDerivedType(typeof(ShipyardBuy), "ShipyardBuy")]
[JsonDerivedType(typeof(ShipyardNew), "ShipyardNew")]
[JsonDerivedType(typeof(ShipyardSell), "ShipyardSell")]
[JsonDerivedType(typeof(ShipyardSwap), "ShipyardSwap")]
[JsonDerivedType(typeof(ShipyardTransfer), "ShipyardTransfer")]
[JsonDerivedType(typeof(StoredModules), "StoredModules")]
[JsonDerivedType(typeof(StoredShips), "StoredShips")]
[JsonDerivedType(typeof(TechnologyBroker), "TechnologyBroker")]
[JsonDerivedType(typeof(AsteroidCracked), "AsteroidCracked")]
[JsonDerivedType(typeof(BuyTradeData), "BuyTradeData")]
[JsonDerivedType(typeof(CollectCargo), "CollectCargo")]
[JsonDerivedType(typeof(EjectCargo), "EjectCargo")]
[JsonDerivedType(typeof(MarketBuy), "MarketBuy")]
[JsonDerivedType(typeof(MarketSell), "MarketSell")]
[JsonDerivedType(typeof(MiningRefined), "MiningRefined")]
[JsonDerivedType(typeof(ApproachBody), "ApproachBody")]
[JsonDerivedType(typeof(Docked), "Docked")]
[JsonDerivedType(typeof(DockingCancelled), "DockingCancelled")]
[JsonDerivedType(typeof(DockingDenied), "DockingDenied")]
[JsonDerivedType(typeof(DockingGranted), "DockingGranted")]
[JsonDerivedType(typeof(DockingRequested), "DockingRequested")]
[JsonDerivedType(typeof(DockingTimeout), "DockingTimeout")]
[JsonDerivedType(typeof(FSDJump), "FSDJump")]
[JsonDerivedType(typeof(FSDTarget), "FSDTarget")]
[JsonDerivedType(typeof(LeaveBody), "LeaveBody")]
[JsonDerivedType(typeof(Liftoff), "Liftoff")]
[JsonDerivedType(typeof(Location), "Location")]
[JsonDerivedType(typeof(NavRoute), "NavRoute")]
[JsonDerivedType(typeof(NavRouteClear), "NavRouteClear")]
[JsonDerivedType(typeof(StartJump), "StartJump")]
[JsonDerivedType(typeof(SupercruiseEntry), "SupercruiseEntry")]
[JsonDerivedType(typeof(SupercruiseExit), "SupercruiseExit")]
[JsonDerivedType(typeof(Touchdown), "Touchdown")]
[JsonDerivedType(typeof(Undocked), "Undocked")]
[JsonDerivedType(typeof(Status), "Status")]
public class JournalBase
{
[JsonPropertyName("timestamp")]
Expand Down
4 changes: 4 additions & 0 deletions ObservatoryFramework/ObservatoryFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>ObservatoryFramework.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.0-preview.4.24266.19" />
</ItemGroup>

</Project>