/// <summary> /// 接口访问次数加1 /// </summary> /// <param name="actionId">接口编号</param> /// <param name="aStat">访问状态</param> public static void ActionVisit(int actionId, GameStruct.LogActionStat aStat) { if (dicActionInfo == null) { if (dicActionInfo == null) { curDate = DateTime.Now.Date; dicActionInfo = new ConcurrentDictionary<int, ActionLog>(); } } if (!dicActionInfo.ContainsKey(actionId)) { ActionLog tmpLog = new ActionLog(actionId, curDate); dicActionInfo.TryAdd(actionId, tmpLog); } dicActionInfo[actionId].Visitor(aStat); if (curDate != DateTime.Now.Date) { //已经进入第二天,全部写入DB,并初始化数据 DateTime newDate = DateTime.Now.Date; foreach (KeyValuePair<int, ActionLog> item in dicActionInfo) { item.Value.InsertDB(newDate); } curDate = newDate; } }
/// <summary> /// 累加访问次数 /// </summary> /// <param name="aStat">接口访问是成功还是失败</param> public void Visitor(GameStruct.LogActionStat aStat) { if (aStat == GameStruct.LogActionStat.Sucess) { this.SucCount++; } else { this.FailCount++; } if (TotalCount >= 100) { this.InsertDB(DateTime.Now.Date); } else { if (lastDbTime.AddMinutes(5).CompareTo(DateTime.Now) <= 0) { this.InsertDB(DateTime.Now.Date); } } }