Ejemplo n.º 1
0
    private void HandoutDevices()
    {
        if (!inputRequests.Any())
        {
            return;
        }
        IEnumerable <InputDevice> unusedDevices =
            from pair in devices
            where pair.Key != null && !pair.Value
            select pair.Key;
        List <InputDevice> sortedDevices = unusedDevices.OrderBy(d => d.SortOrder).ToList();

        if (sortedDevices.Any())
        {
            // This int is outside the loop because it must be used to remove
            // all fulfilled requests (if there are more requests than devices,
            // i will go up to the index of the first request left unfulfilled)
            int i = 0;
            for (; i < sortedDevices.Count && i < inputRequests.Count; i++)
            {
                InputDevice         device          = sortedDevices[i];
                InputDeviceCallback createdCallback = inputRequests.Values[i].Item1;
                Action action = inputRequests.Values[i].Item2;
                devices[device] = true;
                actions[device] = action;
                createdCallback(device);
            }
            Dictionary <int, Tuple <InputDeviceCallback, Action> > unfufilledRequestsDictionary = inputRequests.Skip(i).ToDictionary(
                pair => pair.Key, pair => pair.Value);
            inputRequests = new SortedList <int, Tuple <InputDeviceCallback, Action> >(unfufilledRequestsDictionary);
        }
    }
Ejemplo n.º 2
0
 public void AddToInputQueue(int priority, InputDeviceCallback callback, Action action)
 {
     inputRequests.Add(priority, Tuple.Create(callback, action));
     HandoutDevices();
 }