AppGlobal.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Collections.Generic;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using System;
  5. using System.Linq;
  6. using Server.JSONObjecten;
  7. using JsonConverter = Server.FileIO.JsonConverter;
  8. namespace Server
  9. {
  10. public class AppGlobal
  11. {
  12. private static AppGlobal _instance;
  13. private List<User> users;
  14. private List<User> activePatient;
  15. private List<User> activeDoctor;
  16. public List<Client> Clients;
  17. public static AppGlobal Instance
  18. {
  19. get { return _instance ?? (_instance = new AppGlobal()); }
  20. }
  21. public AppGlobal()
  22. {
  23. users = new List<User>();
  24. Clients = new List<Client>();
  25. TestMethode();
  26. Console.WriteLine(JsonConverter.GetUserSessions(users.ElementAt(1)));
  27. }
  28. private void TestMethode()
  29. {
  30. users.Add(new User("no", "no", 0, false, 0));
  31. users.Add(new User("JK123", "jancoow", 5, true, 100));
  32. users.Add(new User("TOM", "tommie", 80, false, 77, true));
  33. Random r = new Random();
  34. Session session = new Session(1, "100");
  35. for (int i = 0; i < 100; i++)
  36. session.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
  37. users.ElementAt(1).tests.Add(session);
  38. Session session2 = new Session(2, "100");
  39. for (int i = 0; i < 200; i++)
  40. session2.AddMeasurement(new Measurement(r.Next(100, 200), r.Next(60, 100), r.Next(100, 150), r.Next(0, 100), i, r.Next(100), r.Next(100), r.Next(100), i, r.Next(100)));
  41. users.ElementAt(1).tests.Add(session2);
  42. }
  43. public void CheckLogin(string username, string password, out int admin, out int id)
  44. {
  45. id = -1;
  46. admin = 0;
  47. foreach (User u in users)
  48. {
  49. if (u.id == username && u.password == password)
  50. {
  51. admin = u.isDoctor ? 1 : 0;
  52. id = users.IndexOf(u);
  53. /* if (u.isDoctor)
  54. {
  55. activeDoctor.Add(u);
  56. }
  57. activePatient.Add(u);*/
  58. }
  59. }
  60. }
  61. public List<User> GetUsers()
  62. {
  63. return users;
  64. }
  65. public List<Session> GetTests(string patientid)
  66. {
  67. foreach (User u in users)
  68. {
  69. if (u.id == patientid)
  70. {
  71. return u.tests;
  72. }
  73. }
  74. return null;
  75. }
  76. public void AddSession(string patientid, int mode, string modevalue)
  77. {
  78. foreach (User u in users)
  79. {
  80. if (u.id == patientid)
  81. {
  82. u.AddSession(new Session(mode, modevalue));
  83. }
  84. }
  85. }
  86. }
  87. }