private void TestMethode() { users.Add(new User("JK123", "jancoow", 5, true, 100)); users.Add(new User("patient", "patient", 0, false, 0)); users.Add(new User("doctor", "doctor", 0, false, 0, true)); users.Add(new User("admin", "admin", 80, false, 77, true)); Random r = new Random(); Session session = new Session(1); for (int i = 0; i < 20; i++) session.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), i, r.Next(100), r.Next(100), r.Next(100), i)); users.ElementAt(1).sessions.Add(session); Session session2 = new Session(2); for (int i = 0; i < 50; i++) session2.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), i, r.Next(100), r.Next(100), r.Next(100), i)); users.ElementAt(1).sessions.Add(session2); }
public void receive() { while (client.Connected) { byte[] bytesFrom = new byte[(int)client.ReceiveBufferSize]; try { sslStream.Read(bytesFrom, 0, client.ReceiveBufferSize); } catch (IOException e) { Console.WriteLine(e.StackTrace); break; } string response = Encoding.ASCII.GetString(bytesFrom); string[] response_parts = response.Split('|'); if (response_parts.Length > 0) { switch (response_parts[0]) { case "0": //login and display correct window after login if (response_parts.Length == 4) { if (response_parts[1] == "1" && response_parts[2] == "1") { currentData = new CurrentData(userID); currentData.isDoctor = true; SendGet(1); } else if (response_parts[2] == "0" && response_parts[1] == "1") { currentData = new CurrentData(userID); currentData.isDoctor = false; SendGet(1); } else new Login("Geen gebruiker gevonden"); } break; case "1": response_parts[1] = response_parts[1].TrimEnd('\0'); currentData.setSessionList(JsonConvert.DeserializeObject<List<Session>>(response_parts[1])); if (currentData.isDoctor == true) { Form activeForm = Form.ActiveForm; activeForm.Invoke((MethodInvoker)delegate () { DoctorForm doctorForm = new DoctorForm(this); activeForm.Hide(); doctorForm.Show(); }); } else { Form activeForm = Form.ActiveForm; if (activeForm != null) { activeForm.Invoke((MethodInvoker)delegate () { PatientForm patientForm = new PatientForm(this); activeForm.Hide(); patientForm.Show(); }); } } break; case "2": dynamic DynMeasurement = JsonConvert.DeserializeObject<dynamic>(response_parts[2].TrimEnd('\0')); Measurement outputMeasurement = new Measurement((int)DynMeasurement.pulse, (int)DynMeasurement.rpm, (int)DynMeasurement.speed, (int)DynMeasurement.distance, (int)DynMeasurement.requestedPower, (int)DynMeasurement.energy, (int)DynMeasurement.actualPower, (int)DynMeasurement.time); currentData.GetSessions().Last().AddMeasurement(outputMeasurement); Forms.DoctorSessionUC sessionUC = null; bool b = DoctorModel.doctorModel.doctorSessions.TryGetValue(response_parts[1], out sessionUC); if (b) { sessionUC.HandleSessionBikeData(outputMeasurement); } break; case "7": // sender receiver message onIncomingChatMessage(new string[] { response_parts[1], response_parts[2], response_parts[3].TrimEnd('\0') }); break; case "8": if (response_parts[1].TrimEnd('\0') != "-1") { DoctorModel.doctorModel.onlinePatients = response_parts[1].TrimEnd('\0').Split('\t').ToList(); } else if (response_parts[1].TrimEnd('\0') == "-1") { DoctorModel.doctorModel.onlinePatients = new List<String>(); } break; case "9": dynamic results = JsonConvert.DeserializeObject<dynamic>(response_parts[1]); foreach (dynamic r in results) { User user = r as User; users.Add(new User(r.id.ToString(), r.password.ToString(), Int32.Parse(r.age.ToString()), Boolean.Parse(r.gender.ToString()), Int32.Parse(r.weight.ToString()), Boolean.Parse(r.isDoctor.ToString()))); int i = 1; foreach (dynamic ses in r.sessions) { Session tempSession = new Session(i); i++; foreach (dynamic m in ses.measurements) { Measurement measurement = new Measurement((int)m.pulse, (int)m.rpm, (int)m.speed, (int)m.distance, (int)m.requestedPower, (int)m.energy, (int)m.actualPower, (int)m.time); ; tempSession.AddMeasurement(measurement); } users.Last().AddSession(tempSession); } Console.WriteLine(users); } break; case "10": if (!currentData.isDoctor) { PatientModel.patientModel.CurrentDoctorID = response_parts[3].TrimEnd('\0'); if (response_parts[1] == "1") { PatientModel.patientModel.startSession(); } else if (response_parts[1] == "0") { StopSessoin(); } } else { if (response_parts[1] == "1") { StartNewSession(true, response_parts[2]); } } break; case "20": PatientModel.patientModel.setDistanceMode(response_parts[1].TrimEnd('\0'), false); break; case "21": PatientModel.patientModel.setTimeMode(response_parts[1].TrimEnd('\0') + response_parts[2].TrimEnd('\0'), false); break; case "22": //PatientModel.patientModel.setPower(response_parts[1].TrimEnd('\0')); PatientModel.patientModel.powerLog = response_parts[1].TrimEnd('\0'); break; } } } }
private void readDataFromJson() { //Read UserDate file string s = File.ReadAllText(@"JSON Files\UserData.Json"); dynamic results = JsonConvert.DeserializeObject<dynamic>(s); //Clear list users = new List<User>(); foreach (dynamic r in results) { users.Add(new User(r.id.ToString(), r.password.ToString(), Int32.Parse(r.age.ToString()), Boolean.Parse(r.gender.ToString()), Int32.Parse(r.weight.ToString()), Boolean.Parse(r.isDoctor.ToString()))); int i = 1; foreach (dynamic ses in r.sessions) { Session tempSession = new Session(i); i++; foreach (dynamic m in ses.measurements) { Measurement measurement = new Measurement(Int32.Parse(m.pulse.ToString()), Int32.Parse(m.rpm.ToString()), Int32.Parse(m.speed.ToString()), Int32.Parse(m.distance.ToString()), Int32.Parse(m.requestedPower.ToString()), Int32.Parse(m.energy.ToString()), Int32.Parse(m.actualPower.ToString()), Int32.Parse(m.time.ToString())); tempSession.AddMeasurement(measurement); } users.Last().AddSession(tempSession); } } }