public override void Execute(HttpRequestReceivedEventArgs args)
        {
            //body should contain a series of commands seperate by /r/n
            var commands = new ArrayList();
            var startIndex = 0;
            var commandIndex = args.Body.IndexOf("\n");
            while (commandIndex > 0)
            {
                commands.Add(args.Body.Substring(startIndex, commandIndex - startIndex));
                startIndex = commandIndex + 1;
                commandIndex = args.Body.IndexOf("\n", startIndex);
            };

            var nixieCommand = new NixieCommand(commands);
            _nixieDevice.SetBackgroundColour(nixieCommand.Colour);
            _nixieDevice.SetNumber(nixieCommand.Number);
            _nixieDevice.SetSpacer(nixieCommand.Separator);
            _nixieDevice.Display();
        }
示例#2
0
        private void StartServer()
        {
            var listener = new HttpListener("http", _port);
            listener.Start();

            while (listener.IsListening)
            {
                var context = listener.GetContext();
                new Thread(() =>
                {
                    var args = new HttpRequestReceivedEventArgs(context);
                    var controller = _modules.Find(context.Request.RawUrl);
                    controller.Execute(args);

                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                    context.Response.KeepAlive = false;
                    context.Response.StatusDescription = "OK";
                    context.Response.Close();
                }).Start();
            }
        }
 public abstract void Execute(HttpRequestReceivedEventArgs args);