ClientService.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using EEMSClientCore;
  2. using ServiceBase;
  3. using System.Windows;
  4. namespace EEMSUIClient.Services
  5. {
  6. public class ClientService : IClientService, IClientBaseProvider
  7. {
  8. private readonly IClientCaller _clientCaller;
  9. private readonly ClientCaller _hubBase;
  10. private bool disposedValue;
  11. public ClientService()
  12. {
  13. _hubBase = new ClientCaller(this);
  14. _clientCaller = _hubBase;
  15. }
  16. public string? RecipePath { get; set; }
  17. public string? ConfigPath { get; set; }
  18. public bool Initialize(string ip, int port, string hub)
  19. {
  20. if (string.IsNullOrWhiteSpace(ip) || port < 0 || string.IsNullOrWhiteSpace(hub))
  21. {
  22. //log
  23. return false;
  24. }
  25. if (!_hubBase.Initialize())
  26. {
  27. //log
  28. return false;
  29. }
  30. if (!_hubBase.Open(ip, port, hub))
  31. {
  32. //log
  33. return false;
  34. }
  35. return true;
  36. }
  37. public Guid RegisterDevice(Models.DeviceInfo deviceInfo)
  38. {
  39. return _clientCaller.RegisterDevice(deviceInfo.Convert()).Result;
  40. }
  41. public bool UpdateRealTimeData(Dictionary<string, object> realtimeData)
  42. {
  43. return _clientCaller.UpdateRealTimeData(realtimeData).Result;
  44. }
  45. public void FileReceivedNotify(FileType fileType)
  46. {
  47. MessageBox.Show($"{fileType} Received");
  48. }
  49. public void StartFileReceiveNotify(FileType fileType)
  50. {
  51. //Log Here
  52. //MessageBox.Show($"Start Receiving {fileType} File");
  53. }
  54. public bool AllowReceiveFile()
  55. {
  56. return true;
  57. }
  58. protected virtual void Dispose(bool disposing)
  59. {
  60. if (!disposedValue)
  61. {
  62. if (disposing)
  63. {
  64. // TODO: dispose managed state (managed objects)
  65. _hubBase?.Dispose();
  66. }
  67. // TODO: free unmanaged resources (unmanaged objects) and override finalizer
  68. // TODO: set large fields to null
  69. disposedValue = true;
  70. }
  71. }
  72. // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
  73. // ~ClientService()
  74. // {
  75. // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  76. // Dispose(disposing: false);
  77. // }
  78. public void Dispose()
  79. {
  80. // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  81. Dispose(disposing: true);
  82. GC.SuppressFinalize(this);
  83. }
  84. }
  85. }