private void Client_OnResponse(object sender, OnReceiveMessageClientEventArgs e) { MedicalProblems medicalproblem = e.Medical; /* * Here I will implement things * Update GUI * Add shit * */ }
public void Response() { while (true) { try { byte[] receivebuffer = new byte[this.buffersize]; //this..Receive(receivebuffer, 0, receivebuffer.Length, 0); //string response = Encoding.ASCII.GetString(receivebuffer); StringBuilder messageData = new StringBuilder(); int bytes = -1; do { bytes = sslStream.Read(receivebuffer, 0, receivebuffer.Length); Decoder decoder = Encoding.UTF8.GetDecoder(); char[] messagepart = new char[decoder.GetCharCount(receivebuffer, 0, bytes)]; decoder.GetChars(receivebuffer, 0, bytes, messagepart, 0); messageData.Append(messagepart); if (messageData.ToString().IndexOf("<EOF>") != -1) { break; } } while (bytes != 0); string response = messageData.ToString(); response = response.Substring(0, response.Length - 5); Console.WriteLine(response); JObject obj = JObject.Parse(response); if (obj["action"] == null) { /* * Error shit * To do: * Write a file with the logs * Creating the MedicalProblems object * * */ Console.WriteLine("No action has been sent!"); return; } string action = (string)obj["action"]; switch (action) { case "response": MedicalProblems problem = new MedicalProblems(); Console.WriteLine("yes"); Console.WriteLine(obj["rezultat"][0][0].GetType()); Console.WriteLine(obj["rezultat"][1][1]); problem.Chanse_To_Have = obj["rezultat"][0][0].ToObject <double>(); problem.Chanse_To_Have_Nothing = obj["rezultat"][1][1].ToObject <double>(); //Console.WriteLine("Problem with invoke shit"); OnResponse?.Invoke(this, new OnReceiveMessageClientEventArgs { Medical = problem }); break; case "regresponse": Console.WriteLine("Receiving register response"); OnRegisterResponse?.Invoke(this, new OnReceiveRegisterMessageArgs { errorcode = (int)obj["errorcode"], errormessage = (string)obj["errormessage"] }); break; case "loginresponse": //Console.WriteLine("Receiving login response"); Console.WriteLine("Code..... \n"); string errorcodeestring = (string)obj["error"]; Console.WriteLine(errorcodeestring); int errorcodee = Int32.Parse(errorcodeestring); Console.WriteLine("Cod de eroare: " + errorcodee); if (errorcodee == 0) { this.Cookie = (string)obj["cookie"]; this.isloged = true; } OnLoginResponse?.Invoke(this, new OnReceiveLoginMessageArgs { errorcode = errorcodee, errormessage = (string)obj["errormessage"], username = (string)obj["username"] }); break; case "code_verify_response": Console.WriteLine("Receiving code_verify response"); OnCodeVerifyResponse?.Invoke(this, new OnCodeVerifyResponseArgs { errorcode = (int)obj["errorcode"], errormessage = (string)obj["errormessage"] }); break; case "results": int errorcode = (int)obj["error"]; if (errorcode == 0) { OnReceiveResultArgs args = JsonConvert.DeserializeObject <OnReceiveResultArgs>(response); OnReceiveResults?.Invoke(this, args); } else { } break; default: /* * Some error comming from server * or maybe from client? * IDK * * */ break; } } catch (Exception ex) { OnConnectionLost?.Invoke(this, EventArgs.Empty); Console.WriteLine("Wrong format " + ex.Message); this.isloged = false; break; } } }