public ConnectionStatusMonitor(IEventStoreConnection connection)
{
var connectedChanged = Observable.FromEventPattern<ClientConnectionEventArgs>(h => connection.Connected += h,
h => connection.Connected -= h)
.Select(_ => ConnectionStatus.Connected);
var disconnectedChanged = Observable.FromEventPattern<ClientConnectionEventArgs>(h => connection.Disconnected += h,
h => connection.Disconnected -= h)
.Select(_ => ConnectionStatus.Disconnected);
var reconnectingChanged = Observable.FromEventPattern<ClientReconnectingEventArgs>(h => connection.Reconnecting += h,
h => connection.Reconnecting -= h)
.Select(_ => ConnectionStatus.Connecting);
_connectionInfoChanged = Observable.Merge(connectedChanged, disconnectedChanged, reconnectingChanged)
.Scan(ConnectionInfo.Initial, UpdateConnectionInfo)
.StartWith(ConnectionInfo.Initial)
.Replay(1);
_connection = _connectionInfoChanged.Connect();
}