Example #1
0
        private void TryToRestartLostConnection(ConnectionInternal connection)
        {
            if (!this.userSettings.Settings.RestartLostConnections ||
                connection.SequencedFailsCount > this.userSettings.Settings.AttemptsToRestartLostConnection)
            {
                return;
            }

            var restartInterval = this.userSettings.Settings.LostConnectionRestartInterval;

            if (restartInterval == TimeSpan.Zero)
            {
                this.BroadcastMessage(connection.Connection.Info, MessageSeverity.Info, "Attempting to reconnect...");
                connection.Connection.Open();
            }
            else
            {
                // ReSharper disable once NotAccessedVariable
                Timer timer;
                timer = new Timer(
                    s =>
                {
                    timer = null;
                    lock (this.syncObject)
                    {
                        this.BroadcastMessage(connection.Connection.Info, MessageSeverity.Info, "Attempting to reconnect...");
                        this.pendingConnections.Add(connection);
                        connection.Connection.Open();
                    }
                },
                    null,
                    (long)restartInterval.TotalMilliseconds,
                    -1);

                var seconds  = restartInterval.TotalSeconds;
                var timePart = seconds / 60 > 0
                    ? string.Format("{0} minute(s)", (int)Math.Ceiling(seconds / 60.0))
                    : string.Format("{0} second(s)", seconds);
                this.BroadcastMessage(
                    connection.Connection.Info,
                    MessageSeverity.Info,
                    string.Format("A reconnection attempt will be made in {0}...", timePart));
            }
        }
        private void TryToRestartLostConnection(ConnectionInternal connection)
        {
            if (!this.userSettings.Settings.RestartLostConnections ||
                connection.SequencedFailsCount > this.userSettings.Settings.AttemptsToRestartLostConnection)
            {
                return;
            }

            var restartInterval = this.userSettings.Settings.LostConnectionRestartInterval;
            if (restartInterval == TimeSpan.Zero)
            {
                this.BroadcastMessage(connection.Connection.Info, MessageSeverity.Info, "Attempting to reconnect...");
                connection.Connection.Open();
            }
            else
            {
                // ReSharper disable once NotAccessedVariable
                Timer timer;
                timer = new Timer(
                    s =>
                    {
                        timer = null;
                        lock (this.syncObject)
                        {
                            this.BroadcastMessage(connection.Connection.Info, MessageSeverity.Info, "Attempting to reconnect...");
                            this.pendingConnections.Add(connection);
                            connection.Connection.Open();
                        }
                    },
                    null,
                    (long)restartInterval.TotalMilliseconds,
                    -1);

                var seconds = restartInterval.TotalSeconds;
                var timePart = seconds / 60 > 0
                    ? string.Format("{0} minute(s)", (int)Math.Ceiling(seconds / 60.0))
                    : string.Format("{0} second(s)", seconds);
                this.BroadcastMessage(
                    connection.Connection.Info,
                    MessageSeverity.Info,
                    string.Format("A reconnection attempt will be made in {0}...", timePart));
            }
        }