Esempio n. 1
0
        protected void ProcessNode(IPAddress address, IPStatus status)
        {
            long roundTripTime = 0;

            if (status == IPStatus.TtlExpired || status == IPStatus.Success)
            {
                var pingIntermediate = new Ping();

                try
                {
                    //Compute roundtrip time to the address by pinging it
                    PingReply reply = pingIntermediate.Send(address, _timeout);
                    roundTripTime = reply.RoundtripTime;
                    status = reply.Status;
                }
                catch (PingException e)
                {
                    //Do nothing
                    System.Diagnostics.Trace.WriteLine(e);
                }
                finally
                {
                    pingIntermediate.Dispose();
                }
            }

            var node = new TracertNode(address, roundTripTime, status);

            lock (_nodes)
            {
                _nodes.Add(node);
            }

            if (RouteNodeFound != null)
                RouteNodeFound(this, new RouteNodeFoundEventArgs(node, IsDone));

            IsDone = address.Equals(_destination);

            lock (_nodes)
            {
                if (!IsDone && _nodes.Count >= _maxHops - 1)
                    ProcessNode(_destination, IPStatus.Success);
            }
        }
 protected internal RouteNodeFoundEventArgs(TracertNode node, bool isDone)
 {
     _node = node;
     _isLastNode = isDone;
 }