当前位置: 首页>>代码示例>>C#>>正文


C# IConnection.EnsureReconnecting方法代码示例

本文整理汇总了C#中IConnection.EnsureReconnecting方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.EnsureReconnecting方法的具体用法?C# IConnection.EnsureReconnecting怎么用?C# IConnection.EnsureReconnecting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnection的用法示例。


在下文中一共展示了IConnection.EnsureReconnecting方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reconnect

        private void Reconnect(IConnection connection, string data, CancellationToken disconnectToken)
        {
            // Need to verify before the task delay occurs because an application sleep could occur during the delayed duration.
            if (!TransportHelper.VerifyLastActive(connection))
            {
                return;
            }

            // Wait for a bit before reconnecting
            TaskAsyncHelper.Delay(ReconnectDelay).Then(() =>
            {
                if (!TransportHelper.VerifyLastActive(connection))
                {
                    return;
                }

                // FIX: Race if Connection is stopped and completely restarted between checking the token and calling
                //      connection.EnsureReconnecting()
                if (!disconnectToken.IsCancellationRequested && connection.EnsureReconnecting())
                {
                    // Now attempt a reconnect
                    OpenConnection(connection, data, disconnectToken, reconnecting: true);
                }
            });
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:25,代码来源:ServerSentEventsTransport.cs

示例2: Reconnect

 private void Reconnect(IConnection connection, string data, CancellationToken disconnectToken)
 {
     // Wait for a bit before reconnecting
     TaskAsyncHelper.Delay(ReconnectDelay).Then(() =>
     {
         // FIX: Race if Connection is stopped and completely restarted between checking the token and calling
         //      connection.EnsureReconnecting()
         if (!disconnectToken.IsCancellationRequested && connection.EnsureReconnecting())
         {
             // Now attempt a reconnect
             OpenConnection(connection, data, disconnectToken, initializeCallback: null, errorCallback: null);
         }
     });
 }
开发者ID:fszlin,项目名称:Nivot.SignalR.Client.Net35,代码行数:14,代码来源:ServerSentEventsTransport.cs

示例3: LostConnection

 /// <summary>
 /// Aborts the currently active polling request thereby forcing a reconnect.
 /// </summary>
 public override void LostConnection(IConnection connection)
 {
     if (connection.EnsureReconnecting())
     {
         lock (_stopLock)
         {
             if (_currentRequest != null)
             {
                 _currentRequest.Abort();
             }
         }
     }
 }
开发者ID:kietnha,项目名称:SignalR,代码行数:16,代码来源:LongPollingTransport.cs

示例4: OnError

        // internal virtual for testing
        internal virtual void OnError(IConnection connection, Exception exception)
        {
            TransportFailed(exception);
            _reconnectInvoker.Invoke();

            if (!TransportHelper.VerifyLastActive(connection))
            {
                StopPolling();
            }

            // Transition into reconnecting state
            connection.EnsureReconnecting();

            // Sometimes a connection might have been closed by the server before we get to write anything
            // so just try again and raise OnError.
            if (!ExceptionHelper.IsRequestAborted(exception) && !(exception is IOException))
            {
                connection.OnError(exception);
            }
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:21,代码来源:LongPollingTransport.cs

示例5: OnMessage

        private void OnMessage(IConnection connection, string message)
        {
            connection.Trace(TraceLevels.Messages, "LP: OnMessage({0})", message);

            var shouldReconnect = ProcessResponse(connection, message);

            if (IsReconnecting(connection))
            {
                // If the timeout for the reconnect hasn't fired as yet just fire the 
                // event here before any incoming messages are processed
                TryReconnect(connection, _reconnectInvoker);
            }

            if (shouldReconnect)
            {
                // Transition into reconnecting state
                connection.EnsureReconnecting();
            }
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:19,代码来源:LongPollingTransport.cs

示例6: Reconnect

        // internal for testing
        internal async Task Reconnect(IConnection connection, string connectionData)
        {
            var reconnectUrl = UrlBuilder.BuildReconnect(connection, Name, connectionData);

            while (TransportHelper.VerifyLastActive(connection) && connection.EnsureReconnecting() && !_disconnectToken.IsCancellationRequested)
            {
                try
                {
                    await StartWebSocket(connection, reconnectUrl);

                    if (connection.ChangeState(ConnectionState.Reconnecting, ConnectionState.Connected))
                    {
                        connection.OnReconnected();
                    }

                    break;
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception ex)
                {
                    connection.OnError(ex);
                }

                await Task.Delay(ReconnectDelay);
            }
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:30,代码来源:WebSocketTransport.cs

示例7: PollingLoop

        private void PollingLoop(IConnection connection,
                                 string data,
                                 CancellationToken disconnectToken,
                                 Action initializeCallback,
                                 Action<Exception> errorCallback,
                                 bool raiseReconnect = false)
        {
            string url = connection.Url;

            IRequest request = null;
            var reconnectInvoker = new ThreadSafeInvoker();
            var callbackInvoker = new ThreadSafeInvoker();
            var requestDisposer = new Disposer();

            if (connection.MessageId == null)
            {
                url += "connect";
            }
            else if (raiseReconnect)
            {
                url += "reconnect";

                // FIX: Race if the connection is stopped and completely restarted between checking the token and calling
                //      connection.EnsureReconnecting()
                if (disconnectToken.IsCancellationRequested || !connection.EnsureReconnecting())
                {
                    return;
                }
            }

            url += GetReceiveQueryString(connection, data);

            #if NET35
            Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "LP: {0}", (object)url));
            #else
            Debug.WriteLine("LP: {0}", (object)url);
            #endif

            HttpClient.Post(url, req =>
            {
                request = req;
                connection.PrepareRequest(request);
            }).ContinueWith(task =>
            {
                bool shouldRaiseReconnect = false;
                bool disconnectedReceived = false;

                try
                {
                    if (!task.IsFaulted)
                    {
                        if (raiseReconnect)
                        {
                            // If the timeout for the reconnect hasn't fired as yet just fire the
                            // event here before any incoming messages are processed
                            reconnectInvoker.Invoke((conn) => FireReconnected(conn), connection);
                        }

                        if (initializeCallback != null)
                        {
                            // If the timeout for connect hasn't fired as yet then just fire
                            // the event before any incoming messages are processed
                            callbackInvoker.Invoke(initializeCallback);
                        }

                        // Get the response
                        var raw = task.Result.ReadAsString();

            #if NET35
                        Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "LP Receive: {0}", (object)raw));
            #else
                        Debug.WriteLine("LP Receive: {0}", (object)raw);
            #endif
                        TransportHelper.ProcessResponse(connection,
                                                        raw,
                                                        out shouldRaiseReconnect,
                                                        out disconnectedReceived);
                    }
                }
                finally
                {
                    if (disconnectedReceived)
                    {
                        connection.Disconnect();
                    }
                    else
                    {
                        bool requestAborted = false;

                        if (task.IsFaulted)
                        {
                            reconnectInvoker.Invoke();

                            // Raise the reconnect event if we successfully reconnect after failing
                            shouldRaiseReconnect = true;

                            // Get the underlying exception
                            Exception exception = task.Exception.Unwrap();

                            // If the error callback isn't null then raise it and don't continue polling
//.........这里部分代码省略.........
开发者ID:stirno,项目名称:SignalR,代码行数:101,代码来源:LongPollingTransport.cs

示例8: PollingSetup

        private void PollingSetup(IConnection connection,
                                  string data,
                                  CancellationToken disconnectToken,
                                  PollingRequestHandler requestHandler,
                                  Action onInitialized)
        {
            // reconnectInvoker is created new on each poll
            var reconnectInvoker = new ThreadSafeInvoker();

            var disconnectRegistration = disconnectToken.SafeRegister(state =>
            {
                reconnectInvoker.Invoke();
                requestHandler.Stop();
            }, null);

            requestHandler.ResolveUrl = () =>
            {
                var url = connection.Url;

                if (connection.MessageId == null)
                {
                    url += "connect";
                    connection.Trace(TraceLevels.Events, "LP Connect: {0}", url);
                }
                else if (IsReconnecting(connection))
                {
                    url += "reconnect";
                    connection.Trace(TraceLevels.Events, "LP Reconnect: {0}", url);
                }
                else
                {
                    url += "poll";
                    connection.Trace(TraceLevels.Events, "LP Poll: {0}", url);
                }

                url += GetReceiveQueryString(connection, data);

                return url;
            };

            requestHandler.PrepareRequest += req =>
            {
                connection.PrepareRequest(req);
            };

            requestHandler.OnMessage += message =>
            {
                var shouldReconnect = false;
                var disconnectedReceived = false;

                connection.Trace(TraceLevels.Messages, "LP: OnMessage({0})", message);

                TransportHelper.ProcessResponse(connection,
                                                message,
                                                out shouldReconnect,
                                                out disconnectedReceived,
                                                onInitialized);

                if (IsReconnecting(connection))
                {
                    // If the timeout for the reconnect hasn't fired as yet just fire the 
                    // event here before any incoming messages are processed
                    TryReconnect(connection, reconnectInvoker);
                }

                if (shouldReconnect)
                {
                    // Transition into reconnecting state
                    connection.EnsureReconnecting();
                }

                if (disconnectedReceived)
                {
                    connection.Disconnect();
                }
            };

            requestHandler.OnError += exception =>
            {
                reconnectInvoker.Invoke();

                // Transition into reconnecting state
                connection.EnsureReconnecting();

                // Sometimes a connection might have been closed by the server before we get to write anything
                // so just try again and raise OnError.
                if (!ExceptionHelper.IsRequestAborted(exception) && !(exception is IOException))
                {
                    connection.OnError(exception);
                }
                else
                {
                    requestHandler.Stop();
                }
            };

            requestHandler.OnPolling += () =>
            {
                // Capture the cleanup within a closure so it can persist through multiple requests
                TryDelayedReconnect(connection, reconnectInvoker);
//.........这里部分代码省略.........
开发者ID:fszlin,项目名称:Nivot.SignalR.Client.Net35,代码行数:101,代码来源:LongPollingTransport.cs

示例9: LostConnection

 public override void LostConnection(IConnection connection)
 {
     if (connection.EnsureReconnecting())
     {
         _requestHandler.LostConnection();
     }
 }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:7,代码来源:LongPollingTransport.cs


注:本文中的IConnection.EnsureReconnecting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。