private void _onRcvXmlMatchInfoResponse(int judgeNum) { JudgePanelInfo judgePanel = _JudgePanelList[judgeNum - 1]; judgePanel._lastSendMatchTickCnt = 0; _callback.callbackJudgePanelStatusChange(judgeNum); }
//由NeedMatchInfo来控制给几个选手同时打分,数据库内容决定给每个选手打几个分,分别是由哪几个裁判来打 //如果MatchSerial为空,表示不允许裁判打分,将不获取MatchInfo,发送空数据给裁判台 public bool setMatchInfo(string MatchSerial, string matchDesc1, string matchDesc2, string matchDesc3) { if (MatchSerial == null || matchDesc1 == null || matchDesc2 == null || matchDesc3 == null) { Debug.Assert(false); return(false); } // 1.记录下最新的比赛信息 _matchInfoSerial = MatchSerial; _matchInfoDesc1 = matchDesc1; _matchInfoDesc2 = matchDesc2; _matchInfoDesc3 = matchDesc3; // 2.从上层获取所有Judge的MatchInfo DataTable tblMatchInfo = null; if (_matchInfoSerial != "") { tblMatchInfo = _callback.callbackNeedMatchInfoForJudge(); if (tblMatchInfo == null) { _outputMsg("RefreshMatchInfo failed! raison:get matchInfo failed", EmMsgType.Debug); return(false); } } // 3.循环所有裁判,发送MatchInfo bool sendResult = true; for (int cycJudge = 1; cycJudge <= _JudgePanelList.Length; cycJudge++) { JudgePanelInfo judgePanel = _JudgePanelList[cycJudge - 1]; //如果裁判台状态不可以接受 if (!judgePanel.CanBeSendMatchInfo) { continue; } //是否发空, MatchInfo中筛选中此Judge的 DataRow[] rowsCurJudge = null; if (_matchInfoSerial != "") { rowsCurJudge = tblMatchInfo.Select("F_JudgeNum = " + cycJudge.ToString()); } //发送到此Judge sendResult &= _sendMatchInfoToJudge(cycJudge, rowsCurJudge); } return(sendResult); }
/// 通知上层某个裁判台状态有变化 /// 在新设备登录时, 某个设备电量有变化时, 向其发送MatchInfo, 收到MatchInfoResponse时 public bool callbackJudgePanelStatusChange(int judgeNum) { if (this.InvokeRequired) { this.Invoke((MethodInvoker) delegate { callbackJudgePanelStatusChange(judgeNum); }); return(true); } JudgePanelInfo judgePanel = m_judgeMgr.judgePanelInfo()[judgeNum - 1]; string strJudgeStatus = string.Format("状态:{0},回复:{1},电量:{2}", judgePanel.HeartbeatStatus.ToString(), judgePanel.WaitResponseStatus.ToString(), judgePanel._batteryPercent); return(updatedgvJudgeStatus(judgeNum, strJudgeStatus)); }
///默认刷新所有裁判台信息 public bool refreshJudgeCtrl(int judgeNum = -1) { if (judgeNum == 0 || judgeNum < -1 || judgeNum > m_strArrJugdes.Length) { Debug.Assert(false); return(false); } JudgePanelInfo[] lstjudgePanelInfo = m_judgeMgr.judgePanelInfo(); Debug.Assert(m_strArrJugdes.Length == lstjudgePanelInfo.Length); for (int cycJudge = 1; cycJudge <= lstjudgePanelInfo.Length; cycJudge++) { if (judgeNum >= 1) //如果参数指定只修改一个值,就只修改一个控件的值 { cycJudge = judgeNum; } { //CtrlJudge ctrlJudge = _lstCtrlJudge[cycJudge - 1]; //JudgePanelInfo judgeInfo = lstjudgePanelInfo[cycJudge - 1]; //ctrlJudge.JudgeDesc = judgeInfo._judgeDesc; //ctrlJudge.TimeoutStatus = (int)judgeInfo.HeartbeatStatus; //ctrlJudge.WaitResponseStatus = (int)judgeInfo.WaitResponseStatus; //ctrlJudge.BatteryPercent = judgeInfo._batteryPercent; //ctrlJudge.ToolTip = judgeInfo.Desc; JudgePanelInfo judgePanel = m_judgeMgr.judgePanelInfo()[cycJudge - 1]; //string strJudgeStatus = string.Format("状态:{0},回复:{1},电量:{2}", string strJudgeStatus = string.Format("状态:{0},电量:{2}", judgePanel.HeartbeatStatus.ToString(), judgePanel.WaitResponseStatus.ToString(), judgePanel._batteryPercent); updatedgvJudgeStatus(cycJudge, strJudgeStatus); } if (judgeNum >= 1) { break; } } return(true); }
//add by huang //手动发送MatchInfo到某个选定的register和选定的Judge public bool reSendMatchInfoToSelected(string MatchSerial, string matchDesc1, string matchDesc2, string matchDesc3, int judgeNum) { // 1.记录下最新的比赛信息 _matchInfoSerial = MatchSerial; _matchInfoDesc1 = matchDesc1; _matchInfoDesc2 = matchDesc2; _matchInfoDesc3 = matchDesc3; if (judgeNum < 1 || judgeNum > _JudgePanelList.Length) { Debug.Assert(false); return(false); } // 1.此裁判台当前状态,不能接受 JudgePanelInfo judgePanel = _JudgePanelList[judgeNum - 1]; if (!judgePanel.CanBeSendMatchInfo) { return(false); } // 2.如果不是空的情况,才去获取比分 DataRow[] rowsCurJudge = null; if (_matchInfoSerial != "") { // 2.从上层获取所有Judge的MatchInfo DataTable tblMatchInfo = _callback.callbackNeedMatchInfoForJudge(judgeNum); if (tblMatchInfo == null) { _outputMsg("reSendMatchInfo failed! raison:get matchInfo failed", EmMsgType.Debug); return(false); } //从MatchInfo中筛选中此Judge的 rowsCurJudge = tblMatchInfo.Select("F_JudgeNum = " + judgeNum.ToString()); } // 3.发送到此Judge bool result = _sendMatchInfoToJudge(judgeNum, rowsCurJudge); return(result); }
/// <summary> /// /// </summary> /// <param name="callback"></param> /// <param name="judgeDesc">裁判的标题,同时也决定了裁判的个数</param> /// <param name="timeout"></param> /// <param name="lowestJudgePanelVersion"></param> public JudgePanelMgr(JudgePanelMgrCallBack callback, string[] lstJudgeDesc, double lowestJudgePanelVersion = 1.00) { if (callback == null || !(callback is JudgePanelMgrCallBack) || lstJudgeDesc == null || lstJudgeDesc.Length < 1 || lstJudgeDesc.Length > MAX_JUDGE_INDEX || lowestJudgePanelVersion < 1.00) { throw new Exception("Param error"); } _callback = callback; _lowestJudgePanelVersion = lowestJudgePanelVersion; _JudgePanelList = new JudgePanelInfo[lstJudgeDesc.Length]; for (int cycJudge = 0; cycJudge < _JudgePanelList.Length; cycJudge++) { _JudgePanelList[cycJudge] = new JudgePanelInfo(); _JudgePanelList[cycJudge]._judgeDesc = lstJudgeDesc[cycJudge]; } }
private void _onRcvXmlHeartbeat(int judgeNum, XmlDocument xml, IPEndPoint ip) { // 1.尝试获取XML中属性值 string strVersion = null; int nBattery = 0; int nPort = 0; try { XmlElement elmHeartbeat = (XmlElement)xml.SelectSingleNode("/Body/HeartBeat"); strVersion = elmHeartbeat.GetAttribute("Version"); nBattery = Str2Int(elmHeartbeat.GetAttribute("Battery")); nPort = Str2Int(elmHeartbeat.GetAttribute("RcvPort")); } catch (Exception e) { _outputMsg("Rcv Heartbeat, but analyse failed.", EmMsgType.Error); return; } if (nPort <= 0) { string err = string.Format("Rcv heartbeat but the rcvPort in JudgePanel{0}({1}) is invalid.", judgeNum, ip.Address.ToString()); _outputMsg(err, EmMsgType.Error); return; } // 3. 此Panel未登录过或登录过已超时,更新此客户端状态,向其发送MatchInfo,并报告其状态改变 // 已登录过且未超时,更新其TickCount即可 JudgePanelInfo judgePanelInfo = _JudgePanelList[judgeNum - 1]; if (judgePanelInfo._ip != null && judgePanelInfo._ip.Address.ToString() == ip.Address.ToString() && judgePanelInfo._ip.Port == nPort) //IP Port是否一样,判断该Panel是否已经登录过 { if (Environment.TickCount - judgePanelInfo._lastRcvTimeoutTickCnt > JudgePanelInfo.TIMEOUT_HEARTBEAT) //超时恢复 { judgePanelInfo._batteryPercent = nBattery; judgePanelInfo._lastRcvTimeoutTickCnt = Environment.TickCount; reSendMatchInfo(judgeNum); //由于reSendMatchInfo时会自动向上层发送StatusChanged,所以这里不再发送 //_callback.callbackJudgePanelStatusChange(judgeNum); _outputMsg("Judge" + judgeNum.ToString() + " who was timeout coming in!", EmMsgType.Important); } else //接收Heartbeat正常 { judgePanelInfo._lastRcvTimeoutTickCnt = Environment.TickCount; if (judgePanelInfo._batteryPercent != nBattery) { judgePanelInfo._batteryPercent = nBattery; //电池电量有变化,需要向上层发送变化信息 _callback.callbackJudgePanelStatusChange(judgeNum); } } } else // 新客户端 向其发送MatchInfo 并通知上层有变化 { judgePanelInfo._ip = new IPEndPoint(ip.Address, nPort); judgePanelInfo._version = strVersion; judgePanelInfo._batteryPercent = nBattery; judgePanelInfo._lastRcvTimeoutTickCnt = Environment.TickCount; reSendMatchInfo(judgeNum); //由于reSendMatchInfo时会自动向上层发送StatusChanged,所以这里不再发送 //_callback.callbackJudgePanelStatusChange(judgeNum); _outputMsg("Judge" + judgeNum.ToString() + "[" + judgePanelInfo._ip.ToString() + "]" + " coming in!", EmMsgType.Important); } }