Ejemplo n.º 1
0
        private void SendStatusToAllRegisteredPorts(Request request)
        {
            //if no one is listening, don't speak!
            if (!_updatePorts.Any())
            {
                _logger.LogMessage("No ports to send status to.");
                return;
            }

            var worker = new BackgroundWorker();

            worker.DoWork += (x, y) => {
                var portsToRemove = new List <int>();
                foreach (var port in _updatePorts.ToList())
                {
                    try {
                        SendSocketService.SendRequest(request, port);
                        _logger.LogMessage($"Sent request to port {port}.");
                    } catch (Exception ex) {
                        //this clearly is not cool- stop trying to talk
                        _logger.LogException(ex, $"Error sending status to port {port}.");
                        portsToRemove.Add(port);
                    }
                }

                foreach (var portToRemove in portsToRemove)
                {
                    _updatePorts.Remove(portToRemove);
                }
            };
            worker.RunWorkerAsync();
        }
        public void SendRequest(Request request)
        {
            //if no one is listening, don't speak!
            if (!_ports.Any())
            {
                _logger.LogMessage("No ports to send status to.");
                _connectionIsAliveTimer.Enabled = false;
                return;
            }

            var worker = new BackgroundWorker();

            worker.DoWork += (x, y) => {
                var portsToRemove = new List <int>();
                lock (_portsLock) {
                    foreach (var port in _ports)
                    {
                        if (SendSocketService.SendRequest(request, port) == null)
                        {
                            //the sender isn't there- stop trying
                            portsToRemove.Add(port);
                        }

                        _logger.LogMessage($"Sent request to port {port}.");
                    }

                    foreach (var portToRemove in portsToRemove)
                    {
                        _ports.Remove(portToRemove);
                    }
                }
            };
            worker.RunWorkerAsync();
        }
 public static string SendRequest(Request request)
 {
     return(SendSocketService.SendRequest(request, TcpInfo.ArkhamOverlayPort));
 }
 private string SendRequest(Request request)
 {
     return(SendSocketService.SendRequest(request, TcpInfo.EmoPort));
 }