void bikeDataChanged(object _bikeData, EventArgs e) { try { RootObjectSendBikeInfo bikeData = (RootObjectSendBikeInfo)_bikeData; allBikeData.Add(bikeData); this.Invoke(new MethodInvoker(delegate { if (bikeData.name == bikeName) { this.pulse = (int)bikeData.data.pulse; txtDistance.Text = bikeData.data.distance.ToString(); txtSpeed.Text = bikeData.data.speed.ToString(); txtRequestedPower.Text = bikeData.data.requestedPower.ToString(); txtEnergy.Text = bikeData.data.energy.ToString(); txtPower.Text = bikeData.data.power.ToString(); txtPulse.Text = bikeData.data.pulse.ToString(); txtRPM.Text = bikeData.data.RPM.ToString(); txtTime.Text = bikeData.data.time; chart1.Series["Energy"].Points.Add(Convert.ToDouble(bikeData.data.energy.Split(' ')[0])); chart1.Series["Power"].Points.Add(Convert.ToDouble(bikeData.data.power)); chart1.Series["Distance"].Points.Add(Convert.ToDouble(bikeData.data.distance)); chart1.Series["Requested Power"].Points.Add(Convert.ToDouble(bikeData.data.requestedPower)); chart1.Series["Pulse"].Points.Add(Convert.ToDouble(bikeData.data.pulse)); chart1.Series["RPM"].Points.Add(Convert.ToDouble(bikeData.data.RPM)); chart1.Series["Speed"].Points.Add(Convert.ToDouble(bikeData.data.speed)); } })); if (aa != null) { if (bikeData.name == bikeName) { aa.Invoke(new MethodInvoker(delegate { if (aa.infoScreen != null) { //aa.infoScreen.Text = bikeData.data.time; aa.time = bikeData.data.time; //aa.CheckTime(); } })); } } } catch { //MessageBox.Show("Dokter has disconnected" ); } }
/// <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; } } }