28 lines
855 B
C#
28 lines
855 B
C#
using System.Globalization;
|
|
|
|
namespace ErsatzTV.Application.Channels;
|
|
|
|
public static class AutoTuneNumberAllocator
|
|
{
|
|
// Allocate `count` sequential integer channel numbers starting at `startingNumber`,
|
|
// skipping any number already present in `existingNumbers`. Channel.Number is a string,
|
|
// so numbers are returned as invariant-culture strings.
|
|
public static List<string> Allocate(int startingNumber, int count, ISet<string> existingNumbers)
|
|
{
|
|
var result = new List<string>(count);
|
|
int next = startingNumber;
|
|
while (result.Count < count)
|
|
{
|
|
string candidate = next.ToString(CultureInfo.InvariantCulture);
|
|
if (!existingNumbers.Contains(candidate))
|
|
{
|
|
result.Add(candidate);
|
|
}
|
|
|
|
next++;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|