public static List<ClientGroup> GenerateGroups(ref Queue<ClientPair> queue, int currentInterval) { var clientGroups = new List<ClientGroup>(); var clientGroup = new ClientGroup(); while (queue.Count >= GroupSize) { // // For now, do a simple FIFO algorithm to generate the groups. // var clientPair = queue.Dequeue(); clientGroup.client1 = clientPair.client; clientPair = queue.Dequeue(); clientGroup.client2 = clientPair.client; /* ToDo: Re-enable this if Group Size goes back up to 4. clientPair = queue.Dequeue(); clientGroup.client3 = clientPair.client; clientPair = queue.Dequeue(); clientGroup.client4 = clientPair.client; */ clientGroups.Add(clientGroup); } // // If there are any remaining clients, check to see if they have gone through a full // cycle of intervals, which means that they should be dequeued. // if (queue.Count == 0) { return clientGroups; } // // If a client has been in the queue for the maximum time, dequeue them into a // new clientGroup which only contains them. // while (queue.ElementAt(0).IntervalsInQueue == currentInterval) { var cp = queue.Dequeue(); clientGroup = new ClientGroup(); clientGroup.client1 = cp.client; clientGroups.Add(clientGroup); if (queue.Count == 0) { break; } } return clientGroups; }
public static List <ClientGroup> GenerateGroups(ref Queue <ClientPair> queue, int currentInterval) { var clientGroups = new List <ClientGroup>(); var clientGroup = new ClientGroup(); while (queue.Count >= GroupSize) { // // For now, do a simple FIFO algorithm to generate the groups. // var clientPair = queue.Dequeue(); clientGroup.client1 = clientPair.client; clientPair = queue.Dequeue(); clientGroup.client2 = clientPair.client; /* ToDo: Re-enable this if Group Size goes back up to 4. * clientPair = queue.Dequeue(); * clientGroup.client3 = clientPair.client; * * clientPair = queue.Dequeue(); * clientGroup.client4 = clientPair.client; */ clientGroups.Add(clientGroup); } // // If there are any remaining clients, check to see if they have gone through a full // cycle of intervals, which means that they should be dequeued. // if (queue.Count == 0) { return(clientGroups); } // // If a client has been in the queue for the maximum time, dequeue them into a // new clientGroup which only contains them. // while (queue.ElementAt(0).IntervalsInQueue == currentInterval) { var cp = queue.Dequeue(); clientGroup = new ClientGroup(); clientGroup.client1 = cp.client; clientGroups.Add(clientGroup); if (queue.Count == 0) { break; } } return(clientGroups); }