aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2019-10-06 07:52:48 +0900
committerKazuki Yamaguchi <k@rhe.jp>2019-10-06 08:24:54 +0900
commitcfa77571c6656a4d1a4ad830de877a2edf05421a (patch)
treec112f62fd08653ecfbc4780858a688909a768b52
parentd45bf8688920cde63ec75ecf8539b1688141c5ce (diff)
downloadwf-clock-cfa77571c6656a4d1a4ad830de877a2edf05421a.tar.gz
move background tasks to AppData
-rw-r--r--WarframeClock/App.xaml.cs121
-rw-r--r--WarframeClock/AppData.cs140
2 files changed, 139 insertions, 122 deletions
diff --git a/WarframeClock/App.xaml.cs b/WarframeClock/App.xaml.cs
index 5302dbc..500efd1 100644
--- a/WarframeClock/App.xaml.cs
+++ b/WarframeClock/App.xaml.cs
@@ -20,7 +20,6 @@ namespace WarframeClock
public static readonly Uri WebsiteUri = new Uri(WebsiteUriString);
public static readonly AppData AppData = new AppData();
- private Timer _worldStateFetchTimer, _eeLogFetchTimer;
private string _debugTracePath;
protected override void OnStartup(StartupEventArgs e)
@@ -31,131 +30,11 @@ namespace WarframeClock
_debugTracePath = Path.GetTempFileName();
Trace.Listeners.Add(new TextWriterTraceListener(File.Create(_debugTracePath)));
}
- StartWorldStateFetchTimer();
- StartEeLogFetchTimer();
- }
-
- private void StartWorldStateFetchTimer()
- {
- _worldStateFetchTimer = new Timer(state =>
- {
- try
- {
- var worldState = WorldState.Fetch().Result;
- var cetusSyndicate =
- worldState.SyndicateMissions.FirstOrDefault(mi => mi.Tag == "CetusSyndicate");
- if (cetusSyndicate == null)
- {
- Trace.WriteLine("WorldState: CetusSyndicate missions not found");
- return;
- }
-
- var cetusExpiry = cetusSyndicate.Expiry.Date.NumberLong;
- Trace.WriteLine($"WorldState: CetusSyndicate missions expire at {cetusExpiry}");
- AppData.NextBountiesResetByWorldState = DateTimeOffset.FromUnixTimeMilliseconds(cetusExpiry);
- }
- catch (Exception ex)
- {
- Trace.WriteLine($"WorldState: Failed to fetch or parse worldState.php: {ex}");
- Trace.WriteLine(ex.StackTrace);
- }
- }, null, TimeSpan.Zero, TimeSpan.FromMinutes(10));
- }
-
- private void StartEeLogFetchTimer()
- {
- var parser = new EeLogParser();
-
- var regexSyncingWorldStateJobs = new Regex(@"^syncing world state jobs in ([0-9.]+)$");
- var regexWorldStateRefreshedFromDb = new Regex(@"^Background: world state refreshed from db$");
- var regexCetusJoin = new Regex(@"^IRC out: JOIN #H_CETUSHUB4_(.+)$");
- var regexArbitration = new Regex(@"^EliteAlertMission at (.+) \(.+\)$");
- var regexKuvaFlood = new Regex(@"^KuvaMission(\d+) at (.+)\((.+) - (.+)\)$");
- parser.OnLogEntry += (sender, args) =>
- {
- Match match;
-
- if ((match = regexSyncingWorldStateJobs.Match(args.Content)).Success)
- {
- var reset = args.DateTime.AddSeconds(
- double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture));
- if (reset < DateTimeOffset.UtcNow)
- return;
- AppData.NextBountiesReset = reset;
- Trace.WriteLine($"EE.log: 'syncing world state jobs in'; next bounties reset: {reset}");
- }
- else if ((match = regexWorldStateRefreshedFromDb.Match(args.Content)).Success)
- {
- if (AppData.NextBountiesReset == null)
- return;
- AppData.NextBountiesReset = null;
- Trace.WriteLine($"EE.log: 'world state refreshed from db'; resetting next bounties reset");
- }
- else if ((match = regexCetusJoin.Match(args.Content)).Success)
- {
- Trace.WriteLine($"EE.log: Loaded Cetus: {match.Groups[1].Value}");
- }
- else if ((match = regexArbitration.Match(args.Content)).Success)
- {
- Trace.WriteLine($"EE.log: Arbitration: {match.Groups[1].Value}");
- try
- {
- var solNode = WfcdWorldStateData.GetSolNode(match.Groups[1].Value);
- AppData.ArbitrationSolNodeUpdated = args.DateTime;
- AppData.ArbitrationSolNode = solNode;
- }
- catch (Exception ex)
- {
- Trace.WriteLine($"EE.log: Unknown SolNode");
- Trace.WriteLine(ex);
- }
- }
- else if ((match = regexKuvaFlood.Match(args.Content)).Success)
- {
- if (match.Groups[1].Value == "6" || match.Groups[1].Value == "12")
- {
- Trace.WriteLine($"EE.log: Arbitration: {match.Groups[1].Value}");
- try
- {
- Trace.WriteLine($"EE.log: Kuva Flood: {match.Groups[2].Value} " +
- $"({match.Groups[3].Value} - {match.Groups[4].Value})");
- var solNode = WfcdWorldStateData.GetSolNodeByName(match.Groups[3].Value,
- match.Groups[4].Value);
- AppData.KuvaFloodSolNodeUpdated = args.DateTime;
- AppData.KuvaFloodSolNode = solNode;
- }
- catch (Exception ex)
- {
- Trace.WriteLine($"EE.log: Unknown SolNode");
- Trace.WriteLine(ex);
- }
- }
- }
- };
- parser.OnLogFileReset += (sender, args) =>
- {
- AppData.NextBountiesReset = null;
- };
-
- _eeLogFetchTimer = new Timer(state =>
- {
- try
- {
- parser.Update();
- }
- catch (Exception ex)
- {
- Trace.WriteLine($"EE.log: Failed to parse EE.log: {ex}");
- Trace.WriteLine(ex.StackTrace);
- }
- }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
}
internal void Terminate()
{
- _worldStateFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
- _eeLogFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
MainWindow?.Close();
if (DEBUG)
{
diff --git a/WarframeClock/AppData.cs b/WarframeClock/AppData.cs
index 7aacee7..ea59d1f 100644
--- a/WarframeClock/AppData.cs
+++ b/WarframeClock/AppData.cs
@@ -1,8 +1,13 @@
using System;
+using System.Diagnostics;
+using System.Globalization;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading;
namespace WarframeClock
{
- public class AppData
+ public class AppData : IDisposable
{
public DateTimeOffset NextBountiesResetByWorldState { get; set; } =
DateTimeOffset.FromUnixTimeMilliseconds(1548159123053);
@@ -15,5 +20,138 @@ namespace WarframeClock
public DateTimeOffset KuvaFloodSolNodeUpdated { get; set; } =
DateTimeOffset.FromUnixTimeMilliseconds(0);
public WfcdWorldStateData.SolNode KuvaFloodSolNode { get; set; }
+
+ private Timer _worldStateFetchTimer, _eeLogFetchTimer;
+
+ public AppData()
+ {
+ StartWorldStateFetchTimer();
+ StartEeLogFetchTimer();
+ }
+
+ public void Dispose()
+ {
+ _worldStateFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
+ _worldStateFetchTimer.Dispose();
+ _eeLogFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
+ _eeLogFetchTimer.Dispose();
+ }
+
+ private void StartWorldStateFetchTimer()
+ {
+ _worldStateFetchTimer = new Timer(state =>
+ {
+ try
+ {
+ var worldState = WorldState.Fetch().Result;
+ var cetusSyndicate =
+ worldState.SyndicateMissions.FirstOrDefault(mi => mi.Tag == "CetusSyndicate");
+ if (cetusSyndicate == null)
+ {
+ Trace.WriteLine("WorldState: CetusSyndicate missions not found");
+ return;
+ }
+
+ var cetusExpiry = cetusSyndicate.Expiry.Date.NumberLong;
+ Trace.WriteLine($"WorldState: CetusSyndicate missions expire at {cetusExpiry}");
+ NextBountiesResetByWorldState = DateTimeOffset.FromUnixTimeMilliseconds(cetusExpiry);
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine($"WorldState: Failed to fetch or parse worldState.php: {ex}");
+ Trace.WriteLine(ex.StackTrace);
+ }
+ }, null, TimeSpan.Zero, TimeSpan.FromMinutes(10));
+ }
+
+ private void StartEeLogFetchTimer()
+ {
+ var parser = new EeLogParser();
+
+ var regexSyncingWorldStateJobs = new Regex(@"^syncing world state jobs in ([0-9.]+)$");
+ var regexWorldStateRefreshedFromDb = new Regex(@"^Background: world state refreshed from db$");
+ var regexCetusJoin = new Regex(@"^IRC out: JOIN #H_CETUSHUB4_(.+)$");
+ var regexArbitration = new Regex(@"^EliteAlertMission at (.+) \(.+\)$");
+ var regexKuvaFlood = new Regex(@"^KuvaMission(\d+) at (.+)\((.+) - (.+)\)$");
+ parser.OnLogEntry += (sender, args) =>
+ {
+ Match match;
+
+ if ((match = regexSyncingWorldStateJobs.Match(args.Content)).Success)
+ {
+ var reset = args.DateTime.AddSeconds(
+ double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture));
+ if (reset < DateTimeOffset.UtcNow)
+ return;
+ NextBountiesReset = reset;
+ Trace.WriteLine($"EE.log: 'syncing world state jobs in'; next bounties reset: {reset}");
+ }
+ else if ((match = regexWorldStateRefreshedFromDb.Match(args.Content)).Success)
+ {
+ if (NextBountiesReset == null)
+ return;
+ NextBountiesReset = null;
+ Trace.WriteLine($"EE.log: 'world state refreshed from db'; resetting next bounties reset");
+ }
+ else if ((match = regexCetusJoin.Match(args.Content)).Success)
+ {
+ Trace.WriteLine($"EE.log: Loaded Cetus: {match.Groups[1].Value}");
+ }
+ else if ((match = regexArbitration.Match(args.Content)).Success)
+ {
+ Trace.WriteLine($"EE.log: Arbitration: {match.Groups[1].Value}");
+ try
+ {
+ var solNode = WfcdWorldStateData.GetSolNode(match.Groups[1].Value);
+ ArbitrationSolNodeUpdated = args.DateTime;
+ ArbitrationSolNode = solNode;
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine($"EE.log: Unknown SolNode");
+ Trace.WriteLine(ex);
+ }
+ }
+ else if ((match = regexKuvaFlood.Match(args.Content)).Success)
+ {
+ if (match.Groups[1].Value == "6" || match.Groups[1].Value == "12")
+ {
+ Trace.WriteLine($"EE.log: Arbitration: {match.Groups[1].Value}");
+ try
+ {
+ Trace.WriteLine($"EE.log: Kuva Flood: {match.Groups[2].Value} " +
+ $"({match.Groups[3].Value} - {match.Groups[4].Value})");
+ var solNode = WfcdWorldStateData.GetSolNodeByName(match.Groups[3].Value,
+ match.Groups[4].Value);
+ KuvaFloodSolNodeUpdated = args.DateTime;
+ KuvaFloodSolNode = solNode;
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine($"EE.log: Unknown SolNode");
+ Trace.WriteLine(ex);
+ }
+ }
+ }
+ };
+
+ parser.OnLogFileReset += (sender, args) =>
+ {
+ NextBountiesReset = null;
+ };
+
+ _eeLogFetchTimer = new Timer(state =>
+ {
+ try
+ {
+ parser.Update();
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine($"EE.log: Failed to parse EE.log: {ex}");
+ Trace.WriteLine(ex.StackTrace);
+ }
+ }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
+ }
}
}