Exemple #1
0
 public static ResponsesList GetInstance()
 {
     if (instance == null)
     {
         instance = new ResponsesList();
     }
     return(instance);
 }
Exemple #2
0
 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"]
             });
         }
     }
 }
Exemple #3
0
        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;
                }
            }
        }
Exemple #4
0
 public Response Request(Request request)
 {
     Send(request);
     return(ResponsesList.GetInstance().GetResponseTo(request.Type, CancellationResponseReadTokenSource.Token));
 }