static void Main(string[] args) { init(); Console.WriteLine("----------------------------"); Console.WriteLine("MachineName:\t" + SystemUtil.MACHINE_NAME); Console.WriteLine("Address:\t" + SystemUtil.MAC_ADDRESS.First()); Console.WriteLine("SystemUser:\t" + SystemUtil.SYS_USER); Console.WriteLine("----------------------------\n"); //start proxy new ProxyServer().start(); //init wind api WindUtil.getAPI(); }
private void handleTheRequest(Socket client) { byte[] buffer = new byte[10240]; // 10 kb, just in case int receivedCount = client.Receive(buffer); // Receive the request string strReceived = Encoding.UTF8.GetString(buffer, 0, receivedCount); // Parse method of the request string httpMethod = strReceived.Substring(0, strReceived.IndexOf(" ")); int start = strReceived.IndexOf(httpMethod) + httpMethod.Length + 1; int length = strReceived.LastIndexOf("HTTP") - start - 1; string url = strReceived.Substring(start, length); url = url.Replace("//", "/").Replace("//", "/"); NameValueCollection param = ParseUrl(url); log.Debug(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " \n -----------------------\n" + url); WindData wd = null; if (param != null && param.Count > 0) { string codes = param.Get("codes"); string startTime = param.Get("startTime"); string endTime = param.Get("endTime"); string options = param.Get("options"); string fields = param.Get("fields"); string reportName = param.Get("reportName"); if (startTime == null) { startTime = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd"); } if (endTime == null) { endTime = DateTime.Now.ToString("yyyy-MM-dd"); } if (options == null) { options = ""; } if (url.ToLower().StartsWith(RUL_EDB)) { wd = WindUtil.getAPI().edb(codes, startTime, endTime, options); } else if (url.ToLower().StartsWith(RUL_WSD)) { wd = WindUtil.getAPI().wsd(codes, fields, startTime, endTime, options); } else if (url.ToLower().StartsWith(RUL_WSET)) { wd = WindUtil.getAPI().wset(reportName, options); } else if (url.ToLower().StartsWith(RUL_WSS)) { wd = WindUtil.getAPI().wss(codes, fields, options); } } if (wd != null) { sendJson(client, JsonConvert.SerializeObject(wd)); } else { sendJson(client, "{ errorCode : " + 500 + " }"); } }