ClientService.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. protected virtual void Dispose(bool disposing)
  46. {
  47. if (!disposedValue)
  48. {
  49. if (disposing)
  50. {
  51. // TODO: dispose managed state (managed objects)
  52. _hubBase?.Dispose();
  53. }
  54. // TODO: free unmanaged resources (unmanaged objects) and override finalizer
  55. // TODO: set large fields to null
  56. disposedValue = true;
  57. }
  58. }
  59. // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
  60. // ~ClientService()
  61. // {
  62. // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  63. // Dispose(disposing: false);
  64. // }
  65. public void Dispose()
  66. {
  67. // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  68. Dispose(disposing: true);
  69. GC.SuppressFinalize(this);
  70. }
  71. public void FileReceivedNotify(FileType fileType)
  72. {
  73. MessageBox.Show($"{fileType} Received");
  74. }
  75. public void StartFileReceiveNotify(FileType fileType)
  76. {
  77. //Log Here
  78. //MessageBox.Show($"Start Receiving {fileType} File");
  79. }
  80. }
  81. }