-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathNavRouteInfo.cs
More file actions
47 lines (41 loc) · 1.42 KB
/
NavRouteInfo.cs
File metadata and controls
47 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Utilities;
namespace EddiDataDefinitions
{
public class NavRouteInfo ( DateTime timestamp, List<NavRouteInfoItem> route )
{
[JsonProperty]
private DateTime timestamp { get; } = timestamp;
[JsonProperty]
public List<NavRouteInfoItem> Route { get; } = route ?? [ ];
[UsedImplicitly]
public static bool TryFromFile (
DateTime journalTimeStamp, bool isRouteExpected,
[CanBeNull] out NavRouteInfo info, [CanBeNull] out string rawRoute,
string filename = "NavRoute.json" )
{
info = null;
rawRoute = null;
var (raw, parsed) = Files.FromSavedGamesAsync(
filename,
extract: json =>
{
var o = JsonConvert.DeserializeObject<NavRouteInfo>( json );
return (o?.timestamp, o);
},
compareTo: journalTimeStamp
).GetResultOrTimeout( TimeSpan.FromSeconds( 5 ) );
if ( parsed?.Route != null &&
( ( isRouteExpected && parsed.Route.Count > 0 ) || ( !isRouteExpected && parsed.Route.Count == 0 ) ) )
{
info = parsed;
rawRoute = raw;
return true;
}
return false;
}
}
}