| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using EEMSClientCore;
- using ServiceBase;
- namespace EEMSUIClient.Services
- {
- public class ClientService : IClientService, IClientProvider
- {
- private readonly IClientCaller _clientCaller;
- private readonly ClientCaller _hubBase;
- private bool disposedValue;
- public ClientService()
- {
- _clientCaller = new ClientCaller();
- _hubBase = new HubBase();
- }
- public event EventHandler<(Guid guid, FileType fileType)>? RequestFileReceived;
- public bool Initialize(string ip, int port, string hub)
- {
- if (string.IsNullOrWhiteSpace(ip) || port < 0 || string.IsNullOrWhiteSpace(hub))
- {
- //log
- return false;
- }
- if (!_hubBase.Initialize(this))
- {
- //log
- return false;
- }
- if (!_hubBase.Open(ip, port, hub))
- {
- //log
- return false;
- }
- return true;
- }
- public Guid RegisterDevice(Models.DeviceInfo deviceInfo)
- {
- return _clientCaller.RegisterDevice(deviceInfo.Convert()).Result;
- }
- public Task<bool> RequestFile(Guid guid, FileType fileType)
- {
- //log
- RequestFileReceived?.Invoke(null, (guid, fileType));
- return Task.FromResult(true);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- // TODO: dispose managed state (managed objects)
- _hubBase?.Dispose();
- }
- // TODO: free unmanaged resources (unmanaged objects) and override finalizer
- // TODO: set large fields to null
- disposedValue = true;
- }
- }
- // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
- // ~ClientService()
- // {
- // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
- // Dispose(disposing: false);
- // }
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
- }
|