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


C# ITransport.ProcessRequest方法代码示例

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


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

示例1: ProcessRequestAsync

        public override Task ProcessRequestAsync(HttpContext context)
        {
            Task task = null;
            var contextBase = new HttpContextWrapper(context);

            if (IsNegotiationRequest(context.Request))
            {
                context.Response.ContentType = Json.MimeType;
                context.Response.Write(_jsonSerializer.Stringify(new
                {
                    Url = VirtualPathUtility.ToAbsolute(context.Request.AppRelativeCurrentExecutionFilePath.Replace("/negotiate", "")),
                    ClientId = _clientIdFactory.CreateClientId(contextBase)
                }));
            }
            else
            {
                _transport = GetTransport(contextBase);

                string clientId = contextBase.Request["clientId"];

                // If there's no client id then this is a bad request
                if (String.IsNullOrEmpty(clientId))
                {
                    throw new InvalidOperationException("Protcol error: Missing client id.");
                }

                IEnumerable<string> groups = GetGroups(contextBase);

                Connection = CreateConnection(clientId, groups, contextBase);

                // Wire up the events we need
                _transport.Connected += () =>
                {
                    task = OnConnectedAsync(contextBase, clientId);
                };

                _transport.Received += (data) =>
                {
                    task = OnReceivedAsync(clientId, data);
                };

                _transport.Error += (e) =>
                {
                    task = OnErrorAsync(e);
                };

                _transport.Disconnected += () =>
                {
                    task = OnDisconnectAsync(clientId);
                };

                Func<Task> processRequestTask = _transport.ProcessRequest(Connection);

                if (processRequestTask != null)
                {
                    if (task != null)
                    {
                        return task.Success(_ => processRequestTask()).Unwrap();
                    }
                    return processRequestTask();
                }
            }

            return task ?? TaskAsyncHelper.Empty;
        }
开发者ID:Rustemt,项目名称:SignalR,代码行数:65,代码来源:PersistentConnection.cs

示例2: ProcessRequestAsync

        /// <summary>
        /// Handles all requests for <see cref="PersistentConnection"/>s.
        /// </summary>
        /// <param name="context">The <see cref="HostContext"/> for the current request.</param>
        /// <returns>A <see cref="Task"/> that completes when the <see cref="PersistentConnection"/> pipeline is complete.</returns>
        /// <exception cref="T:System.InvalidOperationException">
        /// Thrown if connection wasn't initialized.
        /// Thrown if the transport wasn't specified.
        /// Thrown if the connection id wasn't specified.
        /// </exception>
        public virtual Task ProcessRequestAsync(HostContext context)
        {
            if (!_initialized)
            {
                throw new InvalidOperationException("Connection not initialized.");
            }

            if (IsNegotiationRequest(context.Request))
            {
                return ProcessNegotiationRequest(context);
            }

            _transport = GetTransport(context);

            if (_transport == null)
            {
                throw new InvalidOperationException("Protocol error: Unknown transport.");
            }

            string connectionId = _transport.ConnectionId;

            // If there's no connection id then this is a bad request
            if (String.IsNullOrEmpty(connectionId))
            {
                throw new InvalidOperationException("Protocol error: Missing connection id.");
            }

            var groups = new List<string>(_transport.Groups);

            Connection connection = CreateConnection(connectionId, groups, context.Request);

            Connection = connection;
            Groups = new GroupManager(connection, DefaultSignal);

            _transport.TransportConnected = () =>
            {
                var command = new ServerCommand
                {
                    Type = ServerCommandType.RemoveConnection,
                    Value = connectionId
                };

                return _serverMessageHandler.SendCommand(command);
            };

            _transport.Connected = () =>
            {
                return OnConnectedAsync(context.Request, connectionId);
            };

            _transport.Reconnected = () =>
            {
                return OnReconnectedAsync(context.Request, groups, connectionId);
            };

            _transport.Received = data =>
            {
                return OnReceivedAsync(context.Request, connectionId, data);
            };

            _transport.Error = OnErrorAsync;

            _transport.Disconnected = () =>
            {
                return OnDisconnectAsync(connectionId);
            };

            return _transport.ProcessRequest(connection) ?? TaskAsyncHelper.Empty;
        }
开发者ID:nairit,项目名称:SignalR,代码行数:79,代码来源:PersistentConnection.cs

示例3: ProcessRequestAsync

        public virtual Task ProcessRequestAsync(HostContext context)
        {
            if (IsNegotiationRequest(context.Request))
            {
                return ProcessNegotiationRequest(context);
            }

            _transport = GetTransport(context);

            if (_transport == null)
            {
                throw new InvalidOperationException("Unknown transport.");
            }

            string connectionId = _transport.ConnectionId;

            // If there's no connection id then this is a bad request
            if (String.IsNullOrEmpty(connectionId))
            {
                throw new InvalidOperationException("Protocol error: Missing connection id.");
            }

            IEnumerable<string> groups = _transport.Groups;

            Connection = CreateConnection(connectionId, groups, context.Request);

            _transport.Connected = () =>
            {
                return OnConnectedAsync(context.Request, connectionId);
            };

            _transport.Received = data =>
            {
                return OnReceivedAsync(connectionId, data);
            };

            _transport.Error = OnErrorAsync;

            _transport.Disconnected = () =>
            {
                return OnDisconnectAsync(connectionId);
            };

            return _transport.ProcessRequest(Connection) ?? TaskAsyncHelper.Empty;
        }
开发者ID:neilkinnish,项目名称:SignalR,代码行数:45,代码来源:PersistentConnection.cs

