/// <summary> /// 带事务的Update /// </summary> /// <param name="entity"></param> /// <param name="trans">The trans.</param> /// <returns></returns> /// <remarks>2016-08-15 11:14:40</remarks> public bool Update(CrosscrowdPairrecordEntity entity, DbTransaction trans) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_CrosscrowdPairrecord_Update"); database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx); database.AddInParameter(commandWrapper, "@CrossCrowdId", DbType.Int32, entity.CrossCrowdId); database.AddInParameter(commandWrapper, "@PairIndex", DbType.Int32, entity.PairIndex); database.AddInParameter(commandWrapper, "@PlayerCount", DbType.Int32, entity.PlayerCount); database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime); int results = 0; if (trans != null) { results = database.ExecuteNonQuery(commandWrapper, trans); } else { results = database.ExecuteNonQuery(commandWrapper); } entity.Idx = (System.Int32)database.GetParameterValue(commandWrapper, "@Idx"); return(Convert.ToBoolean(results)); }
void RunPair() { try { if (CompetitorDic.Count < 2) { return; } _needClearFightDic = false; _status = EnumLadderStatus.Grouping; CrosscrowdPairrecordEntity pairRecord = GetCompetitorToMatch(); var playerNumber = pairRecord.FightList.Count; if (playerNumber % 2 != 0)//检查玩家数量是否是2的倍数 { //将天梯赛服务状态置为结束 _status = EnumLadderStatus.End; //将上一轮比赛的经理池清空,暂时没有异常回退方案 ManagerFightDic = new Dictionary <Guid, CrowdHeartEntity>(); SystemlogMgr.Info("CrowdThread", "The player is " + playerNumber + " not multiple of 2"); return; } //开始分组 var matchDic = new Dictionary <Guid, CrosscrowdMatchEntity>(); Grouping(pairRecord, matchDic); RunPairAfter(); _nbThreadPool.Add(() => RunMatch(matchDic, pairRecord)); } catch (Exception ex) { SystemlogMgr.Error("CrossCrowd-RunPair", ex); } }
public CrossCrowdProcess(Dictionary <Guid, CrosscrowdMatchEntity> matchDic, CrosscrowdPairrecordEntity pairRecord, int crowdResurrectionCd, int crowdCd, CrossCrowdThread.ClearFightDicDelegate clearDelegate, int domainId) { _domainId = domainId; _matchDic = matchDic; _pairRecord = pairRecord; _managerDic = pairRecord.FightList.ToDictionary(d => d.ManagerId, d => d); _crowdResurrectionCd = crowdResurrectionCd; _crowdCd = crowdCd; _clearFightDicDelegate = clearDelegate; _coinChargeSourceType = (int)EnumCoinChargeSourceType.CrossCrowd; }
/// <summary> /// 将IDataReader的当前记录读取到CrosscrowdPairrecordEntity 对象 /// </summary> /// <param name="reader"></param> /// <returns></returns> public CrosscrowdPairrecordEntity LoadSingleRow(IDataReader reader) { var obj = new CrosscrowdPairrecordEntity(); obj.Idx = (System.Int32)reader["Idx"]; obj.CrossCrowdId = (System.Int32)reader["CrossCrowdId"]; obj.PairIndex = (System.Int32)reader["PairIndex"]; obj.PlayerCount = (System.Int32)reader["PlayerCount"]; obj.RowTime = (System.DateTime)reader["RowTime"]; return(obj); }
/// <summary> /// GetById /// </summary> /// <param name="idx">idx</param> /// <returns>CrosscrowdPairrecordEntity</returns> /// <remarks>2016-08-15 11:14:39</remarks> public CrosscrowdPairrecordEntity GetById(System.Int32 idx) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("P_CrosscrowdPairrecord_GetById"); database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, idx); CrosscrowdPairrecordEntity obj = null; using (IDataReader reader = database.ExecuteReader(commandWrapper)) { if (reader.Read()) { obj = LoadSingleRow(reader); } } return(obj); }
void Grouping(CrosscrowdPairrecordEntity pairRecord, Dictionary <Guid, CrosscrowdMatchEntity> matchDic) { var managerFightList = pairRecord.FightList; var totalCount = managerFightList.Count; int totalLoopCount = totalCount; int index = 0; while (totalCount > 1 && totalLoopCount > 0) { var template = GetGroupTemplate(totalCount); var loopCount = template.Length; for (int i = 0; i < loopCount; i = i + 2) { BuildFightInfo(pairRecord.CrossCrowdId, pairRecord.PairIndex, managerFightList, index, i, template, matchDic); } index = index + template.Length; totalCount = totalCount - template.Length; totalLoopCount--; } }
CrosscrowdPairrecordEntity GetCompetitorToMatch() { var crowdPair = new CrosscrowdPairrecordEntity(); lock (_competitorLock) { var totalCount = CompetitorDic.Count; var playerCount = totalCount; if (totalCount % 2 == 1) { playerCount = totalCount - 1; } var fightList = new List <CrosscrowdManagerEntity>(playerCount); ManagerFightDic = new Dictionary <Guid, CrowdHeartEntity>(playerCount); int i = 0; CrosscrowdManagerEntity outManager = null; foreach (var dic in CompetitorDic) { i++; if (i <= playerCount) { //将经理推进比赛池 ManagerFightDic.Add(dic.Key, null); fightList.Add(dic.Value); } else if (i == totalCount) { outManager = dic.Value; } } _crowdInfo.PairCount++; crowdPair.FightList = fightList; crowdPair.PairIndex = _crowdInfo.PairCount; crowdPair.PlayerCount = playerCount; crowdPair.CrossCrowdId = _crowdInfo.Idx; PairReady(outManager); } return(crowdPair); }
/// <summary> /// Runs the arena match. /// </summary> void RunMatch() { if (_matchDic == null) { return; } try { Status = EnumLadderStatus.Running; foreach (var item in _matchDic.Values) { var matchHome = new MatchManagerInfo(item.HomeId, item.HomeSiteId); var matchAway = new MatchManagerInfo(item.AwayId, item.AwaySiteId); var matchData = new BaseMatchData((int)EnumMatchType.CrossCrowd, item.Idx, matchHome, matchAway); matchData.ErrorCode = (int)MessageCode.MatchWait; MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData); Fight(matchData, item); } _matchDic = null; _pairRecord.RowTime = DateTime.Now; CrosscrowdPairrecordMgr.Insert(_pairRecord); _pairRecord = null; } catch (Exception ex) { SystemlogMgr.Error("CrossCrowdProcess-RunMatch", ex); } finally { Status = EnumLadderStatus.End; if (_clearFightDicDelegate != null) { _clearFightDicDelegate(); } } }
public static bool Update(CrosscrowdPairrecordEntity crosscrowdPairrecordEntity, DbTransaction trans = null, string zoneId = "") { var provider = new CrosscrowdPairrecordProvider(zoneId); return(provider.Update(crosscrowdPairrecordEntity, trans)); }
void RunMatch(Dictionary <Guid, CrosscrowdMatchEntity> matchDic, CrosscrowdPairrecordEntity pairRecord) { _crowdProcess = new CrossCrowdProcess(matchDic, pairRecord, _crowdResurrectionCd, _crowdCd, doClearFightDic, _domainId); _crowdProcess.StartProcess(); }
/// <summary> /// Update /// </summary> /// <param name="entity"></param> /// <returns></returns> /// <remarks>2016-08-15 11:14:40</remarks> public bool Update(CrosscrowdPairrecordEntity entity) { return(Update(entity, null)); }
/// <summary> /// Insert /// </summary> /// <param name="entity"></param> /// <param name="trans">The trans.</param> /// <returns></returns> /// <remarks>2016-08-15 11:14:39</remarks> public bool Insert(CrosscrowdPairrecordEntity entity) { return(Insert(entity, null)); }