/// <summary>Method which when a StatsConnection is established requests Interface statistics.</summary> /// <param name="sender">The source of the event.</param> /// <param name="connectionStatus">The <see cref="StatsConnection"/>'s new <see cref="StatsConnection.ConnectionStatus"/>.</param> private void Connection_ConnectionStatusChanged(object sender, StatsConnection.ConnectionStatus connectionStatus) { // The sender should be a StatsConnection so that we can interact with that StatsConnection instance. StatsConnection statsConnection = sender as StatsConnection; if (statsConnection == null) { return; } // Specifically what did the ConnectionStatus change to? switch (connectionStatus) { // It was previously not connected and now it is. case StatsConnection.ConnectionStatus.Connected: // Compose a subscription request message. SubscriptionRequest subscriptionRequest = new SubscriptionRequest { Subscribe = new Subscription[] { new Subscription() { name = SubscriptionMessageType.Interfaces } }, SessionID = statsConnection.SessionID }; // Ask for events to be delivered. statsConnection.SubscribeForEvents(subscriptionRequest); break; } }
/// <summary>Method which when a StatsConnection is established requests Interface statistics.</summary> /// <param name="sender">The source of the event.</param> /// <param name="connectionStatus">The <see cref="StatsConnection"/>'s new <see cref="StatsConnection.ConnectionStatus"/>.</param> private static void Connection_ConnectionStatusChanged(object sender, StatsConnection.ConnectionStatus connectionStatus) { // The sender should be a StatsConnection so that we can interact with that StatsConnection instance. StatsConnection statsConnection = sender as StatsConnection; if (statsConnection == null) { return; } // Specifically what did the ConnectionStatus change to? switch (connectionStatus) { // It was previously not connected and now it is. case StatsConnection.ConnectionStatus.Connected: // Compose a subscription request message. SubscriptionRequest subscriptionRequest = new SubscriptionRequest { Subscribe = new Subscription[] { new Subscription() { name = SubscriptionMessageType.LogFeed } }, SessionID = statsConnection.SessionID }; // Ask for events to be delivered. statsConnection.SubscribeForEvents(subscriptionRequest); // Start the heartbeat timer. sessionHeartbeatTimer.Enabled = true; break; // The router has disconnected (usually due to session expiry due to lack of heartbeats). case StatsConnection.ConnectionStatus.DisconnectedByHost: // Stop the heartbeat timer. sessionHeartbeatTimer.Enabled = false; // Just close this program. WantToQuit.Set(); break; } }