ClientThread.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using ErgometerLibrary;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace ErgometerDoctorApplication
  9. {
  10. public class ClientThread
  11. {
  12. public int Session { get; }
  13. public string Name { get; }
  14. public bool IsOldData { get; }
  15. private SessionWindow window;
  16. public List<Meting> Metingen { get; set; }
  17. public List<ChatMessage> Chat { get; }
  18. public ClientThread(string name, int session, bool old)
  19. {
  20. Name = name;
  21. Session = session;
  22. IsOldData = old;
  23. window = new SessionWindow(Name, old, Session, this);
  24. window.FormClosed += Window_FormClosed;
  25. Metingen = new List<Meting>();
  26. Chat = new List<ChatMessage>();
  27. }
  28. private void Window_FormClosed(object sender, FormClosedEventArgs e)
  29. {
  30. MainClient.RemoveActiveClient(this);
  31. }
  32. public void HandleCommand(NetCommand command)
  33. {
  34. switch (command.Type)
  35. {
  36. case NetCommand.CommandType.DATA:
  37. lock (Metingen)
  38. {
  39. Metingen.Add(command.Meting);
  40. }
  41. window.Invoke(window.updateMetingen, new Object[] { command.Meting });
  42. break;
  43. case NetCommand.CommandType.CHAT:
  44. ChatMessage chat = new ChatMessage(command.DisplayName, command.ChatMessage, command.IsDoctor);
  45. Chat.Add(chat);
  46. window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { chat });
  47. break;
  48. case NetCommand.CommandType.UITLEG:
  49. window.steps.UitlegText.Invoke((MethodInvoker)(() => window.steps.UitlegText.Text = command.UitlegText));
  50. break;
  51. case NetCommand.CommandType.PERSONDATA:
  52. window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { new ChatMessage("Test", "DATA Gewicht=" + command.Gewicht + " Geslacht=" + command.Geslacht + " Leeftijd=" + command.Leeftijd + " Lengte=" + command.Lengte + ".", false) });
  53. Console.WriteLine("Not fully implemented");
  54. //NOG DOEN
  55. break;
  56. case NetCommand.CommandType.TESTRESULT:
  57. window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { new ChatMessage("Test", "DATA Vo2Max=" + command.VO2Max + " MET=" + command.MET + " PopulationAvg=" + command.PopulationAvg + " Zscore=" + command.ZScore + " Rating=" + command.Rating + ".", false) });
  58. Console.WriteLine("Not fully implemented");
  59. //NOG DOEN
  60. break;
  61. }
  62. }
  63. public void run()
  64. {
  65. Application.Run(window);
  66. }
  67. public void stop()
  68. {
  69. window.Close();
  70. MainClient.RemoveActiveClient(this);
  71. }
  72. private void sendCommand(NetCommand command)
  73. {
  74. if(! IsOldData)
  75. MainClient.SendNetCommand(command);
  76. }
  77. }
  78. }