protected string CreateResult <T, U>(ParamsMessage receivedMessage, T result) where U : ResultMessage <T>, new() { return(SerializeResult(new U { Id = receivedMessage.Id, Jsonrpc = receivedMessage.Jsonrpc, Result = result })); }
protected override void HandleParams(byte[] bytes) { currentState = Packet.Deserialize <ParamsMessage>(bytes); ChangeRow(0); // build rows popup var items = new List <string>(); for (int i = 0; i < 3; i++) { items.Add(currentState.whos[i] + " - " + currentState.whats[i]); } chooseRowPopup.items = items; }
public async Task <PagedList <Message> > GetMessagesForUser(ParamsMessage paramsMessage) { //get the messages var messages = _context.Messages //include the sender object, and then include the photo of the sender .Include(u => u.Sender).ThenInclude(p => p.Photos) //include the Recipient object, and then include the photo of the Recipient .Include(u => u.Recipient).ThenInclude(p => p.Photos) //make it quaryable, so as not to cause error .AsQueryable(); //check the passed in parameter switch (paramsMessage.MessageContainer) { case "Inbox": //get messages based on inboxe, based on RecipientID who sent me messages, & where it's not deleted messages = messages.Where(u => u.RecipientId == paramsMessage.UserId && u.RecipientDeleted == false); break; case "Outbox": //get messages based on outbox, based on who i sent messages, & where it's not deleted messages = messages.Where(u => u.SenderId == paramsMessage.UserId && u.SenderDeleted == false); break; default: //get the default, which is "UnRead" messages = messages.Where(u => u.RecipientId == paramsMessage.UserId && u.RecipientDeleted == false && u.IsRead == false); break; } //order by decending, so as to show from the latest message messages = messages.OrderByDescending(d => d.MessageSent); //query and get the number of messages based on the page size and it number return(await PagedList <Message> .QueryAsync(messages, paramsMessage.PageNumber, paramsMessage.PageSize)); }
public async Task <IActionResult> GetMessagesForUser(int userId, [FromQuery] ParamsMessage messageParams) { //check if logged in user is authorized if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } //set the logedin userId as USerID Params before it's been passed messageParams.UserId = userId; //get all messages from repo based on the params var messagesFromRepo = await _repo.GetMessagesForUser(messageParams); //map the data from database to the object data we would be returning var messages = _mapper.Map <IEnumerable <MessageToReturnDto> >(messagesFromRepo); //add the PAGINATION detail to our response header helper method Response.AddPagination(messagesFromRepo.CurrentPage, messagesFromRepo.PageSize, messagesFromRepo.TotalCount, messagesFromRepo.TotalPages); //return Okay, with the mapped messages data return(Ok(messages)); }
public async Task Start() { byte[] buffer = new byte[1024]; List <NamedPipeServerStream> servers = new List <NamedPipeServerStream>(); servers.Add(CreateServer()); while (!Successful) { NamedPipeServerStream serverStream = servers.Last(); try { await serverStream.WaitForConnectionAsync(_cancellationTokenSource.Token); } catch (OperationCanceledException) { serverStream.Dispose(); break; } int read = await serverStream.ReadAsync(buffer, 0, 1024); ParamsMessage message = ParseMessage(buffer, read); string output = null; switch (message.Method) { case "ClientLibrary.isClientRunning": output = CreateResult <bool, ResultMessage <bool> >(message, true); break; case "ClientLibrary.initSession": output = CreateResult <string, ResultMessage <string> >(message, message.Params.SessionId); break; case "ClientLibrary.queryAuthorizationCode": output = CreateResult <string, ResultMessage <string> >(message, _sessionToken); _sessionToken = null; break; case "ClientLibrary.queryGameAccountName": output = CreateResult <string, ResultMessage <string> >(message, Process.Account.Name); Process.Process.Exited -= OnNostaleExit; Successful = true; break; } if (!Successful) { servers.Add(CreateServer()); } if (output != null) { byte[] data = Encoding.ASCII.GetBytes(output); serverStream.Write(data, 0, data.Length); } } foreach (NamedPipeServerStream server in servers) { server.Dispose(); } }