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); }
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); } }