Skip to content

Commit 4ae4e46

Browse files
committed
checks for duplicate keys in participant list
1 parent 6d41b7b commit 4ae4e46

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Assets/UXF/Scripts/UI/ParticipantListSelection.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,21 @@ public void SetPPList(DataTable data)
141141

142142
Debug.Log(string.Format("Loaded: {0}", ppListPath));
143143

144-
List<string> participants = ppList.AsEnumerable().Select(x => x[0].ToString()).ToList();
145-
participantSelector.SetParticipants(participants);
144+
IEnumerable<string> participants = ppList
145+
.AsEnumerable()
146+
.Select(x => x[0].ToString());
147+
148+
IEnumerable<string> duplicatedParticipants = participants.GroupBy(x => x)
149+
.Where(g => g.Count() > 1)
150+
.Select(y => y.Key);
151+
152+
foreach (string ppid in duplicatedParticipants)
153+
{
154+
string s = string.Format("Participant '{0}' is listed multiple times in the participant list. Only the first listing will be used.", ppid);
155+
Debug.LogWarning(s);
156+
}
157+
158+
participantSelector.SetParticipants(participants.Distinct().ToList());
146159
participantSelector.SelectNewList();
147160

148161
PlayerPrefs.SetString(ppListLocKey, ppListPath);
@@ -166,7 +179,7 @@ public void SetPPList(DataTable data)
166179

167180
public void UpdateFormByPPID(string ppid)
168181
{
169-
DataRow row = ppList.AsEnumerable().Single(r => r.Field<string>("ppid") == ppid);
182+
DataRow row = ppList.AsEnumerable().First(r => r.Field<string>("ppid") == ppid);
170183

171184
foreach (var dataPoint in startup.participantDataPoints)
172185
{
@@ -210,7 +223,7 @@ public string Finish()
210223
if (participantSelector.IsNewSelected())
211224
{
212225
// if new participant is given an id that exists in pplist, throw error
213-
DataRow searchResultRow = ppList.AsEnumerable().SingleOrDefault(r => r.Field<string>("ppid") == ppid);
226+
DataRow searchResultRow = ppList.AsEnumerable().FirstOrDefault(r => r.Field<string>("ppid") == ppid);
214227
if (searchResultRow != null)
215228
{
216229
form.ppidElement.controller.DisplayFault();

0 commit comments

Comments
 (0)