public async Task <ConcurrentBag <APIAgent> > GetAgents(Guid tenantID) { var request = new RestRequest("bc/api/resource_manager/v1/agents", Method.GET); var response = await _client.ExecuteAsync(request); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception($"Error - Received HTTP {response.StatusCode}:{response.StatusDescription}. Response content: {response.Content}"); } JObject responseJson = JObject.Parse(response.Content); var agentBag = new ConcurrentBag <APIAgent>(); foreach (JToken item in responseJson.SelectToken("items")) { var apiAgentItem = new APIAgent(); apiAgentItem.AgentID = new Guid(item.Value <string>("id")); apiAgentItem.AgentVersion = item.SelectToken("details").Value <string>("version") ?? string.Empty; apiAgentItem.AvailableUpdateVersion = item.SelectToken("updateState").Value <string>("version") ?? string.Empty; apiAgentItem.Hostname = item.Value <string>("name") ?? string.Empty; apiAgentItem.Online = item.SelectToken("communication").Value <bool>("online"); apiAgentItem.OS = item.SelectToken("details").SelectToken("os").Value <string>("name") ?? string.Empty; apiAgentItem.TenantID = tenantID; apiAgentItem.UpdateAvailable = string.IsNullOrEmpty(item.SelectToken("updateState").Value <string>("status")) ? false : item.SelectToken("updateState").Value <string>("status").Equals("available"); agentBag.Add(apiAgentItem); } return(agentBag); }
public ContentResult GetBalance() { BalanceResult result = APIAgent.Instance().GetBalance(this.SiteInfo, this.GameInfo, this.UserInfo); return(new ContentResult() { ContentType = "application/json", StatusCode = 200, Content = result.ToString() }); }
public ContentResult QueryTransfer([FromForm] string orderID) { QueryTransferResult result = APIAgent.Instance().QueryTransfer(this.SiteInfo, this.GameInfo, orderID); return(new ContentResult() { ContentType = "application/json", StatusCode = 200, Content = result.ToString() }); }
public ContentResult Transfer([FromForm] TransferAction action, [FromForm] string orderId, [FromForm] decimal money) { TransferResult result = APIAgent.Instance().Transfer(this.SiteInfo, this.GameInfo, this.UserInfo, action, orderId, money); return(new ContentResult() { ContentType = "application/json", StatusCode = 200, Content = result.ToString() }); }
public ContentResult Guest([FromForm] GameCategory?category, [FromForm] string code) { LoginResult result = APIAgent.Instance().Guest(this.GameInfo, category, code); return(new ContentResult() { ContentType = "application/json", StatusCode = 200, Content = result.ToString() }); }
public override void OnActionExecuting(ActionExecutingContext context) { MethodInfo method = (context.ActionDescriptor as ControllerActionDescriptor).MethodInfo; // 如果带有游客标记则不需要做验证判断 if (method.HasAttribute <GuestAttribute>()) { return; } //#1 从Http头中得到商户信息 bool isSite = context.HttpContext.GetAuth(out string merchant, out string secretKey); if (!isSite) { context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString()); return; } int siteId = merchant.GetValue <int>(); Site site = SiteAgent.Instance().GetSiteInfo(siteId); if (site == null || site.SecretKey != secretKey) { context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString()); return; } //#2 固定参数判断(自动在游戏中创建账户) string gameCode = context.HttpContext.Request.Form["GameCode"]; string userName = context.HttpContext.Request.Form["UserName"]; if (!string.IsNullOrEmpty(gameCode)) { GameSetting game = GameAgent.Instance().GetGameSetting(gameCode); if (game == null) { context.Result = (ContentResult) new Result(false, ResultStatus.NoGame.ToString()); return; } if (!string.IsNullOrEmpty(userName)) { ResultStatus registerStatus = APIAgent.Instance().Register(siteId, userName, game, out UserGame user); if (registerStatus != ResultStatus.Success) { context.Result = (ContentResult) new Result(false, registerStatus.ToString()); return; } context.HttpContext.SetItem(user); } context.HttpContext.SetItem(game); } context.HttpContext.SetItem(site); }