using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Threading; using Sog; using SimpleHttpServer; using MySql.Data.MySqlClient; using LitJson; using Newtonsoft.Json.Serialization; namespace SMWebServer { public class Q_TheServers { } public class S_TheServers { public int code { get; set; } public List<_TheServers_data> data { get; set; } public string msg { get; set; } } public class _TheServers_data { public string id { get; set; } public string state { get; set; } public string memory { get; set; } public string name { get; set; } public string CfgPath { get; set; } public string WorkPath { get; set; } } public class TheServers { private MySqlDB db; public static string OnPassHttpRes(string Message) { List<_TheServers_data> theServers_Datas = new List<_TheServers_data>(); var _list = Message.Split('\n', StringSplitOptions.None).ToArray(); foreach (var str in _list) { //头部跳过 if (str.Contains("--------------- HostName")) { Console.WriteLine(str); continue; } var data = str.Split('\t'); if (data.Length == 6) { theServers_Datas.Add(new _TheServers_data() { id = data[0], state = data[1], memory = data[2], name = data[3], CfgPath = data[4], WorkPath = data[5] }); } } S_TheServers s_The = new S_TheServers(); s_The.code = 20000; s_The.data = theServers_Datas; return s_The.ToJsonstr(); } public void InitConnection() { SMWebServerConfig config = SMWebServerUtils.GetServerConfig();//配置 db = new MySqlDB(config.dbname, config.dbip, config.dbuser, config.dbpassword); } private void DoSelect(Q_TheServers q, S_TheServers s, TokenInfo tokeninfo, HttpContext httpContext) { httpContext.httpResponse.IsWaitFor = true; Msg.Send("list *", httpContext.id); } public void ProccessRequest(Q_TheServers q, S_TheServers s, TokenInfo tokeninfo, HttpContext httpContext) { InitConnection();//初始化链接 DoSelect(q, s, tokeninfo, httpContext); db.Dispose(); return; } } }