ClientService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 HubBase(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. protected virtual void Dispose(bool disposing)
  41. {
  42. if (!disposedValue)
  43. {
  44. if (disposing)
  45. {
  46. // TODO: dispose managed state (managed objects)
  47. _hubBase?.Dispose();
  48. }
  49. // TODO: free unmanaged resources (unmanaged objects) and override finalizer
  50. // TODO: set large fields to null
  51. disposedValue = true;
  52. }
  53. }
  54. // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
  55. // ~ClientService()
  56. // {
  57. // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  58. // Dispose(disposing: false);
  59. // }
  60. public void Dispose()
  61. {
  62. // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  63. Dispose(disposing: true);
  64. GC.SuppressFinalize(this);
  65. }
  66. }
  67. }