ClientService.cs 2.4 KB

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