示例4: ProcessRequestAsync

        public override Task ProcessRequestAsync(HttpContext context)
        {
            Task task = null;

            if (IsNegotiationRequest(context.Request)) {
                context.Response.ContentType = Json.MimeType;
                context.Response.Write(_jsonStringifier.Stringify(new {
                    Url = VirtualPathUtility.ToAbsolute(context.Request.AppRelativeCurrentExecutionFilePath.Replace("/negotiate", "")),
                    ClientId = Guid.NewGuid().ToString("d")
                }));
            }
            else {
                var contextBase = new HttpContextWrapper(context);
                _transport = GetTransport(contextBase);

                string clientId = contextBase.Request["clientId"];
                IEnumerable<string> groups = GetGroups(contextBase);

                Connection = CreateConnection(clientId, groups, contextBase);

                // Wire up the events we needs
                _transport.Connected += () => {
                    OnConnected(contextBase, clientId);
                };

                _transport.Received += (data) => {
                    task = OnReceivedAsync(clientId, data);
                };

                _transport.Error += (e) => {
                    OnError(e);
                };

                _transport.Disconnected += () => {
                    OnDisconnect(clientId);
                };

                var processRequestTask = _transport.ProcessRequest(Connection);

                if (processRequestTask != null) {
                    return processRequestTask;
                }
            }

            return task ?? TaskAsyncHelper.Empty;
        }
开发者ID:JamesTryand,项目名称:SignalR,代码行数:46,代码来源:PersistentConnection.cs

示例5: ProcessRequestAsync

        /// <summary>
        /// Handles all requests for <see cref="PersistentConnection"/>s.
        /// </summary>
        /// <param name="context">The <see cref="HostContext"/> for the current request.</param>
        /// <returns>A <see cref="Task"/> that completes when the <see cref="PersistentConnection"/> pipeline is complete.</returns>
        /// <exception cref="T:System.InvalidOperationException">
        /// Thrown if connection wasn't initialized.
        /// Thrown if the transport wasn't specified.
        /// Thrown if the connection id wasn't specified.
        /// </exception>
        public virtual Task ProcessRequestAsync(HostContext context)
        {
            if (!_initialized)
            {
                throw new InvalidOperationException("Connection not initialized.");
            }

            if (IsNegotiationRequest(context.Request))
            {
                return ProcessNegotiationRequest(context);
            }

            _transport = GetTransport(context);

            if (_transport == null)
            {
                throw new InvalidOperationException("Protocol error: Unknown transport.");
            }

            string connectionId = _transport.ConnectionId;

            // If there's no connection id then this is a bad request
            if (String.IsNullOrEmpty(connectionId))
            {
                throw new InvalidOperationException("Protocol error: Missing connection id.");
            }

            IEnumerable<string> signals = GetSignals(connectionId);
            IEnumerable<string> groups = OnRejoiningGroups(context.Request, _transport.Groups, connectionId);

            Connection connection = CreateConnection(connectionId, signals, groups);

            Connection = connection;
            Groups = new GroupManager(connection, DefaultSignal);

            _transport.TransportConnected = () =>
            {
                var command = new ServerCommand
                {
                    Type = ServerCommandType.RemoveConnection,
                    Value = connectionId
                };

                return _serverMessageHandler.SendCommand(command);
            };

            _transport.Connected = () =>
            {
                return OnConnectedAsync(context.Request, connectionId).OrEmpty();
            };

            _transport.Reconnected = () =>
            {
                return OnReconnectedAsync(context.Request, connectionId).OrEmpty();
            };

            _transport.Received = data =>
            {
                return OnReceivedAsync(context.Request, connectionId, data).OrEmpty();
            };

            _transport.Disconnected = () =>
            {
                return OnDisconnectAsync(context.Request, connectionId).OrEmpty();
            };

            return _transport.ProcessRequest(connection).OrEmpty().Catch(_counters.ErrorsAllTotal, _counters.ErrorsAllPerSec);
        }
开发者ID:ntcnet83,项目名称:SignalR,代码行数:78,代码来源:PersistentConnection.cs

示例6: ProcessRequestAsync

        public virtual Task ProcessRequestAsync(HostContext context)
        {
            Task transportEventTask = null;

            if (IsNegotiationRequest(context.Request))
            {
                return ProcessNegotiationRequest(context);
            }

            _transport = GetTransport(context);

            string connectionId = _transport.ConnectionId;

            // If there's no connection id then this is a bad request
            if (String.IsNullOrEmpty(connectionId))
            {
                throw new InvalidOperationException("Protocol error: Missing connection id.");
            }

            IEnumerable<string> groups = _transport.Groups;

            Connection = CreateConnection(connectionId, groups, context.Request);

            // Wire up the events we need
            _transport.Connected += () =>
            {
                transportEventTask = OnConnectedAsync(context.Request, connectionId);
            };

            _transport.Received += (data) =>
            {
                transportEventTask = OnReceivedAsync(connectionId, data);
            };

            _transport.Error += (e) =>
            {
                transportEventTask = OnErrorAsync(e);
            };

            _transport.Disconnected += () =>
            {
                transportEventTask = OnDisconnectAsync(connectionId);
            };

            Func<Task> transportProcessRequest = _transport.ProcessRequest(Connection);

            if (transportProcessRequest != null)
            {
                if (transportEventTask != null)
                {
                    return transportEventTask.Then(transportProcessRequest).FastUnwrap();
                }
                return transportProcessRequest();
            }

            return transportEventTask ?? TaskAsyncHelper.Empty;
        }
开发者ID:codeinpeace,项目名称:SignalR,代码行数:57,代码来源:PersistentConnection.cs


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