public IntegUnitTests(TestServerAppCoreEntryPointCfg fixture)
    {
        //preparing and establishing TCP connection
        ILifetimeScope container = fixture.Configure();

        _tcpServer = container.Resolve <ITcpServer>();
        _tcpClient = container.Resolve <TcpClient>();

        var prefs = container.Resolve <ISocketPrefs>();

        _tcpServer.Start();

        _tcpClient.Connect(prefs.IpAddress, prefs.PortNumber);

        var isConnected = _tcpClient.Connected;

        var clientStream = _tcpClient.GetStream();

        _sWriter = new StreamWriter(clientStream, Encoding.ASCII)
        {
            AutoFlush = true
        };
        _sReader = new StreamReader(clientStream, Encoding.ASCII);

        _sWriter.WriteLine("TestUser");
        _sWriter.WriteLine(Guid.NewGuid().ToString());

        _sReader.ReadLine();
    }
Exemplo n.º 2
0
        private async void BtnSwitchService_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnSwitchService.Text == @"启动")
                {
                    // 启动服务
                    if (!_server.Start())
                    {
                        throw new Exception($"error code: {_server.ErrorCode}, error message: {_server.ErrorMessage}");
                    }

                    btnSwitchService.Text = @"停止";

                    // 等待服务停止
                    await _server.WaitAsync();

                    // 停止以后还原按钮标题
                    btnSwitchService.Text = @"启动";

                    btnSwitchService.Enabled = true;
                }
                else
                {
                    btnSwitchService.Enabled = false;

                    // 等待服务停止
                    await _server.StopAsync();
                }
            }
            catch (Exception ex)
            {
                AddLog($"exception: {ex.Message}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The Function starts the service
        /// </summary>
        public void StartServer()
        {
            m_TCPServer.Start();

            m_logging.MessageRecieved += delegate(object sender, MessageRecievedEventArgs e)
            {
                LogMessage newLogMessage = new LogMessage
                {
                    Type    = e.Status,
                    Message = e.Message
                };

                List <LogMessage> newLogList = new List <LogMessage>();
                newLogList.Add(newLogMessage);

                CommandMessage msg = new CommandMessage
                {
                    Status      = true,
                    Type        = CommandEnum.LogAdded,
                    Message     = @"A new log entry was made",
                    LogMessages = newLogList
                };

                m_TCPServer.SendMessage(msg.ToJSONString(), ServerMessageTypeEnum.LogMessage);
            };

            string paths = System.Configuration.ConfigurationManager.AppSettings["Handler"];

            string[] pathArr = paths.Split(new char[] { ';' });
            foreach (string path in pathArr)
            {
                m_handlerManager.AddHandler(path);
            }
        }
Exemplo n.º 4
0
        public void Run()
        {
            var applicationArguments = _applicationArgumentsGetter.GetApplicationArguments();
            var loggingSystem        = _loggingSystemInitializer.Initialize(
                applicationArguments.FirstOrDefault(x => x.Key.Id == CommandLineArgument.LoggingConfigurationFile));

            if (loggingSystem == null)
            {
                return;
            }
            using (loggingSystem)
            {
                Configuration.Configuration configuration;
                if (_configurationReader.Read(out configuration) == false)
                {
                    return;
                }
                if (_tcpServer.Start(configuration.Binds, _httpRequestProcessor) == false)
                {
                    return;
                }
                Console.WriteLine("Press any key to stop the application.");
                Console.ReadKey();

                _tcpServer.Stop();
            }
        }
        public void Run()
        {
            _tcpServer.Start();
            _mqttBrocker.Start();

            //MQTT publisher starting
            _sysMonitorsPool.StartServices();
        }
Exemplo n.º 6
0
 public void Start()
 {
     lock (isStartedLock)
     {
         if (!isStarted)
         {
             cancelReceiveTokenSource  = new CancellationTokenSource();
             tcpServer.AcceptedClient += TcpServer_AcceptedClient;
             tcpServer.Start();
             isStarted = true;
         }
     }
 }
Exemplo n.º 7
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            server.Start(serverDefine.IP, serverDefine.Port);

            grpcSetUp.SetUp(serverDefine.IP, serverDefine.GrpcPort);

            var database   = mongoClient.GetDatabase("game");
            var collection = database.GetCollection <BsonDocument>("player");
            var document   = new BsonDocument("name", "bbb");

            collection.InsertOne(document);

            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        private async void BtnSwitchService_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnSwitchService.Text == @"启动")
                {
                    // 2个线程处理耗时操作, 作为相对耗时的任务, 可根据业务需求多开线程处理
                    if (!_threadPool.Start(2, RejectedPolicy.WaitFor))
                    {
                        btnSwitchService.Enabled = false;
                        throw new Exception($"线程池启动失败, 错误码: {_threadPool.ErrorCode}");
                    }

                    // 启动服务
                    if (!_server.Start())
                    {
                        throw new Exception($"error code: {_server.ErrorCode}, error message: {_server.ErrorMessage}");
                    }

                    btnSwitchService.Text = @"停止";

                    // 等待线程池停止
                    await _threadPool.WaitAsync();

                    // 等待服务停止
                    await _server.WaitAsync();

                    // 停止以后还原按钮标题
                    btnSwitchService.Text = @"启动";

                    btnSwitchService.Enabled = true;
                }
                else
                {
                    btnSwitchService.Enabled = false;
                    // 停止并等待线程池任务全部完成
                    await _threadPool.StopAsync();

                    // 等待服务停止
                    await _server.StopAsync();
                }
            }
            catch (Exception ex)
            {
                AddLog($"exception: {ex.Message}");
            }
        }
        public void Start(int acceptWorkers, CancellationTokenSource cts)
        {
            this.cts = cts;

            // catalog provider
            // do not load for test
            //CatalogProvider.Load();

            // start tcp server
            Server.Start(EndPoint.Host, EndPoint.Port, acceptWorkers);

            ShowEnv();
            ShowUsage();

            // start command line interpreter
            BConsole.Enabled = true;
            commandLineInterpreter?.Start(cts);
        }
