@@ -21,6 +21,8 @@ public class DeviceInfo : IEquatable<DeviceInfo>, IComparable<DeviceInfo>
21
21
22
22
public bool IsUsb { get ; } = true ;
23
23
24
+ public DateTime DiscoveredAt { get ; set ; } = DateTime . UtcNow ;
25
+
24
26
public string NameClean
25
27
{
26
28
get
@@ -43,15 +45,6 @@ public string NameClean
43
45
}
44
46
}
45
47
46
- [ JsonConstructor ]
47
- public DeviceInfo ( string name , string id , DataFlow type , bool isUsb )
48
- {
49
- Name = name ;
50
- Id = id ;
51
- Type = type ;
52
- IsUsb = isUsb ;
53
- }
54
-
55
48
public DeviceInfo ( MMDevice device )
56
49
{
57
50
Name = device . FriendlyName ;
@@ -62,6 +55,16 @@ public DeviceInfo(MMDevice device)
62
55
IsUsb = enumerator == "USB" ;
63
56
}
64
57
58
+ [ JsonConstructor ]
59
+ public DeviceInfo ( string name , string id , DataFlow type , bool isUsb , DateTime discoveredAt )
60
+ {
61
+ Name = name ;
62
+ Id = id ;
63
+ Type = type ;
64
+ IsUsb = isUsb ;
65
+ DiscoveredAt = discoveredAt ;
66
+ }
67
+
65
68
66
69
public static bool operator == ( DeviceInfo left , DeviceInfo right )
67
70
{
@@ -79,18 +82,6 @@ public override string ToString()
79
82
return NameClean ;
80
83
}
81
84
82
- public int CompareTo ( DeviceInfo other )
83
- {
84
- if ( ReferenceEquals ( this , other ) ) return 0 ;
85
- if ( ReferenceEquals ( null , other ) ) return 1 ;
86
- var nameComparison = string . Compare ( NameClean , other . NameClean , StringComparison . Ordinal ) ;
87
- if ( nameComparison != 0 ) return nameComparison ;
88
- var idComparison = string . Compare ( Id , other . Id , StringComparison . Ordinal ) ;
89
- if ( idComparison != 0 ) return idComparison ;
90
- return Type . CompareTo ( other . Type ) ;
91
- }
92
-
93
-
94
85
95
86
public bool Equals ( DeviceInfo other )
96
87
{
@@ -119,5 +110,16 @@ public override int GetHashCode()
119
110
return hashCode ;
120
111
}
121
112
}
113
+
114
+ public int CompareTo ( DeviceInfo other )
115
+ {
116
+ if ( ReferenceEquals ( this , other ) ) return 0 ;
117
+ if ( ReferenceEquals ( null , other ) ) return 1 ;
118
+ var discoveredAtComparison = DiscoveredAt . CompareTo ( other . DiscoveredAt ) ;
119
+ if ( discoveredAtComparison != 0 ) return discoveredAtComparison ;
120
+ var nameComparison = string . Compare ( Name , other . Name , StringComparison . Ordinal ) ;
121
+ if ( nameComparison != 0 ) return nameComparison ;
122
+ return string . Compare ( Id , other . Id , StringComparison . Ordinal ) ;
123
+ }
122
124
}
123
125
}
0 commit comments