Esempio n. 1
0
 public DoubleWriter(TextWriter one, TextWriter two, WebSocketComms.CommsServer commsOutput)
 {
     _consoleBuffer = new List <ConsoleKeyPress>();
     this.one       = one;
     this.two       = two;
     _comms         = commsOutput;
 }
Esempio n. 2
0
        public WebConsole()
        {
            string[] prefix =
            {
                "http://localhost:8088/"
            };

            WebConsoleContent.Content c = new WebConsoleContent.Content();

            EmbeddedWebServer.ContentServer _server = new EmbeddedWebServer.ContentServer(prefix, c.GetType(), (request) =>
            {
                WebServer.Server.ResponseInformation resp = null;

                if (request.Url.AbsolutePath == "/console.txt")
                {
                    resp             = new WebServer.Server.ResponseInformation();
                    resp.Content     = System.Text.Encoding.UTF8.GetBytes(tOut.GetStringBuilder().ToString());
                    resp.ContentType = "text/plain";
                }

                return(resp);
            });

            _wsServer = new WebSocketComms.CommsServer("webconsole", "webconsole", this, 888, null);
            MirrorConsole();
        }
            public WebSocketListener(object commandStructure, CommsServer server, bool echo, Func <TCPCommand, TCPCommand, bool> checkMessage)
            {
                _echo             = echo;
                _checkMessage     = checkMessage;
                _commandStructure = commandStructure;
                _server           = server;
                messageQueue      = new ConcurrentQueue <TCPCommand>();
                sendSignal        = new AutoResetEvent(false);
                serializer        = new JsonSerializer();
                //sendTimer = new Timer(SendElapsed, null, 1000, Timeout.Infinite);

                sendingThread = new Thread(() =>
                {
                    while (running)
                    {
                        while (messageQueue.Count > 0)
                        {
                            TCPCommand msg;
                            while (!messageQueue.TryDequeue(out msg))
                            {
                                Thread.Sleep(1);
                            }

                            /*if (checkMessage != null && messageQueue.Count > 0)
                             * {
                             *  // 'checkMessage' allows us to compare the current message and the next one in the queue, to see if we should bother sending the current message
                             *  TCPCommand peekMessage;
                             *  while (!messageQueue.TryPeek(out peekMessage)) ;
                             *  while (!checkMessage(msg, peekMessage))
                             *  {
                             *      // checkMessage returned false, so we need to skip the current message, move on and then run the check again.
                             *      Console.WriteLine("Skipping " + msg.name);
                             *      while (!messageQueue.TryDequeue(out msg)) ;
                             *      if (messageQueue.Count > 0)
                             *      {
                             *          while (!messageQueue.TryPeek(out peekMessage)) ;
                             *      }
                             *      else
                             *      {
                             *          // at end of message queue, so we can't run the check again
                             *          break;
                             *      }
                             *  }
                             * }*/

                            StringWriter sw = new StringWriter();
                            serializer.Serialize(sw, msg);
                            Send(sw.ToString());
                            sw.Dispose();
                        }
                        sendSignal.WaitOne();
                    }
                });
                sendingThread.Start();
            }