//[Command] //IP=127.0.0.1 //Port=8001 //Type=40002000 //Data={"Item1":"127.0.0.1","Item2":8001} public static void Start() { Task.Factory.StartNew(() => { while (!R.MainUI.IsDisposed) { if (Ls.Ok(R.Tx.Hosts)) { List <string> cmd_files = FileTool.GetAllFile(R.Paths.Command, new[] { "*.cmd.ini" }); string tuple_string = Json.Object2String(new Tuple <string, int>("abc", 123)); if (Ls.Ok(cmd_files)) { foreach (var file in cmd_files) { string ip = IniTool.GetString(file, "Command", "IP", ""); int port = IniTool.GetInt(file, "Command", "Port", 0); int type = IniTool.GetInt(file, "Command", "Type", 0); string data = IniTool.GetString(file, "Command", "Data", ""); if (Str.Ok(ip) && type > 0) { List <string> hosts = TxHostMapTool.GetHost($"{ip}"); if (Ls.Ok(hosts)) { foreach (var host in hosts) { Tuple <string, int> info = new Tuple <string, int>(ip, port); string ss = Json.Object2String(info); R.Tx.TcppServer.Write(host, type, Json.Object2Byte(ss)); } } } R.Log.I($"处理指令:{type},IP:{ip},Port:{port},Data:{data}"); FileTool.Delete(file); } } } Sleep.S(10); } }); }
/// <summary> /// 接受消息 /// </summary> /// <param name="host"></param> /// <param name="model"></param> public static void ReceiveMessage(string host, TcpDataModel model) { switch (model.Type) { case 10001000: R.TxConvert.IsAuth = true; R.TxConvert.ConnectTime = DateTime.Now; break; //状态信息 case 20001000: /* 普通应答 */ break; case 20001001: /* 状态 */ //R.MainUI.UIStatus(model); break; case 20001002: /* 状态(二维码) */ break; case 20002000: //R.MainUI.UILog(Json.Byte2Object<string>(model.Data)); break; case 20003000: //R.MainUI.UIScreen(model); break; case 20004000: /* 系统信息 */ //R.MainUI.UIInfo(model); break; case 20004001: /* 软件信息 */ //R.MainUI.UIInfo(model); break; case 20004002: /* 硬件信息 */ //R.MainUI.UIInfo(model); break; case 20004003: /* 共享信息 */ //R.MainUI.UIInfo(model); break; case 20004004: /* APP信息 */ //R.MainUI.UIInfo(model); break; case 30001000: //R.MainUI.UIConsole(Json.Byte2Object<List<string>>(model.Data)); break; //指令操作 case 40001000: /* 清除过期日志 */ try { string ss = Json.Byte2Object <string>(model.Data); Tuple <string> info = Json.String2Object <Tuple <string> >(ss); List <string> next_hosts = TxHostMapTool.GetHost(info.Item1); if (Ls.Ok(next_hosts)) { foreach (var next in next_hosts) { R.Tx.TcppServer.Write(next, 40001000, Json.Object2Byte(ss)); } } } catch { } break; case 40002000: /* 重启服务 */ try { string ss = Json.Byte2Object <string>(model.Data); Tuple <string, int> info = Json.String2Object <Tuple <string, int> >(ss); List <string> next_hosts = TxHostMapTool.GetHost(info.Item1); if (Ls.Ok(next_hosts)) { foreach (var next in next_hosts) { R.Tx.TcppServer.Write(next, 40002000, Json.Object2Byte(ss)); } } } catch { } break; default: break; } }