protected override async Task ExecuteAsync(CancellationToken st)
        {
            _token = st;
            while (!st.IsCancellationRequested)
            {
                var hosts = _config.CurrentValue.Hosts;
                if (hosts != null && hosts.Length > 0)
                {
                    foreach (var host in _config.CurrentValue.Hosts)
                    {
                        if (_clientCache.Clients.Any(x => x.IPAddress == host.IPAddress))
                        {
                            continue;
                        }
                        else if (_errorHosts.Contains(host))
                        {
                            continue;
                        }

                        PiClient piClient = new PiClient();
                        if (await piClient.ConnectToServerAsync(host.Name, host.IPAddress, host.Port, _token))
                        {
                            _logger.LogInformation($"Connected to {host.Name}");
                            _clientCache.AddClient(piClient);
                        }
                        else
                        {
                            _errorHosts.Add(host);
                        }
                    }
                }
                await Task.Delay(5000, st);
            }
        }
Example #2
0
        public void AddClient(PiClient client)
        {
            if (client == null || string.IsNullOrEmpty(client.IPAddress))
            {
                throw new ArgumentNullException("Client was null or had no IP Address");
            }

            _allClientAddresses.Add(client.IPAddress);
            _memoryCache.Set(client.IPAddress, client);
        }
Example #3
0
        private void AcceptClient(TcpClient client)
        {
            var piClient = new PiClient(client, _loggerFactory);

            piClient.StartListening(_appStopToken);
        }