//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)); }