Example #1
0
 static void Connection_Disconnected(object sender, DisconnectedEventArgs e)
 {
     e.Retry = e.RetryCount < 6;
 }
Example #2
0
 /// <summary>
 /// Fires the Disconnected event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 protected virtual void OnDisconnected(DisconnectedEventArgs e)
 {
     Disconnected?.Invoke(this, e);
 }
Example #3
0
        /// <summary>
        /// Will be called from polling timer on every interval.
        /// </summary>
        /// <param name="state">State (not used)</param>
        internal void SendHeartbeat(object state)
        {
            if (_sendingHeartbeat)
            {
                // if polling timer interval is less than
                // channel timeout, skip sending a heartbeat
                return;
            }

            try
            {
                _sendingHeartbeat = true;
                try
                {
                    PrepareCallContext(false);
                    RemoteDispatcher.ReceiveClientHeartbeat(_sessionID);
                }
                finally
                {
                    _sendingHeartbeat = false;
                }
            }
            catch (Exception ex)
            {
                PollingEnabled = false;
                bool problemSolved = false;

                DisconnectedEventArgs e = new DisconnectedEventArgs()
                {
                    Exception  = ex,
                    RetryCount = 0,
                    Retry      = false
                };

                OnDisconnected(e);

                while (e.Retry)
                {
                    e.Retry = false;

                    Thread.Sleep(Convert.ToInt32(_pollingInterval.TotalMilliseconds));

                    try
                    {
                        problemSolved = InternalReconnect();
                    }
                    catch (Exception retryEx)
                    {
                        e.Exception = retryEx;
                        e.RetryCount++;
                        OnDisconnected(e);
                    }
                }

                if (problemSolved)
                {
                    PollingEnabled = true;
                    OnReconnected(EventArgs.Empty);
                }
                else
                {
                    // connection wasn't restored, make sure
                    // that the polling timer is stopped
                    PollingEnabled = false;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Will be called from polling timer on every interval.
        /// </summary>
        /// <param name="state">State (not used)</param>
        internal void SendHeartbeat(object state)
        {
            if (_sendingHeartbeat)
            {
                // if polling timer interval is less than
                // channel timeout, skip sending a heartbeat
                return;
            }

            try
            {
                _sendingHeartbeat = true;
                try
                {
                    _transportAdapter.SendRequest(new RequestMessage()
                    {
                        RequestType     = RequestType.SystemOperation,
                        MethodName      = "ReceiveClientHeartbeat",
                        Address         = _serverUrl,
                        ParameterValues = new object[] { _sessionID },
                        CallContext     = PrepareCallContext(false)
                    });
                    //RemoteDispatcher.ReceiveClientHeartbeat(_sessionID);
                }
                finally
                {
                    _sendingHeartbeat = false;
                }
            }
            catch (Exception ex)
            {
                PollingEnabled = false;
                bool problemSolved = false;

                DisconnectedEventArgs e = new DisconnectedEventArgs()
                {
                    Exception  = ex,
                    RetryCount = 0,
                    Retry      = false
                };

                OnDisconnected(e);

                while (e.Retry)
                {
                    e.Retry = false;

                    Thread.Sleep(Convert.ToInt32(_pollingInterval.TotalMilliseconds));

                    try
                    {
                        problemSolved = InternalReconnect();
                    }
                    catch (Exception retryEx)
                    {
                        e.Exception = retryEx;
                        e.RetryCount++;
                        OnDisconnected(e);
                    }
                }

                if (problemSolved)
                {
                    PollingEnabled = true;
                    OnReconnected(EventArgs.Empty);
                }
                else
                {
                    // connection wasn't restored, make sure
                    // that the polling timer is stopped
                    PollingEnabled = false;
                }
            }
        }