public async Task Handle(QueuedMatchResponseModel response) { var responseModel = new MatchResponseModel { MatchId = response.Match.Id, GameFormat = response.Match.Format, GameTitle = response.Match.Title, GameMode = response.Match.Mode, Players = response.Match.Requests.SelectMany(x => x.Players.Select(p => new PlayerModel { Id = p.Id, Name = p.Name })) }; var json = JsonSerializer.Serialize(responseModel); var bytes = Encoding.UTF8.GetBytes(json); var bufferSize = 1024 * 4; var segments = ArraySegmentHelper.Segment(bytes, bufferSize); var webSocket = response.WebSocket; var tcs = response.WebSocketCompletionSource; foreach (var segment in segments) { var eom = segment == segments.Last(); await webSocket.SendAsync(segment, WebSocketMessageType.Text, eom, CancellationToken.None); } tcs.TrySetResult(new object()); }
public IHttpActionResult Get(string id) { if (string.IsNullOrEmpty(id)) { ModelState.AddModelError("Id", "Invalid request!"); return(BadRequest(ModelState)); } MatchByIdQuery query = new MatchByIdQuery(id); MatchResult result = queryDispatcher.Dispatch <MatchByIdQuery, MatchResult>(query); if (result == null) { return(NotFound()); } MatchResponseModel responseModel = Mapper.Map <MatchResponseModel>(result); return(Ok(responseModel)); }
public ActionResult ConfirmMatch(string keyword, string phrase) { var response = new MatchResponseModel(); var deviceId = GetDeviceId(); var accountId = GetAccountId(); try { _phraseService.Match(keyword, phrase, deviceId, accountId); response.Success = true; } catch (SoapException e) { response.SetError(e); } catch (Exception e) { response.SetError(e); } return(Json(response, JsonRequestBehavior.AllowGet)); }