/// <summary> /// This method is running the thread started by the ServerConnect() method /// It listens to incoming messages and enters the switch case which switches on the id from the message /// </summary> public void MethodThread() { Console.WriteLine("started listening"); Boolean connected = false; while (!connected) { dynamic jsonReceive = JsonConvert.DeserializeObject(ConnectionUtils.ReadMessage(stream)); string id = jsonReceive.id; switch (id) { case "LoginResponse": Boolean response = jsonReceive.response; if (!response) { errorLabel.Invoke(new MethodInvoker(delegate { errorLabel.Text = "The credentials you supplied were not correct."; })); } else { Thread t = new Thread(new ThreadStart(ThreadProc)); t.Start(); login.Invoke(new MethodInvoker(delegate { login.Close(); })); connected = true; SendAdd(); } break; } } Boolean finished = false; while (!finished) { dynamic jsonReceive = JsonConvert.DeserializeObject(ConnectionUtils.ReadMessage(stream)); string id = jsonReceive.id; switch (id) { case "Ack": Console.WriteLine("Bike added"); Console.WriteLine(jsonReceive); List <string> bikeNames = GetBikeNames(jsonReceive); Console.WriteLine("BIKENAMES: " + bikeNames.Count); patientNames = GetPatientNames(jsonReceive); Console.WriteLine("AANTAL PATIENTEN: " + patientNames.Count); if (machineNames == null) { machineNames = new List <string>(); machineNames = bikeNames; } else { machineNames.Concat(bikeNames); } Form1.patients = patientNames; Form1.getNames(); Console.WriteLine("IS FORM NULL: " + form == null); Thread t2 = new Thread(new ThreadStart(StartUpdate)); t2.Start(); break; case "PatientNames": Console.WriteLine("PATIENTS: " + jsonReceive); this.patientNames = GetPatientNames(jsonReceive); this.patientNames.Concat(patientNames); foreach (Patient patient in this.patientNames) { Console.WriteLine(patient.age.ToString()); } break; case "SendNewName": string newClient = jsonReceive.name; Console.WriteLine("name: " + newClient); if (machineNames == null) { machineNames = new List <string>(); machineNames.Add(newClient); } else { machineNames.Add(newClient); } if (form != null) { Console.WriteLine("updated"); form.Invoke((MethodInvoker) delegate() { form.UpdateForm(machineNames, patientNames); Console.WriteLine("BIKENAMES: " + machineNames.Count); }); } break; case "Bike": JObject data = (JObject)jsonReceive; bikeInfoData = data.ToObject <RootObjectSendBikeInfo>(); if (AvansAstrand != null) { AvansAstrand.FillChart(); } //Console.WriteLine(bikeInfoData.data); break; case "HistoryData": Console.WriteLine("RECEIVED HISTORY: " + jsonReceive); SetHistoryData(jsonReceive); break; case "Astrand": string AInfo = jsonReceive.info; string AName = jsonReceive.name; int value = jsonReceive.value; AvansAstrand.SetInfo(AInfo, AName, value); break; case "Time": string time = jsonReceive.time; string TName = jsonReceive.name; AvansAstrand.SetTime(time, TName); break; case "VO2": string VName = jsonReceive.name; double Vo2 = jsonReceive.VO2; if (AvansAstrand.machineName == VName) { AvansAstrand.Invoke(new MethodInvoker(delegate { AvansAstrand.Vo2.Text = Vo2.ToString(); })); } break; } } }
private void button2_Click(object sender, EventArgs e) { aa = new AvansAstrand(doctor, bikeName, AaPatient, this); aa.Show(); doctor.StartAvansTest(bikeName, AaPatient); }