Ejemplo n.º 1
0
 public void OnChanged(TcpConnectionDescriptor descriptor)
 {
     lock (_syncRoot)
     {
         _currentConnections.Add(descriptor);
     }
 }
Ejemplo n.º 2
0
        private void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs args)
        {
            TcpConnectionDescriptor descriptor;

            if (TcpConnectionDescriptor.TryParse(args.Data, out descriptor))
            {
                _result.Add(descriptor);

                lock (_listeners)
                {
                    foreach (var listener in _listeners)
                    {
                        listener.OnChanged(descriptor);
                    }
                }
            }
            else
            {
                Log.DebugFormat("Unable to parse '{0}'", args.Data);
            }
        }
        public static bool TryParse(string value, out TcpConnectionDescriptor descriptor)
        {
            if (value != null)
            {
                string[] values = value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                EndPoint localAddress, foreignAddress;
                TcpState state;
                if (values.Length == 4 &&
                    values[0] == "TCP" &&
                    TryParse(values[1], out localAddress) &&
                    TryParse(values[2], out foreignAddress) &&
                    TryParse(values[3], out state))
                {
                    descriptor = new TcpConnectionDescriptor(localAddress, foreignAddress, state);
                    return(true);
                }
            }

            descriptor = null;
            return(false);
        }