/// <summary> /// 带事务的Update /// </summary> /// <param name="entity"></param> /// <param name="trans">The trans.</param> /// <returns></returns> /// <remarks>2016-09-14 15:52:48</remarks> public bool Update(CrossladderHookEntity entity, DbTransaction trans) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_CrossladderHook_Update"); database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId); database.AddInParameter(commandWrapper, "@SiteId", DbType.AnsiString, entity.SiteId); database.AddInParameter(commandWrapper, "@CurTimes", DbType.Int32, entity.CurTimes); database.AddInParameter(commandWrapper, "@CurWiningTimes", DbType.Int32, entity.CurWiningTimes); database.AddInParameter(commandWrapper, "@MaxTimes", DbType.Int32, entity.MaxTimes); database.AddInParameter(commandWrapper, "@MinScore", DbType.Int32, entity.MinScore); database.AddInParameter(commandWrapper, "@MaxScore", DbType.Int32, entity.MaxScore); database.AddInParameter(commandWrapper, "@MaxWiningTimes", DbType.Int32, entity.MaxWiningTimes); database.AddInParameter(commandWrapper, "@NextMatchTime", DbType.DateTime, entity.NextMatchTime); database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status); database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime); database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime); database.AddInParameter(commandWrapper, "@Expired", DbType.DateTime, entity.Expired); int results = 0; if (trans != null) { results = database.ExecuteNonQuery(commandWrapper, trans); } else { results = database.ExecuteNonQuery(commandWrapper); } entity.ManagerId = (System.Guid)database.GetParameterValue(commandWrapper, "@ManagerId"); return(Convert.ToBoolean(results)); }
public MessageCode HookAttend(CrossladderHookEntity entity) { if (!IsManagerBusy(entity.ManagerId)) { if (!CompetitorDic.ContainsKey(entity.ManagerId)) { entity.LadderManager.UpdateTime = DateTime.Now; //锁住 lock (_competitorLock) { if (_playerNum == 0) { _startTime = DateTime.Now; } CompetitorDic.Add(entity.ManagerId, entity.LadderManager); _playerNum++; } } return(MessageCode.Success); } else { return(MessageCode.LadderBusy); } }
bool AddToDic(CrossladderHookEntity entity) { var response = CrossLadderCore.Instance.GetLadderManager(entity.SiteId, entity.ManagerId); if (response.Code != (int)MessageCode.Success) { return(false); } var arenaManager = response.Data; if (arenaManager == null) { return(false); } arenaManager.IsBot = false; arenaManager.UpdateTime = DateTime.Now; arenaManager.IsHook = true; entity.Score = arenaManager.Score; entity.Status = (int)EnumHookStatus.Run; entity.LadderManager = arenaManager; if (_hookDic.ContainsKey(entity.ManagerId)) { _hookDic[entity.ManagerId] = entity; } else { _hookDic.TryAdd(entity.ManagerId, entity); } return(true); }
public LadderHookInfoResponse GetHookInfoResponse(Guid managerId) { CrossladderHookEntity hook = null; _hookDic.TryGetValue(managerId, out hook); return(GetHookInfoResponse(managerId, hook, true)); }
bool HookEnd(Guid managerId, int hookStatus) { if (CrossladderHookMgr.End(managerId, hookStatus)) { var e = new CrossladderHookEntity(); _hookDic.TryRemove(managerId, out e); return(true); } return(false); }
public LadderHookInfoResponse GetHookInfoResponse(Guid managerId, CrossladderHookEntity hook, bool isHook = false) { if (hook != null) { if (hook.Status >= (int)EnumHookStatus.Run) { return(BuildHookInfoResponse(hook, isHook)); } } var response = ResponseHelper.CreateSuccess <LadderHookInfoResponse>(); response.Data = new LadderHookInfoEntity(); return(response); }
/// <summary> /// 将IDataReader的当前记录读取到CrossladderHookEntity 对象 /// </summary> /// <param name="reader"></param> /// <returns></returns> public CrossladderHookEntity LoadSingleRow(IDataReader reader) { var obj = new CrossladderHookEntity(); obj.ManagerId = (System.Guid)reader["ManagerId"]; obj.SiteId = (System.String)reader["SiteId"]; obj.CurTimes = (System.Int32)reader["CurTimes"]; obj.CurWiningTimes = (System.Int32)reader["CurWiningTimes"]; obj.MaxTimes = (System.Int32)reader["MaxTimes"]; obj.MinScore = (System.Int32)reader["MinScore"]; obj.MaxScore = (System.Int32)reader["MaxScore"]; obj.MaxWiningTimes = (System.Int32)reader["MaxWiningTimes"]; obj.NextMatchTime = (System.DateTime)reader["NextMatchTime"]; obj.Status = (System.Int32)reader["Status"]; obj.RowTime = (System.DateTime)reader["RowTime"]; obj.UpdateTime = (System.DateTime)reader["UpdateTime"]; obj.Expired = (System.DateTime)reader["Expired"]; return(obj); }
/// <summary> /// GetById /// </summary> /// <param name="managerId">managerId</param> /// <param name="siteId">siteId</param> /// <returns>CrossladderHookEntity</returns> /// <remarks>2016-09-14 15:52:48</remarks> public CrossladderHookEntity GetById(System.Guid managerId, System.String siteId) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("C_CrossLadderHook_GetById"); database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, managerId); database.AddInParameter(commandWrapper, "@SiteId", DbType.AnsiString, siteId); CrossladderHookEntity obj = null; using (IDataReader reader = database.ExecuteReader(commandWrapper)) { if (reader.Read()) { obj = LoadSingleRow(reader); } } return(obj); }
void Hook(CrossladderHookEntity entity) { if (HookEndCheck(entity)) { _finishList.Add(entity); return; } DateTime compareTime = DateTime.Now; if (compareTime < entity.NextMatchTime) { return; } entity.NextMatchTime = compareTime.AddSeconds(_ladderHookCD); var thread = GetThread(entity.SiteId); if (thread != null) { thread.HookAttend(entity); } }
LadderHookInfoResponse BuildHookInfoResponse(CrossladderHookEntity entity, bool isHook) { var response = ResponseHelper.CreateSuccess <LadderHookInfoResponse>(); response.Data = new LadderHookInfoEntity(); response.Data.IsHook = isHook; response.Data.CurTimes = entity.CurTimes; response.Data.CurWiningTimes = entity.CurWiningTimes; response.Data.MaxScore = entity.MaxScore; response.Data.MaxTimes = entity.MaxTimes; response.Data.MinScore = entity.MinScore; response.Data.LadderHookList = new List <LadderHook>(); if (_hookListDic.ContainsKey(entity.ManagerId)) { response.Data.LadderHookList = _hookListDic[entity.ManagerId]; } var curTime = DateTime.Now; response.Data.NextMatchWaitSeconds = isHook ? ShareUtil.CalWaitTime(entity.NextMatchTime, curTime) : 0; response.Data.ExpiredTick = ShareUtil.GetTimeTick(entity.Expired); return(response); }
bool HookEndCheck(CrossladderHookEntity entity) { if (entity.Status != (int)EnumHookStatus.Run) { return(true); } if (entity.Expired <= DateTime.Now) { return(true); } int local = entity.Status; entity.Status = (int)EnumHookStatus.Finish; if (entity.MaxTimes > 0 && entity.CurTimes >= entity.MaxTimes) { return(true); } if (entity.MaxWiningTimes > 0 && entity.CurWiningTimes >= entity.MaxWiningTimes) { return(true); } if (entity.Score > 0) { if (entity.MaxScore > 0 && entity.Score >= entity.MaxScore) { return(true); } if (entity.MinScore > 0 && entity.Score <= entity.MinScore) { return(true); } } if (entity.MaxTimes < 1 && entity.MinScore < 1 && entity.MaxScore < 1 && entity.MaxWiningTimes < 1) { return(true); } entity.Status = local; return(false); }
/// <summary> /// Update /// </summary> /// <param name="entity"></param> /// <returns></returns> /// <remarks>2016-09-14 15:52:48</remarks> public bool Update(CrossladderHookEntity entity) { return(Update(entity, null)); }
/// <summary> /// Insert /// </summary> /// <param name="entity"></param> /// <param name="trans">The trans.</param> /// <returns></returns> /// <remarks>2016-09-14 15:52:48</remarks> public bool Insert(CrossladderHookEntity entity) { return(Insert(entity, null)); }
/// <summary> /// 更新挂机信息 /// </summary> /// <param name="managerId">经理ID</param> /// <param name="score">获得积分</param> /// <param name="isWin">是否胜利</param> /// <param name="homtScore">主队进球数</param> /// <param name="awayScore">客队进球数</param> /// <param name="homeName">主队名</param> /// <param name="awayName">客队名</param> /// <param name="myCoin">获得金币</param> public void UpdateHookScore(Guid managerId, int score, bool isWin, int homtScore, int awayScore, string homeName, string awayName, int myCoin) { try { CrossladderHookEntity entity = null; _hookDic.TryGetValue(managerId, out entity); if (entity != null) { if (entity.LadderManager != null) { entity.LadderManager.Score += score; entity.Score = entity.LadderManager.Score; } else { entity.Score += score; } entity.CurTimes++; if (isWin) { entity.CurWiningTimes++; } try { if (_hookListDic == null) { _hookListDic = new ConcurrentDictionary <Guid, List <LadderHook> >(); } if (!_hookListDic.ContainsKey(managerId)) { _hookListDic.TryAdd(managerId, new List <LadderHook>()); } if (_hookListDic[managerId].Count >= 10) { _hookListDic[managerId].RemoveAt(0); } LadderHook hookrecord = new LadderHook(); hookrecord.HomeName = homeName; hookrecord.AwayName = awayName; hookrecord.HomeScore = homtScore; hookrecord.AwayScore = awayScore; hookrecord.MyCoin = myCoin; hookrecord.MyIntegral = score; _hookListDic[managerId].Add(hookrecord); } catch (Exception e) { } if (HookEndCheck(entity)) { HookEnd(managerId, entity.Status); } else { CrossladderHookMgr.Update(entity); } } } catch (Exception ex) { SystemlogMgr.Error("UpdateLadderHookInfo", ex); } }
public static bool Update(CrossladderHookEntity crossladderHookEntity, DbTransaction trans = null, string zoneId = "") { var provider = new CrossladderHookProvider(zoneId); return(provider.Update(crossladderHookEntity, trans)); }