Example #1
0
        private Boolean ExecuteStartState(ref ITcpServer server, Object[] args)
        {
            const String serverStartFormat = "=================> Server was started on {0} : {1}";
            Boolean      result;

            if (args.Length >= 2 && (args[0] != null && args[1] != null))
            {
                String          ipAddress    = args[0] as String;
                UInt16          port         = Convert.ToUInt16(args[1]);
                String          settingsFile = args[2] as String;
                String          scriptFile   = args[3] as String;
                TcpServerConfig config       = settingsFile != null?TcpServerConfigBuilder.Build(settingsFile) : null;

                if (server == null || scriptFile != null)
                {
                    server = new FlexibleTcpServer(scriptFile, ipAddress, port, _logger, false, config);
                }
                result = server.Start(ipAddress, port);
                if (result)
                {
                    System.Console.WriteLine(serverStartFormat, ipAddress, port);
                }
                _currentState = result ? MachineState.Started : _currentState;
                return(result);
            }
            result = server.Start();
            if (result)
            {
                System.Console.WriteLine("=================> Server was started");
            }
            _currentState = result ? MachineState.Started : _currentState;
            return(result);
        }
Example #2
0
        private Boolean ExecuteStartState(ref ITcpServer server, Object[] args)
        {
            const String serverStartFormat = "=================> Server was started on {0} : {1}";
            Boolean      result;

            if (args.Length >= 2 && (args[0] != null && args[1] != null))
            {
                String ipAddress = args[0] as String;
                if (!String.IsNullOrEmpty(ipAddress))
                {
                    _ipAddress = ipAddress;
                }
                UInt16 port = Convert.ToUInt16(args[1]);
                _port = port;
                String settingsFile = args[2] as String;
                String scriptFile   = args[3] as String;
                if (!String.IsNullOrEmpty(scriptFile))
                {
                    _scriptFile = scriptFile;
                }
                String          compilerOptionFile = args[4] as String;
                CompilerOptions compilerOptions    = compilerOptionFile != null?CompilerOptionsBuilder.Build(compilerOptionFile) : null;

                TcpServerConfig config = settingsFile != null?TcpServerConfigBuilder.Build(settingsFile) : null;

                if (compilerOptions != null)
                {
                    _compilerOptions = compilerOptions;
                }
                if (config != null)
                {
                    _config = config;
                }
                if (server == null || scriptFile != null || compilerOptionFile != null)
                {
                    //System.Console.WriteLine("tcp server re-creation....");
                    server = new FlexibleTcpServer(_scriptFile, _ipAddress, _port, _compilerOptions, _logger, false, _config);
                }
                result = server.Start(_ipAddress, _port);
                if (result)
                {
                    System.Console.WriteLine(serverStartFormat, _ipAddress, _port);
                }
                _currentState = result ? MachineState.Started : _currentState;
                return(result);
            }
            server = new FlexibleTcpServer(_scriptFile, _ipAddress, _port, _compilerOptions, _logger, false, _config);
            result = server.Start();
            if (result)
            {
                System.Console.WriteLine("=================> Server was started");
            }
            _currentState = result ? MachineState.Started : _currentState;
            return(result);
        }
Example #3
0
        private void ReadConfigAndCheck(String configFile, TcpServerConfig expectedConfig)
        {
            TcpServerConfig actualConfig = TcpServerConfigBuilder.Build(configFile);

            Assert.AreEqual(expectedConfig.ChunkSize, actualConfig.ChunkSize, "ChunkSize");
            Assert.AreEqual(expectedConfig.ClientBufferSize, actualConfig.ClientBufferSize, "ClientBufferSize");
            Assert.AreEqual(expectedConfig.ClientConnectAttempts, actualConfig.ClientConnectAttempts, "ClientConnectAttempts");
            Assert.AreEqual(expectedConfig.ClientConnectTimeout, actualConfig.ClientConnectTimeout, "ClientConnectTimeout");
            Assert.AreEqual(expectedConfig.ClientInactivityTime, actualConfig.ClientInactivityTime, "ClientInactivityTime");
            Assert.AreEqual(expectedConfig.ClientReadAttempts, actualConfig.ClientReadAttempts, "ClientReadAttempts");
            Assert.AreEqual(expectedConfig.ParallelTask, actualConfig.ParallelTask, "ParallelTask");
            Assert.AreEqual(expectedConfig.ReadTimeout, actualConfig.ReadTimeout, "ReadTimeout");
            Assert.AreEqual(expectedConfig.ServerCloseTimeout, actualConfig.ServerCloseTimeout, "ServerCloseTimeout");
            Assert.AreEqual(expectedConfig.WriteTimeout, actualConfig.WriteTimeout, "WriteTimeout");
        }
Example #4
0
        private void Start()
        {
            UInt16 port = Convert.ToUInt16(_portTextBox.Text);

            if (_server == null)
            {
                if (!String.IsNullOrEmpty(_configFile))
                {
                    _serverConfig = TcpServerConfigBuilder.Build(_configFile);
                }
                if (!String.IsNullOrEmpty(_compilerOptionsFile))
                {
                    _compilerOptions = CompilerOptionsBuilder.Build(_compilerOptionsFile);
                }
                if (_ipAddressComboBox.SelectedIndex >= 0 && _portTextBox.Text != null && !String.IsNullOrEmpty(_scriptFile))
                {
                    _server = ServerFactory.Create(_ipAddressComboBox.Items[_ipAddressComboBox.SelectedIndex].ToString(), port, _scriptFile, _logger, _compilerOptions, _serverConfig);
                }
                else
                {
                    MessageBox.Show(@"Can not start server, please select IP address, port and server script");
                    return;
                }
                _server.Start();
            }
            else
            {
                if (!String.IsNullOrEmpty(_compilerOptionsFile))
                {
                    _compilerOptions = CompilerOptionsBuilder.Build(_compilerOptionsFile);
                }
                if (_configChanged)
                {
                    _server = ServerFactory.Create(_ipAddressComboBox.Items[_ipAddressComboBox.SelectedIndex].ToString(), port, _scriptFile, _logger, _compilerOptions, _serverConfig);
                }
                _server.Start(_ipAddressComboBox.Items[_ipAddressComboBox.SelectedIndex].ToString(), port);
            }

            if (_timers[0] == null)
            {
                System.Threading.Timer periodicalUpdater = new System.Threading.Timer(StateUpdater, null, 500, 500);
                _timers[0] = periodicalUpdater;
            }
            else
            {
                _timers[0].Change(500, 500);
            }
        }