Exemplo n.º 1
0
        private void ActionEvent()
        {
            // If we're in a delay, wait for it to finish first.
            if (_IsDelaying)
            {
                return;
            }

            UInt32 e;

            if (!_Queue.TryDequeue(out e))
            {
                // Nothing left in the queue: return.
                return;
            }

            var type = e.GetEventType();

            if (type == EventType.None)
            {
                // This shouldn't happen, but don't fail if it does.
                return;
            }
            else if (type == EventType.KeyUp)
            {
                // Key up event: pass to output and dequeue next item.
                var key = e.GetKeyPressedAsClient();
                _KeyboardOut.KeyUp(key);
                ActionEvent();
            }
            else if (type == EventType.KeyDown)
            {
                // Key down event: pass to output and dequeue next item.
                _KeyboardOut.KeyDown(e.GetKeyPressedAsClient());
                _UI.KeystrokesReceived = _UI.KeystrokesReceived + 1;
                ActionEvent();
            }
            else if (type == EventType.KeyPress)
            {
                // Key press event combines a key up and down.
                var key = e.GetKeyPressedAsClient();
                _KeyboardOut.KeyDown(key);
                _KeyboardOut.KeyUp(key);
                _UI.KeystrokesReceived = _UI.KeystrokesReceived + 1;
                ActionEvent();
            }
            else if (type == EventType.Delay)
            {
                // Delay event: wait for specified time on timer thread before processing next item.
                // Alternative: just sleep this thread for the delay time (depends on what thread this is though).
                var milliseconds = e.GetDelay();
                _Timer.Change(milliseconds, milliseconds);
                _IsDelaying = true;
            }
            else
            {
                throw new Exception("Unexpected state of event type: " + type);
            }
        }
        public void ClearBuffer()
        {
            string result;

            foreach (string s in Buffer)
            {
                if (s != null)
                {
                    Buffer.TryDequeue(out result);
                }
            }
        }
Exemplo n.º 3
0
        public void FixedSizeQueueCorrectlyDequeues()
        {
            int expected = 3;

            FixedSizeQueue<int> queue = new FixedSizeQueue<int>(10);

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Enqueue(6);

            int overflow;
            queue.TryDequeue(out overflow);
            queue.TryDequeue(out overflow);

            int actual;
            queue.TryDequeue(out actual);

            Assert.Equal(expected, actual);
        }