Skip to content

Commit

Permalink
Append index number to duplicated sensor names
Browse files Browse the repository at this point in the history
  • Loading branch information
ts-korhonen committed Aug 28, 2021
1 parent ddcfbc9 commit 99cec38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
13 changes: 13 additions & 0 deletions SensorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ private void Initialize()
if (enabledSensors.Contains(sensor.SensorType))
_sensors.Add(sensor);
}));

// Find duplicated names
var duplicates = _sensors
.GroupBy(sensor => sensor.Name)
.Where(group => group.Count() > 1);

// Append index number to each duplicated name (#2,#3,...)
foreach (var group in duplicates.Select(g => g.Skip(1)))
{
int index = 2;
foreach (var sensor in group)
sensor.Name += $" #{index++}";
}
}

public int SensorCount => _sensors.Count;
Expand Down

0 comments on commit 99cec38

Please sign in to comment.