-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathMarketInfo.cs
More file actions
64 lines (55 loc) · 1.85 KB
/
MarketInfo.cs
File metadata and controls
64 lines (55 loc) · 1.85 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Utilities;
namespace EddiDataDefinitions
{
public class MarketInfo (
DateTime timestamp,
long marketId,
string stationName,
string starSystem,
List<MarketInfoItem> items )
{
[JsonProperty]
public DateTime timestamp { get; } = timestamp;
[JsonProperty]
public long MarketID { get; } = marketId;
[JsonProperty]
public string StationName { get; } = stationName;
[JsonProperty]
public string StarSystem { get; } = starSystem;
[JsonProperty]
public List<MarketInfoItem> Items { get; } = items ?? [ ];
[UsedImplicitly]
public static bool TryFromFile (
DateTime journalTimeStamp,
string expectedStarSystem, string expectedStation, long expectedMarketID,
[CanBeNull] out MarketInfo info, [CanBeNull] out string rawMarket,
string filename = "Market.json" )
{
info = null;
rawMarket = null;
var (raw, parsed) = Files.FromSavedGamesAsync(
filename,
extract: json =>
{
var o = JsonConvert.DeserializeObject<MarketInfo>( json );
return ( o?.timestamp, o );
},
compareTo: journalTimeStamp
).GetResultOrTimeout( TimeSpan.FromSeconds( 5 ) );
if ( parsed?.Items != null &&
parsed.StarSystem == expectedStarSystem &&
parsed.StationName == expectedStation &&
parsed.MarketID == expectedMarketID )
{
info = parsed;
rawMarket = raw;
return true;
}
return false;
}
}
}