Beispiel #1
0
 private void DisplayResult(OnReceiveResultArgs e)
 {
     if (this.InvokeRequired)
     {
         SetDisplayCallBack callback = new SetDisplayCallBack(DisplayResult);
         this.Invoke(callback, new object[] { e });
     }
     else
     {
         foreach (ResultPatient result in e.results)
         {
             this.metroGrid1.Rows.Add(result.name_patient, result.Sex, result.Age, result.on_thyroxine, result.query_on_thyroxine, result.on_antithyroid_medication, result.tumor, result.FTI_measured, result.FTI, result.thyroid_surgery, result.query_hypothyroid, result.query_hyperthyroid, result.pregnant, result.sick, result.lithium, result.TBG_measured, result.TBG, result.goitre, result.TSH_measured, result.TSH, result.T3_measured, result.T3, result.TT4_measured, result.TT4, result.positive, result.negative);
         }
     }
 }
Beispiel #2
0
        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;
                }
            }
        }
Beispiel #3
0
 private void ClientTCP_OnReceiveResults(object sender, OnReceiveResultArgs e)
 {
     DisplayResult(e);
 }