-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRealtimeInfo.cs
66 lines (59 loc) · 1.98 KB
/
RealtimeInfo.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBSharp
{
/// <summary>
/// Holds realtime changes to arrival/departure of a connection
/// </summary>
public class RealtimeInfo : ConnectionInfo, IMergeable<RealtimeInfo>
{
public RealtimeInfo()
{
Messages = new List<InformationMessage>();
}
/// <summary>
/// ps/cs = c/a
/// </summary>
public virtual string Status { get; set; }
/// <summary>
/// clt = [Timestamp]
/// </summary>
public virtual DateTime? StatusSince { get; set; }
/// <summary>
/// m
/// </summary>
public virtual List<InformationMessage> Messages { get; set; }
/// <summary>
/// Was connection caneled today?
/// </summary>
public virtual bool IsCanceled => Status == "c";
/// <summary>
/// Gets the latest delay message string
/// </summary>
/// <returns></returns>
public virtual string GetDelayReason() => Messages.OrderByDescending(m => m.Time).FirstOrDefault(m => m.Type == "d")?.GetHumanString();
public virtual void MergeChanges(RealtimeInfo changes)
{
if (changes != null)
{
base.MergeChanges(changes);
Status = changes.Status ?? Status;
StatusSince = changes.StatusSince ?? StatusSince;
if (changes.Messages != null)
{
foreach (var msg in changes.Messages)
{
var localEquivalent = Messages.Where(m => m.Uid == msg.Uid).FirstOrDefault();
if (localEquivalent != null)
localEquivalent.MergeChanges(msg);
else
Messages.Add(msg);
}
}
}
}
}
}