/// <summary> /// 启动机器人 /// </summary> /// <param name="siteId"></param> /// <param name="managerId"></param> /// <returns></returns> public RobotResponse StartRobot(string siteId, Guid managerId) { var manager = ManagerCore.Instance.GetManager(managerId, false, siteId); if (manager == null) { return(ResponseHelper.Create <RobotResponse>(MessageCode.MissManager)); } if (manager.Level < RobotLevel) { return(ResponseHelper.Create <RobotResponse>(MessageCode.LackofManagerLevel)); } if (!CheckManagerVip(manager)) { return(ResponseHelper.Create <RobotResponse>(MessageCode.LackofVipLevel)); } var crossRobotManager = CrossrobotManagerMgr.GetById(managerId); if (crossRobotManager == null) { crossRobotManager = RobotCore.BuildCrossRobotManager(siteId, managerId); SetHookStatus(crossRobotManager, true); if (!CrossrobotManagerMgr.Insert(crossRobotManager)) { return(ResponseHelper.Create <RobotResponse>(MessageCode.FailUpdate)); } } else { if (!GetHookStatus(crossRobotManager)) { SetHookStatus(crossRobotManager, true); if (!CrossrobotManagerMgr.Update(crossRobotManager)) { return(ResponseHelper.Create <RobotResponse>(MessageCode.FailUpdate)); } } } if (!_crossRobotManagerDic.ContainsKey(managerId)) { _crossRobotManagerDic.TryAdd(managerId, crossRobotManager); } var response = ResponseHelper.CreateSuccess <RobotResponse>(); return(RobotCore.BuildRobotResponse(response, crossRobotManager)); }
MessageCode StopCrossRobotManager(Guid managerId, out CrossrobotManagerEntity entity) { entity = CrossrobotManagerMgr.GetById(managerId); if (entity == null || !GetHookStatus(entity)) { return(MessageCode.InvalidArgs); } SetHookStatus(entity, false); entity.Status = (int)EnumRobotMatchStatus.Stop; LogHelper.Insert("test", LogType.Info); if (!CrossrobotManagerMgr.Update(entity)) { return(MessageCode.FailUpdate); } LogHelper.Insert("test2", LogType.Info); CrossrobotManagerEntity newEntity = null; _crossRobotManagerDic.TryRemove(managerId, out newEntity); return(MessageCode.Success); }
public RobotResponse RobotInfo(string siteId, Guid managerId) { var manager = ManagerCore.Instance.GetManager(managerId, false, siteId); if (manager == null) { return(ResponseHelper.Create <RobotResponse>(MessageCode.MissManager)); } var crossRobotManager = CrossrobotManagerMgr.GetById(managerId); if (crossRobotManager == null) { crossRobotManager = BuildCrossRobotManager(siteId, managerId); if (!CrossrobotManagerMgr.Insert(crossRobotManager)) { return(ResponseHelper.Create <RobotResponse>(MessageCode.FailUpdate)); } } var response = ResponseHelper.CreateSuccess <RobotResponse>(); return(BuildRobotResponse(response, crossRobotManager)); }