public static void Stop() { //端口监听服务 try { if (tcpServer != null) { tcpServer.evtReciveHandle -= CommandManager.commandConsumer.Append; //注册接受处理体 tcpServer.Stop(); } tcpServer = null; } catch (Exception e) { TraceManagerForCommand.AppendErrMsg("命令端口监听服务停止失败" + "堆栈:" + e.StackTrace); } // 命令消费者服务 try { if (commandConsumer != null) { commandConsumer.Stop(); if (!commandConsumer.IsRuning) { CommandManager.commandConsumer = null; } else { TraceManagerForCommand.AppendErrMsg("命令消费者服务停止失败"); } } } catch (Exception e) { TraceManagerForCommand.AppendErrMsg("命令消费者服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } // 命令记录服务 try { if (commandRecorder != null) { commandRecorder.Stop(); if (!commandRecorder.IsRuning) { CommandManager.commandRecorder = null; } else { TraceManagerForCommand.AppendErrMsg("命令记录服务停止失败"); } } } catch (Exception e) { TraceManagerForCommand.AppendErrMsg("命令记录服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); } IsRuning = false; }
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; }