ClientThread.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  49. }
  50. public void run()
  51. {
  52. Application.Run(window);
  53. }
  54. public void stop()
  55. {
  56. window.Close();
  57. MainClient.RemoveActiveClient(this);
  58. }
  59. private void sendCommand(NetCommand command)
  60. {
  61. if(! IsOldData)
  62. MainClient.SendNetCommand(command);
  63. }
  64. }
  65. }