public void ReleaseColor(string groupName) { if (ColorAssignments.ContainsKey(groupName)) { var count = ColorAssignments[groupName].Count -= 1; if (count < 1) ColorAssignments.Remove(groupName); } }
public Color RequestColor(string groupName) { if (ColorAssignments.ContainsKey(groupName)) { ColorAssignments[groupName].Count++; return ColorAssignments[groupName].AssignedColor; } var assignedColor = GetNextAvailableColor(); ColorAssignments.Add(groupName, new ColorGroupDetails() { Count = 1, AssignedColor = assignedColor }); return assignedColor; }
private Color GetNextAvailableColor() { var assignedColors = ColorAssignments.Select(a => a.Value.AssignedColor).ToList(); return Colors.Values.Except(assignedColors).First(); }