-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplayControlForm.cs
182 lines (148 loc) · 5.7 KB
/
ReplayControlForm.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using LiteDB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
namespace EDVRHUD
{
public partial class ReplayControlForm : Form
{
public ReplayControlForm()
{
InitializeComponent();
}
private void tbRate_ValueChanged(object sender, EventArgs e)
{
ReplayRate = (1000 - tbRate.Value);
lblRate.Text = tbRate.Value.ToString();
}
private Thread ReplayThread = null;
private bool ReplayRunning = false;
private int ReplayRate = 1000;
private bool ReplayBreakOnFSDJump = false;
private bool ReplayBreak = false;
private bool BeginOfReplay = true;
private JavaScriptSerializer Serializer = new JavaScriptSerializer();
private void btnStartStop_Click(object sender, EventArgs e)
{
if (ReplayThread == null)
{
btnStartStop.Text = "Stop";
dtpStartDate.Enabled = false;
dtpStartTime.Enabled = false;
ReplayThread = new Thread(() =>
{
if (!BeginOfReplay && !ReplayEntries.Any())
BeginOfReplay = true;
while (ReplayRunning)
{
if (!ThreadTick())
break;
if (ReplayRate > 0)
Thread.Sleep(ReplayRate);
//else
// Application.DoEvents();
}
Invoke((Action)(() =>
{
btnStartStop.Text = "Start";
lblTimestamp.BackColor = Form.DefaultBackColor;
dtpStartDate.Enabled = true;
dtpStartTime.Enabled = true;
}));
ReplayRunning = false;
ReplayThread = null;
})
{ IsBackground = true };
ReplayRunning = true;
lblTimestamp.BackColor = Color.Green;
ReplayThread.Start();
}
else
{
ReplayRunning = false;
}
}
//private List<string> AllLines = new List<string>();
private IList<Dictionary<string, object>> ReplayEntries = new List<Dictionary<string, object>>();
private DateTime SimTime;
private bool ThreadTick()
{
if (BeginOfReplay)
{
BeginOfReplay = false;
SimTime = dtpStartDate.Value.Date;
SimTime = SimTime.Add(dtpStartTime.Value.TimeOfDay);
var simEndTime = /*SimTime.Date*/DateTime.UtcNow.AddDays(1).AddSeconds(-1);
var s = new BsonValue(SimTime.ToString("yyyy-MM-ddTHH:mm:ssZ"));
var e = new BsonValue(simEndTime.ToString("yyyy-MM-ddTHH:mm:ssZ"));
ReplayEntries = EDCommon.DBJournal.Find(LiteDB.Query.Between("timestamp", s, e)).ToList();
NotificationApp.LastJournalTimeStamp = DateTime.MinValue;
EDCommon.TravelMapData.Clear();
ReplayBreak = false;
}
if (!ReplayEntries.Any())
{
return false;
}
//get line and
var entry = ReplayEntries.First();
var ts = entry.GetProperty("timestamp", "");
if (!DateTime.TryParse(ts.ToString(), out var tsdt))
{
ReplayEntries.RemoveAt(0);
return true;
}
tsdt = tsdt.ToUniversalTime();
BeginInvoke((Action)(() => { lblTimestamp.Text = ts + "/" + ReplayEntries.Count; }));
entry.Remove("_id");
entry.Remove("SimTime");
entry["IsReplay"] = true;
var currLine = Serializer.Serialize(entry);
if (!ReplayBreak && ReplayBreakOnFSDJump && currLine.Contains("\"event\":\"FSDJump\","))
{
ReplayBreak = true;
return false;
}
else
ReplayBreak = false;
//check timestamp
ReplayEntries.RemoveAt(0);
lock (NotificationApp.ContentLock)
NotificationApp.CachedContent += currLine + Environment.NewLine;
return true;
}
private void chkAutoPause_CheckedChanged(object sender, EventArgs e)
{
ReplayBreakOnFSDJump = chkAutoPause.Checked;
}
private void dtpStartDate_ValueChanged(object sender, EventArgs e)
{
ReplayEntries.Clear();
BeginOfReplay = true;
}
private void dtpStartTime_ValueChanged(object sender, EventArgs e)
{
ReplayEntries.Clear();
BeginOfReplay = true;
}
private void ReplayControlForm_FormClosing(object sender, FormClosingEventArgs e)
{
ReplayRunning = false;
if (ReplayThread != null)
{
ReplayThread.Abort();
ReplayThread = null;
}
}
}
}