private void button_save_Click(object sender, EventArgs e) { ConfCommandServiceInfo info = new ConfCommandServiceInfo(); int port = Convert.ToInt32(text_Port.Text == "" ? "0" : text_Port.Text); int second = Convert.ToInt32(text_Sec.Text == "" ? "0" : text_Sec.Text); if (port <= 9000 && port >= 65535) { MessageBox.Show("端口范围不对,9000~65535!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (second < 0 && second > 60) { MessageBox.Show("命令超时秒数范围不对,0~60!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } info.Port = port; info.timeoutSeconds = second; if (config.UpdateCommandInfo(info, out string errMsg)) { MessageBox.Show("更新命令配置信息成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("更新命令配置信息," + errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static bool CheckConfig(ConfCommandServiceInfo config, out string errMsg) { errMsg = ""; if (!config.EnvIsOkay) { errMsg = config.ErrMsg; return(false); } CommandManager.ip = config.IP; CommandManager.port = config.Port; CommandManager.timeoutSeconds = config.timeoutSeconds; if (!config.CheckIsValidPort(out errMsg)) { return(false); } return(true); }
public static void Start(Action <RequestCommand> actionRequestCommand, ConfCommandServiceInfo confCommandServiceInfo, out string errMsg) { errMsg = ""; if (IsRuning) { return; } config = confCommandServiceInfo; DoRequestCommand = actionRequestCommand; // 加载服务所需配置文件信息 if (!CheckConfig(config, out errMsg)) { return; } // 命令记录服务 if (commandRecorder != null) { commandRecorder.Stop(); } commandRecorder = new CommandRecorder(); commandRecorder.Start(); if (!commandRecorder.IsRuning) { TraceManagerForCommand.AppendErrMsg("命令记录服务打开失败"); Stop(); return; } // 命令消费者服务 if (commandConsumer != null) { commandConsumer.Stop(); } commandConsumer = new SocketCommandConsumer(DoRequestCommand); commandConsumer.Start(); if (!commandConsumer.IsRuning) { TraceManagerForCommand.AppendErrMsg("命令消费者服务打开失败"); Stop(); return; } //端口监听服务 if (tcpServer != null) { tcpServer.Stop(); } tcpServer = new SuperSocketTcpServerOper(CommandManager.ip, CommandManager.port); tcpServer.evtReciveHandle += CommandManager.commandConsumer.Append; //注册接受处理体 if (!tcpServer.Start(out errMsg)) { TraceManagerForCommand.AppendErrMsg("命令端口监听服务打开失败"); Stop(); return; } IsRuning = true; }