public bool?Update(DateTime utcNow, long counter, ConnectionState?simulateConnection) { bool?result = null; PeerGroup peerGroup = this.Location.PeerGroup; if (peerGroup.CanPoll(utcNow, this.lastPolled)) { ConnectionState priorConnection = this.Connection; using (Pinger pinger = new Pinger(peerGroup.Wait)) { TimeSpan roundtripTime = TimeSpan.Zero; if (simulateConnection != null) { this.Connection = simulateConnection.Value; } else { bool?ping = pinger.TryPing(this.Location.Address, out roundtripTime); switch (ping) { case true: this.Connection = ConnectionState.Connected; break; case false: this.Connection = ConnectionState.Disconnected; break; default: this.Connection = ConnectionState.Unavailable; break; } } this.RoundtripTime = roundtripTime; this.UpdateCounter = counter; } result = this.Connection != priorConnection; this.lastPolled = utcNow; } return(result); }
public bool?Update(DateTime utcNow, long counter, bool simulateFailure) { bool?result = null; PeerGroup peerGroup = this.Location.PeerGroup; if (peerGroup.CanPoll(utcNow, this.lastPolled)) { bool?wasConnected = this.IsConnected; using (Pinger pinger = new Pinger(peerGroup.Wait)) { TimeSpan roundtripTime = TimeSpan.Zero; this.IsConnected = !simulateFailure && pinger.TryPing(this.Location.Address, out roundtripTime); this.RoundtripTime = roundtripTime; this.UpdateCounter = counter; } result = this.IsConnected != wasConnected; this.lastPolled = utcNow; } return(result); }