예제 #1
0
        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);
            }
        }
예제 #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);
        }
예제 #3
0
        private void AcceptClient(TcpClient client)
        {
            var piClient = new PiClient(client, _loggerFactory);

            piClient.StartListening(_appStopToken);
        }