ClientThread.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if (command != null && command.Meting != null)
  38. {
  39. lock (Metingen)
  40. {
  41. Metingen.Add(command.Meting);
  42. }
  43. window.Invoke(window.updateMetingen, new Object[] { command.Meting });
  44. }
  45. break;
  46. case NetCommand.CommandType.CHAT:
  47. ChatMessage chat = new ChatMessage(command.DisplayName, command.ChatMessage, command.IsDoctor);
  48. Chat.Add(chat);
  49. window.panelClientChat.Invoke(window.panelClientChat.passChatMessage, new Object[] { chat });
  50. break;
  51. case NetCommand.CommandType.UITLEG:
  52. window.steps.UitlegText.Invoke((MethodInvoker)(() => window.steps.UitlegText.Text = command.UitlegText));
  53. break;
  54. case NetCommand.CommandType.PERSONDATA:
  55. 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) });
  56. Console.WriteLine("Not fully implemented");
  57. //NOG DOEN
  58. break;
  59. case NetCommand.CommandType.TESTRESULT:
  60. 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) });
  61. Console.WriteLine("Not fully implemented");
  62. //NOG DOEN
  63. break;
  64. }
  65. }
  66. public void run()
  67. {
  68. Application.Run(window);
  69. }
  70. public void stop()
  71. {
  72. window.Close();
  73. MainClient.RemoveActiveClient(this);
  74. }
  75. private void sendCommand(NetCommand command)
  76. {
  77. if(! IsOldData)
  78. MainClient.SendNetCommand(command);
  79. }
  80. }
  81. }