public static ResponsesList GetInstance() { if (instance == null) { instance = new ResponsesList(); } return(instance); }
private void ReceiveChatMessages(Action <Message> OnMessageReceive, CancellationToken CancellationToken) { while (!CancellationToken.IsCancellationRequested) { Response response = ResponsesList.GetInstance().GetResponseTo(RequestType.SpreadMessage, CancellationToken); if (response != null) { OnMessageReceive(new Message { Author = response.Data["Author"], Content = response.Data["Message"] }); } } }
public async void Receive() { NetworkStream networkStream = new NetworkStream(socket); String message = String.Empty; while (!CancellationResponseReadTokenSource.Token.IsCancellationRequested) { byte[] data = new byte[256]; await networkStream.ReadAsync(data, 0, data.Length, CancellationResponseReadTokenSource.Token); message += Encoding.UTF8.GetString(data); if (!networkStream.DataAvailable) { ResponsesList.GetInstance().Items.Add(JsonConvert.DeserializeObject <Response>(message)); message = String.Empty; } } }
public Response Request(Request request) { Send(request); return(ResponsesList.GetInstance().GetResponseTo(request.Type, CancellationResponseReadTokenSource.Token)); }