예제 #1
0
        private void ClientTCP_OnReceivePneumoniaResponse(object sender, OnReceivePhotoResult e)
        {
            Cursor.Current = Cursors.Arrow;

            ResponseUserControl response = new ResponseUserControl(ResponseUserControl.PNEUMONIA);

            response.SetCancer(e.pneumoniaChanse);
            response.SetNonCancer(e.nonPneumoniaChanse);

            Console.WriteLine(e.pneumoniaChanse);
            Console.WriteLine(e.nonPneumoniaChanse);



            Panel p = (Panel)this.Parent;

            p.Controls.Clear();
            p.Controls.Add(response);
        }
예제 #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();

                        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;


                    case "photoresult":

                        OnReceivePhotoResult pneoargs = new OnReceivePhotoResult((string)obj["rezultat"][0][1], (string)obj["rezultat"][0][0]);
                        OnReceivePneumoniaResponse.Invoke(this, pneoargs);
                        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;
                }
            }
        }