//ConcurrentQueue<IAction> actionQueue = new ConcurrentQueue<IAction>();

        Task IHttpAsyncHandler.Execute(HttpRequestContext context)
        {
            var    url         = context.Request.Url;
            string path        = url.AbsolutePath.ToLower();
            string queryString = url.Query.StartsWith("?") ? url.Query.Remove(0, 1) : url.Query;
            string body;

            using (var reader = new StreamReader(context.Request.InputStream))
            {
                body = reader.ReadToEnd();
            }
            var parameters = ParseParameters(queryString, body);

            switch (path)
            {
            // TODO: refactor this to put actions on a queue and run asynchronously so we don't block the caller

            case "/key":
                Debug.WriteLine("Handling 'Key' command:");
                Debug.WriteLine("Query String: " + queryString);
                Debug.WriteLine("Body: " + body);
                IAction action = new KeyAction();
                action.Initialize(parameters);
                //actionQueue.Enqueue(action);
                action.Execute();
                break;

            default:
                string message = "Unrecognized commnand in URL: " + path;
                Debug.WriteLine("ERROR: " + message);
                // TODO: change this to return a proper HTTP response instead
                throw new InvalidOperationException(message);
            }
            return(Task.FromResult(true));
        }
Пример #2
0
        private void TestParsing(string spec, IEnumerable <KeyboardEvent> expectedEvents, bool ignoreTimings = true)
        {
            var expected = expectedEvents.ToArray();

            KeyAction action = new KeyAction();

            action.Initialize(spec);
            var actual = action.ParseSpec().ToArray();

            Assert.AreEqual(expected.Count(), actual.Count(), "Event count mismatch for spec: " + spec);

            for (int i = 0; i < expected.Length; i++)
            {
                var e = expected[i];
                var a = actual[i];

                Assert.AreEqual(e.KeyCode, a.KeyCode, "Key code mismatch at position " + i + " for spec: " + spec);
                Assert.AreEqual(e.KeyDown, a.KeyDown, "Key down mismatch at position " + i + " for spec: " + spec);
                if (!ignoreTimings)
                {
                    Assert.AreEqual(e.Timeout, a.Timeout, "Timout mismatch at position " + i + " for spec: " + spec);
                }
            }
        }