Exemplo n.º 1
0
        protected override void OnShown(EventArgs e)
        {
            var workerFactory = new WorkerManager(
                new BufferManager(10, 2048), TimeSpan.FromTicks(1), _logger);

            var listener = new Listener(
                new ListenerSettings(IPAddress.Any, 8088),
                s => workerFactory.Get(new WorkerSocket(s))
                );

            var process = new ServerProcess(
                listener, () => new HttpMessageHandler(_logger),
                _logger)
                {
                    Name = "sandbox",
                    Server = _server
                };

            process.Start();

            StartStopButton.Click += (s, ce) =>
                {
                    if (process.IsStarted)
                    {
                        process.Stop();
                        StartStopButton.Text = "Start";
                    }
                    else
                    {
                        process.Start();
                        StartStopButton.Text = "Stop";
                    }
                };
        }
        public void cannot_start_one_already_started()
        {
            using (var sut = new ServerProcess(
                GetListenerMock().Object, () => GetMessageHandlerMock().Object, null))
            {
                sut.Start();

                // ReSharper disable AccessToDisposedClosure
                // executed right away, not disposed at this point
                Assert.Throws<InvalidOperationException>(() => sut.Start());
                // ReSharper restore AccessToDisposedClosure

                Thread.Sleep(50);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Start the language server.
        /// </summary>
        /// <returns>
        ///     A <see cref="Task"/> representing the operation.
        /// </returns>
        async Task Start()
        {
            if (_process == null)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (!_process.IsRunning)
            {
                Log.LogDebug("Starting language server...");

                await _process.Start();

                Log.LogDebug("Language server is running.");
            }

            Log.LogDebug("Opening connection to language server...");

            if (_connection == null)
            {
                _connection = new LspConnection(LoggerFactory, input: _process.OutputStream, output: _process.InputStream);
            }

            _connection.Connect(_dispatcher);

            Log.LogDebug("Connection to language server is open.");
        }
        public void can_restart_a_process()
        {
            using (var sut = new ServerProcess(
                GetListenerMock().Object, () => GetMessageHandlerMock().Object, null))
            {
                sut.Start();
                Assert.True(sut.IsStarted);

                sut.Stop();
                Assert.False(sut.IsStarted);

                sut.Start();
                Assert.True(sut.IsStarted);

                Thread.Sleep(50);
            }
        }
        /// <summary>
        /// Starts the server process and starts the standard output/error stream if it has not already been started
        /// </summary>
        private void StartServerProcess()
        {
            if (Running)
            {
                return;
            }

            ServerProcess.Start();

            try
            {
                ServerProcess.BeginOutputReadLine();
                ServerProcess.BeginErrorReadLine();
            }
            catch (InvalidOperationException) { }
        }
        /// <summary>
        /// Starts the server process and starts the standard output/error stream if it has not already been started
        /// </summary>
        /// <exception cref="InvalidOperationException">Process is already running</exception>
        private void StartServerProcess()
        {
            if (Running)
            {
                throw new InvalidOperationException("Can't start the server process when it is already running!");
            }
            ServerProcess.Start();
            Started?.Invoke(this, EventArgs.Empty);

            try
            {
                ServerProcess.BeginOutputReadLine();
                ServerProcess.BeginErrorReadLine();
            }
            catch (InvalidOperationException) { }
        }
Exemplo n.º 7
0
 public bool Start()
 {
     if (IsListening) return true;
     IsListening = true;
     Config.Load();
     //本地api
     InitDeulListener();
     try
     {
         m_apilistener.Start();
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
     if (Config.Ports != null)
     {
         foreach (int port in Config.Ports)
         {
             ServerProcess server = new ServerProcess(port, Config.ApiPort, Config.ServerExe, Config.Config);
             server.Start();
             Porcess.Add(server);
         }
     }
     else {
         Logger.Error("no configs");
     }
     InitRoomListener();
     try
     {
         m_listener.Start();
     }
     catch (Exception e)
     {
         Logger.Error(e);
         Stop();
     }
     if (IsListening)
     {
         infoTimer.Start();
     }
     return IsListening;
 }
        public void on_error_Exception_is_set()
        {
            var exception = new Exception();

            var listenerMock = new Mock<IListener>();
            listenerMock
                .Setup(o => o.AcceptAsync())
                .Callback(() => { throw exception; });

            using (var sut = new ServerProcess(
                listenerMock.Object, () => GetMessageHandlerMock().Object, null))
            {
                sut.Start();
                Thread.Sleep(50);

                Assert.Equal(exception, sut.Exception);
            }
        }
 public void start_with_no_server()
 {
     using (var sut = new ServerProcess(
         GetListenerMock().Object, () => GetMessageHandlerMock().Object, null))
     {
         // ReSharper disable AccessToDisposedClosure
         // executed right away, not disposed at this point
         Assert.DoesNotThrow(() => sut.Start());
         // ReSharper restore AccessToDisposedClosure
     }
 }
        public void on_error_IsStarted_is_false()
        {
            var listenerMock = GetListenerMock();
            listenerMock
                .Setup(o => o.AcceptAsync())
                .Callback(() => { throw new Exception(); });

            using (var sut = new ServerProcess(
                listenerMock.Object, () => GetMessageHandlerMock().Object, null))
            {
                sut.Start();
                Thread.Sleep(50);

                Assert.False(sut.IsStarted);
            }
        }