Exemplo n.º 10
0
        private void Start_button_Click(object sender, EventArgs e)
        {
            _ipAddress = IPAddress_textBox.Text;
            _port      = Port_textBox.Text;
            IEventListener      listener = new EventListener();
            EchoServiceProvider Provider = new EchoServiceProvider(listener);
            int port;

            if (int.TryParse(Port_textBox.Text, out port))
            {
                _server = new TcpServer(Provider, IPAddress_textBox.Text, port);
            }
            else
            {
                MessageBox.Show("invalid port!");
                return;
            }
            try
            {
                if (!_server.Start())
                {
                    MessageBox.Show("Start failed");
                    return;
                }
                if (USB_checkBox.Checked)
                {
                    _usbServer = new TcpServer(Provider, "127.0.0.1", 15555);
                    if (!_usbServer.Start())
                    {
                        MessageBox.Show("Start USB Support failed");
                    }
                }
                MessageBox.Show("Server Started");
                Status_label.ForeColor = Color.Green;
                Status_label.Text      = "Start";
                Stop_button.Enabled    = true;
                Start_button.Enabled   = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Start failed:" + ex.Message);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// constructor, start the server and creath hanlers for the directory we need to watch
        /// </summary>
        /// <param name="m_controller">The controller.</param>
        /// <param name="m_logging">The logger.</param>
        public ImageServer(IImageController m_controller, ILoggingService m_logging)
        {
            this.m_controller = m_controller;
            this.m_logging    = m_logging;
            Handlers          = new Dictionary <string, IDirectoryHandler>();
            string[] dirs = ConfigurationManager.AppSettings.Get("Handler").Split(';');

            foreach (string dir in dirs)
            {
                IDirectoryHandler handler = new DirectoryHandler(m_controller, m_logging);
                Handlers[dir] = handler;
                this.m_logging.Log("handler created for " + dir + " directory", Logging.Modal.MessageTypeEnum.INFO);
                CommandRecieved += handler.OnCommandRecieved;
                CloseServer     += handler.CloseHandler;
                handler.StartHandleDirectory(dir);
                this.m_logging.Log("handler started for " + dir + " directory", Logging.Modal.MessageTypeEnum.INFO);
            }
            try {
                m_tcpServer = new TcpServer();
                m_tcpServer.DataRecieved += this.OnCommandRecieved;
                m_tcpServer.Start();
            } catch (Exception e) {
            }
        }
Exemplo n.º 12
0
 public void Initialize(Location location, string[] args)
 {
     _server = null;
     _server = new TcpServer(Environment.NewLine);
     _server.IncomingMessage += Handle_serverIncomingMessage;
     _server.ClientConnected += Handle_serverClientConnected;
     _server.Start();
     Logger.Write("Server started and running on port {0}", _server.Port);
     _executable = getExecutable(args);
     _parameters = getParameters();
     if (_process != null)
         _process.Kill();
     _process = new Process();
     _process.StartInfo = new ProcessStartInfo(_executable, _parameters);
     _process.StartInfo.CreateNoWindow = true;
     _process.StartInfo.UseShellExecute = true;
     _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     _process.Start();
     listenForModifications();
     Thread.Sleep(500);
     _isInitialized = true;
     GoTo(location);
 }