Exemplo n.º 1
0
 static void Connection_Disconnected(object sender, DisconnectedEventArgs e)
 {
     e.Retry = e.RetryCount < 6;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Fires the Disconnected event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 protected virtual void OnDisconnected(DisconnectedEventArgs e)
 {
     Disconnected?.Invoke(this, e);
 }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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;
                }
            }
        }