static Engine() { typeof(CommandManage).Assembly .GetTypes() .Where(t => t.GetInterfaces().Any(t2 => t2 == typeof(ICommand))) .Select(t3 => typeof(CommandManage).Assembly.CreateInstance(t3.FullName)). ToList().ForEach(c => CommandManage.Regist((ICommand)c)); }
static void Main(string[] args) { if (args.Any(a => a.ToLower() == "-log")) { var logStream = File.Open($"{DateTime.Now.ToString("yyyy-MM-dd")}.log", FileMode.OpenOrCreate); logWriter = new StreamWriter(logStream); } typeof(CommandManage).Assembly .GetTypes() .Where(t => t.GetInterfaces().Any(t2 => t2 == typeof(ICommand))) .Select(t3 => typeof(CommandManage).Assembly.CreateInstance(t3.FullName)). ToList().ForEach(c => CommandManage.Regist((ICommand)c)); ExcuteScript(args[0]); }
/// <summary> /// 当客户端连入时要发送泵类型信息, /// 如果用户尚未配置,则不用发,留到点开始的时候发 /// </summary> /// <param name="e"></param> private void SendPumpType2Wifi(SocketConnectArgs e) { Controller controller = ControllerManager.Instance().Get(e.ConnectedSocket); if (controller == null) { return; } int dockNo = controller.DockNo; AgingDock dock = m_DockList.Find((x) => { return(x.DockNo == dockNo); }); if (dock == null || dock.ChannelHashRowNo == null || !dock.ChannelHashRowNo.ContainsKey(controller.RowNo)) { return; } AgingParameter para = m_DockParameter[dockNo] as AgingParameter; if (para != null) { if (Enum.IsDefined(typeof(ProductID), para.PumpType)) { ProductID pid = (ProductID)Enum.Parse(typeof(ProductID), para.PumpType); CommandManage cmdManager = new CommandManage(); int iChannel = (int)dock.ChannelHashRowNo[controller.RowNo]; byte channel = (byte)(iChannel & 0x000000FF); //一旦收到连接,立即发送泵信息,必须要延迟10秒 cmdManager.SendPumpType(pid, (ushort)m_QueryInterval, e.ConnectedSocket, null, channel); } else { Logger.Instance().ErrorFormat("SendPumpType2Wifi()->para.PumpType is not defined! para.PumpType={0}", para.PumpType); } } else { Logger.Instance().Debug("SendPumpType2Wifi()->DefaultParameter is null"); } }
/// <summary> /// 当客户端连入时要发送泵类型信息, /// 如果用户尚未配置,则不用发,留到点开始的时候发 /// </summary> /// <param name="e"></param> private void SendPumpType2Wifi(SocketConnectArgs e) { Controller controller = ControllerManager.Instance().Get(e.ConnectedSocket); if (controller == null) { return; } int dockNo = controller.DockNo; AgingDock dock = m_DockList.Find((x) => { return(x.DockNo == dockNo); }); if (dock == null || dock.ChannelHashRowNo == null || !dock.ChannelHashRowNo.ContainsKey(controller.RowNo)) { return; } AgingParameter para = m_DockParameter[dockNo] as AgingParameter; if (para != null) { CustomProductID cid = ProductIDConvertor.Name2CustomProductID(para.PumpType); ProductID pid = ProductIDConvertor.Custom2ProductID(cid); CommandManage cmdManager = new CommandManage(); int iChannel = (int)dock.ChannelHashRowNo[controller.RowNo]; byte channel = (byte)(iChannel & 0x000000FF); //一旦收到连接,立即发送泵信息,必须要延迟10秒 if (pid == ProductID.Graseby1200En)//英文版的ID和中文的一样 { pid = ProductID.Graseby1200; } cmdManager.SendPumpType(pid, (ushort)m_QueryInterval, e.ConnectedSocket, null, channel); } else { Logger.Instance().Debug("SendPumpType2Wifi()->DefaultParameter is null"); } }
private void ReceiveData(object userState) { User user = (User)userState; TcpClient client = user.client; while (!Instance.ISExit) { string receive = string.Empty; ReceiveMessageDelegate d = new ReceiveMessageDelegate(ReceiveMessage); IAsyncResult result = d.BeginInvoke(user, out receive, null, null); //使用轮询方式来判断异步操作是否完成 while (!result.IsCompleted) { if (Instance.ISExit) { break; } Thread.Sleep(50); //Thread.Sleep(100); } //获取Begin方法的返回值和所有输入/输出参数 d.EndInvoke(out receive, result); if (receive.Length == 0 || receive == null) { if (!Instance.ISExit) { //日志 Console.WriteLine(string.Format("与{0}失去联系,已终止接收该用户信息", user.IP)); RemoveUser(user); } break; } string aswer = string.Empty; CommandManage manage = new CommandManage(); try { Console.WriteLine("接受:" + receive); aswer = manage.Proc(receive); Console.WriteLine("应答:" + aswer); } catch { manage.CloseUser = true; } //foreach (User target in Instance.UserList) //{ // if (target.IP == client.Client.RemoteEndPoint.ToString()) // { // AsyncSendToClient(target, aswer); // } //} AsyncSendToClient(user, aswer); if (manage.CloseUser) { this.RemoveUser(user); } } }