ClientService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public void FileReceivedNotify(FileType fileType)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. }
  75. }