@@ -21,10 +21,18 @@ public DeviceCollection(IEnumerable<T> deviceInfos)
21
21
}
22
22
23
23
_byId [ item . Id ] = item ;
24
- _byName [ item . NameClean ] = item ;
24
+ _byName [ GetNameKey ( item ) ] = item ;
25
25
}
26
26
}
27
27
28
+ /// <summary>
29
+ /// Generate a key that merge together the type of device and their name.
30
+ /// </summary>
31
+ /// <remarks>Recording and Playback device can share the same name, this is done to avoid conflict between the two</remarks>
32
+ /// <param name="item"></param>
33
+ /// <returns></returns>
34
+ private string GetNameKey ( T item ) => $ "{ item . Type } -{ item . NameClean } ";
35
+
28
36
public IEnumerator < T > GetEnumerator ( )
29
37
{
30
38
return _byId . Values . OrderBy ( info => info . DiscoveredAt ) . GetEnumerator ( ) ;
@@ -43,7 +51,7 @@ public void Add(T item)
43
51
}
44
52
45
53
_byId . TryAdd ( item . Id , item ) ;
46
- _byName . TryAdd ( item . NameClean , item ) ;
54
+ _byName . TryAdd ( GetNameKey ( item ) , item ) ;
47
55
}
48
56
49
57
public void Clear ( )
@@ -59,8 +67,7 @@ public bool Contains(T item)
59
67
throw new ArgumentNullException ( ) ;
60
68
}
61
69
62
- return _byId . ContainsKey ( item . Id ) || _byName . ContainsKey ( item . NameClean ) ;
63
-
70
+ return _byId . ContainsKey ( item . Id ) || _byName . ContainsKey ( GetNameKey ( item ) ) ;
64
71
}
65
72
66
73
public void CopyTo ( T [ ] array , int arrayIndex )
@@ -76,12 +83,13 @@ public bool Remove(T item)
76
83
}
77
84
78
85
var removeId = _byId . Remove ( item . Id ) ;
79
- var removeName = _byName . Remove ( item . NameClean , out var removedByName ) ;
86
+ var removeName = _byName . Remove ( GetNameKey ( item ) , out var removedByName ) ;
80
87
81
88
//If we found it by name, remove it also with it's id
82
89
//this avoid the case that a device is removed because of name matching
83
90
//but it's still used since we iterate the _byId
84
- if ( removeName ) {
91
+ if ( removeName )
92
+ {
85
93
_byId . Remove ( removedByName . Id ) ;
86
94
}
87
95
0 commit comments