public Program(string ip, int port, string deviceId, int interval, int sendCountByOneDevice, ProcessCounter processCounter) { // TODO: Complete member initialization this.latlonBuilder = new LatlonBuilder(initLat, initLon, 31.802893, 39.300299, 104.941406, 117.861328); this.ip = ip; this.port = port; this.deviceId = deviceId; this.interval = interval; this.sendCountByOneDevice = sendCountByOneDevice; this.processCounter = processCounter; }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //var headpack = new Gps.Plugin.Tcp.GT808.HeadPack(); //byte[] packBytes = stringtobytes("7E-01-02-00-0E-00-20-47-05-52-32-00-00-32-30-31-32-30-31-31-39-30-38-31-30-34-37-0D-7E"); //if (RawFormatter.Instance.Bytes2Struct(headpack, packBytes , 1, HeadPack.PackSize)) //{ // Console.WriteLine("OK"); // Console.ReadKey(); //} //MessageContext pack = new MessageContext(); //byte[] packBytes = stringtobytes("68-68-25-00-00-00-00-00-00-00-12-34-56-00-18-10-DC-01-13-13-06-17-04-14-11-DC-0C-4A-7F-5C-1A-00-00-00-00-00-00-00-00-00-0A-0D"); //if (RawFormatter.Instance.Bytes2Struct(pack, packBytes, BodyData.PackSize, MessageContext.PackSize)) //{ // Console.WriteLine("OK"); // Console.ReadKey(); //} sendLogPrint = Convert.ToBoolean(ConfigurationManager.AppSettings["sendLogPrint"]); waitReceive = Convert.ToBoolean(ConfigurationManager.AppSettings["waitReceive"]); receiveLogPrint = Convert.ToBoolean(ConfigurationManager.AppSettings["receiveLogPrint"]); string ip = ""; int port = 0; while (port == 0 || string.IsNullOrEmpty(ip)) { string line = ""; string configValue = ConfigurationManager.AppSettings["remoteServerPort"]; if (string.IsNullOrEmpty(configValue)) { Console.Write("请输入服务器IP和端口(113.31.92.200:8201):"); line = Console.ReadLine(); } else { line = configValue; } if (string.IsNullOrEmpty(line)) { line = "113.31.92.200:8201"; } int pos = line.IndexOf(':'); if (pos == -1) { Console.WriteLine("正确格式:xx.xxx.xxx.xxx:xxxx"); continue; } ip = line.Substring(0, pos); string strPort = line.Substring(pos + 1); int.TryParse(strPort, out port); } int min = 0, max = 0; string deviceIdRangeValue = ConfigurationManager.AppSettings["deviceIdRange"]; if (string.IsNullOrEmpty(deviceIdRangeValue)) { Console.WriteLine("生成设备标识格式为:0000000000000000,0000000000000001...."); Console.Write("依客户端网络情况输入要模拟的客户端数量(1-10000):"); string strCount = Console.ReadLine(); max = int.Parse(strCount); } else { string[] items = deviceIdRangeValue.Split('-'); min = int.Parse(items[0]); max = int.Parse(items[1]); } int interval = 30; string strInterval = ConfigurationManager.AppSettings["interval"]; if (string.IsNullOrEmpty(strInterval)) { Console.Write("每个消息间隔(秒):"); strInterval = Console.ReadLine(); interval = int.Parse(strInterval); } else { interval = int.Parse(strInterval); } int sendCountByOneDevice = 30; string strSendCountByOneDevice = ConfigurationManager.AppSettings["sendCountByOneDevice"]; if (string.IsNullOrEmpty(strSendCountByOneDevice)) { Console.Write("每个设备发送共多少个包后断开连接:"); strSendCountByOneDevice = Console.ReadLine(); sendCountByOneDevice = int.Parse(strSendCountByOneDevice); } else { sendCountByOneDevice = int.Parse(strSendCountByOneDevice); } ProcessCounter processCounter = new ProcessCounter((max - min + 1) * sendCountByOneDevice, pc => { Console.Title = pc.ToString(); }); for (int i = min; i <= max; ++i) { string deviceId = string.Concat("010000", i.ToString("00000")); Program p = new Program(ip, port, deviceId, interval, sendCountByOneDevice, processCounter); //p.Run(); Thread iThred = new Thread(p.Run); iThred.Start(); //Thread.SpinWait(2); } Console.ReadLine(); }