• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ITransportConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ITransportConnection的典型用法代码示例。如果您正苦于以下问题:C# ITransportConnection类的具体用法?C# ITransportConnection怎么用?C# ITransportConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ITransportConnection类属于命名空间,在下文中一共展示了ITransportConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

        public override Task ProcessRequest(ITransportConnection connection)
        {
            return _context.Request.AcceptWebSocketRequest(socket =>
            {
                _socket = socket;

                socket.OnClose = clean =>
                {
                    // If we performed a clean disconnect then we go through the normal disconnect routine.  However,
                    // If we performed an unclean disconnect we want to mark the connection as "not alive" and let the
                    // HeartBeat clean it up.  This is to maintain consistency across the transports.
                    if (clean)
                    {
                        OnDisconnect();
                    }

                    _isAlive = false;
                };

                socket.OnMessage = message =>
                {
                    OnReceiving(message);

                    if (Received != null)
                    {
                        Received(message).Catch();
                    }
                };

                return ProcessRequestCore(connection);
            });
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:32,代码来源:WebSocketTransport.cs


示例2: ProcessRequest

        public override Task ProcessRequest(ITransportConnection connection)
        {
            return _context.Request.AcceptWebSocketRequest(socket =>
            {
                _socket = socket;

                socket.OnClose = () =>
                {
                    OnDisconnect();

                    _isAlive = false;
                };

                socket.OnMessage = message =>
                {
                    OnReceiving(message);

                    if (Received != null)
                    {
                        Received(message).Catch();
                    }
                };

                return ProcessRequestCore(connection);
            });
        }
开发者ID:TSASoftware,项目名称:SignalR,代码行数:26,代码来源:WebSocketTransport.cs


示例3: ConnectionRun

 public ConnectionRun(RunData runData)
     : base(runData)
 {
     var connectionManager = new ConnectionManager(Resolver);
     _context = connectionManager.GetConnectionContext<StressConnection>();
     _transportConnection = (ITransportConnection)_context.Connection;
 }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:7,代码来源:ConnectionRun.cs


示例4: ProcessRequest

        public override Task ProcessRequest(ITransportConnection connection)
        {
            if (IsAbortRequest)
            {
                return connection.Abort(ConnectionId);
            }
            else
            {
                var webSocketRequest = _context.Request as IWebSocketRequest;

                // Throw if the server implementation doesn't support websockets
                if (webSocketRequest == null)
                {
                    throw new InvalidOperationException(Resources.Error_WebSocketsNotSupported);
                }

                Connection = connection;
                InitializePersistentState();

                return webSocketRequest.AcceptWebSocketRequest(socket =>
                {
                    _socket = socket;
                    socket.OnClose = _closed;
                    socket.OnMessage = _message;
                    socket.OnError = _error;

                    return ProcessReceiveRequest(connection);
                },
                InitializeTcs.Task);
            }
        }
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:31,代码来源:WebSocketTransport.cs


示例5: InitializeResponse

 protected override Task InitializeResponse(ITransportConnection connection)
 {
     return base.InitializeResponse(connection)
                .Then(() =>
                {
                    Context.Response.ContentType = "text/event-stream";
                    return Context.Response.WriteAsync("data: initialized\n\n");
                });
 }
开发者ID:kristineyu,项目名称:SignalR,代码行数:9,代码来源:ServerSentEventsTransport.cs


示例6: InitializeResponse

 protected override Task InitializeResponse(ITransportConnection connection)
 {
     return base.InitializeResponse(connection)
         .Then(initScript =>
         {
             Context.Response.ContentType = "text/html";
             Context.Response.WriteAsync(initScript);
         },
         _initPrefix + Context.Request.QueryString["frameId"] + _initSuffix);
 }
开发者ID:nairit,项目名称:SignalR,代码行数:10,代码来源:ForeverFrameTransport.cs


示例7: SendCommand

        private static Task SendCommand(ITransportConnection connection, string connectionId, CommandType commandType)
        {
            var command = new Command
            {
                CommandType = commandType
            };

            var message = new ConnectionMessage(PrefixHelper.GetConnectionId(connectionId),
                                                command);

            return connection.Send(message);
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:12,代码来源:TransportConnectionExtensions.cs


示例8: InitializeResponse

        protected override Task InitializeResponse(ITransportConnection connection)
        {
            return base.InitializeResponse(connection)
                       .Then(() =>
                       {
                           Context.Response.ContentType = "text/event-stream";

                           // "data: initialized\n\n"
                           OutputWriter.WriteLine("data: initialized");
                           OutputWriter.WriteLine();
                           OutputWriter.WriteLine();
                           OutputWriter.Flush();
                       });
        }
开发者ID:thoughtentity,项目名称:SignalR,代码行数:14,代码来源:ServerSentEventsTransport.cs


示例9: InitializeResponse

        protected override Task InitializeResponse(ITransportConnection connection)
        {
            return base.InitializeResponse(connection)
                .Then(initScript =>
                {
                    Context.Response.ContentType = "text/html";

                    return EnqueueOperation(() =>
                    {
                        OutputWriter.Write(initScript);
                        OutputWriter.Flush();

                        return Context.Response.FlushAsync();
                    });
                },
                _initPrefix + Context.Request.QueryString["frameId"] + _initSuffix);
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:17,代码来源:ForeverFrameTransport.cs


示例10: ProcessRequestCore

        protected async Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                await ProcessSendRequest().PreserveCulture();
            }
            else if (IsAbortRequest)
            {
                await Connection.Abort(ConnectionId).PreserveCulture();
            }
            else
            {
                await InitializePersistentState().PreserveCulture();
                await ProcessReceiveRequest(connection).PreserveCulture();
            }
        }
开发者ID:bestwpw,项目名称:SignalR-Server,代码行数:18,代码来源:ForeverTransport.cs


示例11: InitializeResponse

        protected internal override Task InitializeResponse(ITransportConnection connection)
        {
            uint frameId;
            string rawFrameId = Context.Request.QueryString["frameId"];
            if (String.IsNullOrWhiteSpace(rawFrameId) || !UInt32.TryParse(rawFrameId, NumberStyles.None, CultureInfo.InvariantCulture, out frameId))
            {
                // Invalid frameId passed in
                throw new InvalidOperationException(Resources.Error_InvalidForeverFrameId);
            }

            string initScript = _initPrefix +
                                frameId.ToString(CultureInfo.InvariantCulture) +
                                _initSuffix;

            var context = new ForeverFrameTransportContext(this, initScript);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return base.InitializeResponse(connection).Then(s => Initialize(s), context);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:19,代码来源:ForeverFrameTransport.cs


示例12: ProcessRequest

        public override Task ProcessRequest(ITransportConnection connection)
        {
            if (IsAbortRequest)
            {
                return connection.Abort(ConnectionId);
            }
            else
            {
                return AcceptWebSocketRequest(socket =>
                {
                    _socket = socket;
                    socket.OnClose = _closed;
                    socket.OnMessage = _message;
                    socket.OnError = _error;

                    return ProcessRequestCore(connection);
                });
            }
        }
开发者ID:nirmana,项目名称:SignalR,代码行数:19,代码来源:WebSocketTransport.cs


示例13: ProcessRequest

        public override Task ProcessRequest(ITransportConnection connection)
        {
            var webSocketRequest = _context.Request as IWebSocketRequest;

            // Throw if the server implementation doesn't support websockets
            if (webSocketRequest == null)
            {
                throw new InvalidOperationException(Resources.Error_WebSocketsNotSupported);
            }

            return webSocketRequest.AcceptWebSocketRequest(socket =>
            {
                _socket = socket;

                socket.OnClose = clean =>
                {
                    Trace.TraceInformation("CloseSocket({0}, {1})", clean, ConnectionId);

                    // If we performed a clean disconnect then we go through the normal disconnect routine.  However,
                    // If we performed an unclean disconnect we want to mark the connection as "not alive" and let the
                    // HeartBeat clean it up.  This is to maintain consistency across the transports.
                    if (clean)
                    {
                        OnDisconnect();
                    }

                    _isAlive = false;
                };

                socket.OnMessage = message =>
                {
                    if (Received != null)
                    {
                        Received(message).Catch();
                    }
                };

                return ProcessRequestCore(connection);
            });
        }
开发者ID:stirno,项目名称:SignalR,代码行数:40,代码来源:WebSocketTransport.cs


示例14: ProcessMessages

        private Task ProcessMessages(ITransportConnection connection, Func<Task> postReceive = null)
        {
            var tcs = new TaskCompletionSource<object>();

            Action<Exception> endRequest = (ex) =>
            {
                if (ex != null)
                {
                    tcs.TrySetException(ex);
                }
                else
                {
                    tcs.TrySetResult(null);
                }

                CompleteRequest();
            };

            ProcessMessages(connection, postReceive, endRequest);

            return tcs.Task;
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:22,代码来源:ForeverTransport.cs


示例15: ProcessRequestCore

        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (Context.Request.Url.LocalPath.EndsWith("/send"))
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort(ConnectionId);
            }
            else
            {
                InitializePersistentState();

                if (IsConnectRequest)
                {
                    if (Connected != null)
                    {
                        // Return a task that completes when the connected event task & the receive loop task are both finished
                        bool newConnection = HeartBeat.AddConnection(this);
                        return TaskAsyncHelper.Interleave(ProcessReceiveRequestWithoutTracking, () =>
                        {
                            if (newConnection)
                            {
                                return Connected().Then(() => _counters.ConnectionsConnected.Increment());
                            }
                            return TaskAsyncHelper.Empty;
                        }
                        , connection, Completed);
                    }

                    return ProcessReceiveRequest(connection);
                }

                if (Reconnected != null)
                {
                    // Return a task that completes when the reconnected event task & the receive loop task are both finished
                    Func<Task> reconnected = () => Reconnected().Then(() => _counters.ConnectionsReconnected.Increment());
                    return TaskAsyncHelper.Interleave(ProcessReceiveRequest, reconnected, connection, Completed);
                }

                return ProcessReceiveRequest(connection);
            }
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:46,代码来源:ForeverTransport.cs


示例16: InitializeResponse

 protected virtual Task InitializeResponse(ITransportConnection connection)
 {
     return TaskAsyncHelper.Empty;
 }
开发者ID:nonintanon,项目名称:SignalR,代码行数:4,代码来源:ForeverTransport.cs


示例17: ProcessRequest

 public virtual Task ProcessRequest(ITransportConnection connection)
 {
     return ProcessRequestCore(connection);
 }
开发者ID:nonintanon,项目名称:SignalR,代码行数:4,代码来源:ForeverTransport.cs


示例18: ProcessReceiveRequestWithoutTracking

        private Task ProcessReceiveRequestWithoutTracking(ITransportConnection connection, Action postReceive = null)
        {
            if (TransportConnected != null)
            {
                TransportConnected().Catch();
            }

            // ReceiveAsync() will async wait until a message arrives then return
            var receiveTask = IsConnectRequest ?
                              connection.ReceiveAsync(null, ConnectionEndToken, MessageBufferSize) :
                              connection.ReceiveAsync(MessageId, ConnectionEndToken, MessageBufferSize);

            if (postReceive != null)
            {
                postReceive();
            }

            return receiveTask.Then(response =>
            {
                response.TimedOut = IsTimedOut;

                if (response.Aborted)
                {
                    // If this was a clean disconnect then raise the event
                    OnDisconnect();
                }

                return Send(response);
            });
        }
开发者ID:thoughtentity,项目名称:SignalR,代码行数:30,代码来源:LongPollingTransport.cs


示例19: ReceiveLoop

        private static void ReceiveLoop(ITransportConnection connection, string messageId)
        {
            connection.ReceiveAsync(messageId, CancellationToken.None, maxMessages: 5000).Then(r =>
            {
                Interlocked.Add(ref _received, r.TotalCount);
                Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);

                ReceiveLoop(connection, r.MessageId);
            });
        }
开发者ID:neiz,项目名称:SignalR,代码行数:10,代码来源:Program.cs


示例20: ProcessReceiveRequest

 private Task ProcessReceiveRequest(ITransportConnection connection, Func<Task> postReceive = null)
 {
     Heartbeat.AddConnection(this);
     return ProcessReceiveRequestWithoutTracking(connection, postReceive);
 }
开发者ID:bjarteskogoy,项目名称:SignalR,代码行数:5,代码来源:LongPollingTransport.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ITransportHeaders类代码示例发布时间:2022-05-24
下一篇:
C# ITransport类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap