ClientService.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. public void FileReceivedNotify(FileType fileType, string path)
  59. {
  60. //Log Here
  61. }
  62. protected virtual void Dispose(bool disposing)
  63. {
  64. if (!disposedValue)
  65. {
  66. if (disposing)
  67. {
  68. // TODO: dispose managed state (managed objects)
  69. _hubBase?.Dispose();
  70. }
  71. // TODO: free unmanaged resources (unmanaged objects) and override finalizer
  72. // TODO: set large fields to null
  73. disposedValue = true;
  74. }
  75. }
  76. // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
  77. // ~ClientService()
  78. // {
  79. // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  80. // Dispose(disposing: false);
  81. // }
  82. public void Dispose()
  83. {
  84. // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  85. Dispose(disposing: true);
  86. GC.SuppressFinalize(this);
  87. }
  88. }
  89. }