コード例 #1
0
ファイル: Program.cs プロジェクト: yallie/zyan
 static void Connection_Disconnected(object sender, DisconnectedEventArgs e)
 {
     e.Retry = e.RetryCount < 6;
 }
コード例 #2
0
ファイル: ZyanConnection.cs プロジェクト: xiaoxiongnpu/Zyan
 /// <summary>
 /// Fires the Disconnected event.
 /// </summary>
 /// <param name="e">Event arguments.</param>
 protected virtual void OnDisconnected(DisconnectedEventArgs e)
 {
     Disconnected?.Invoke(this, e);
 }
コード例 #3
0
ファイル: ZyanConnection.cs プロジェクト: xiaoxiongnpu/Zyan
        /// <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;
                }
            }
        }
コード例 #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;
                }
            }
        }