Example #1
0
        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));
            }
        }
Example #2
0
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (Context.Request.Url.LocalPath.EndsWith("/send"))
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort());
            }
            else
            {
                if (IsConnectRequest)
                {
                    if (Connected != null)
                    {
                        // Return a task that completes when the connected event task & the receive loop task are both finished
                        return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Connected, connection));
                    }

                    return(ProcessReceiveRequest(connection));
                }

                if (Reconnected != null)
                {
                    // Return a task that completes when the reconnected event task & the receive loop task are both finished
                    return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection));
                }

                return(ProcessReceiveRequest(connection));
            }
        }
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort(ConnectionId));
            }
            else
            {
                InitializePersistentState();

                if (IsConnectRequest)
                {
                    return(ProcessConnectRequest(connection));
                }
                else if (MessageId != null)
                {
                    if (IsReconnectRequest && 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));
                }
            }

            return(null);
        }
Example #4
0
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort(ConnectionId));
            }
            else
            {
                if (IsConnectRequest)
                {
                    return(ProcessConnectRequest(connection));
                }
                else if (MessageId != null)
                {
                    if (IsReconnectRequest && Reconnected != null)
                    {
                        // Return a task that completes when the reconnected event task & the receive loop task are both finished
                        return(TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection, Completed));
                    }

                    return(ProcessReceiveRequest(connection));
                }
            }

            return(null);
        }
Example #5
0
        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);
            }
        }
Example #6
0
 public override Task ProcessRequest(ITransportConnection connection)
 {
     if (IsAbortRequest)
     {
         return(connection.Abort(ConnectionId));
     }
     else
     {
         return(AcceptWebSocketRequest(connection));
     }
 }
Example #7
0
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (Context.Request.Url.LocalPath.EndsWith("/send", StringComparison.OrdinalIgnoreCase))
            {
                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);

                        // The connected callback
                        Func <Task> connected = () =>
                        {
                            if (newConnection)
                            {
                                return(Connected().Then(() => _counters.ConnectionsConnected.Increment()));
                            }
                            return(TaskAsyncHelper.Empty);
                        };

                        return(TaskAsyncHelper.Interleave(ProcessReceiveRequestWithoutTracking, connected, 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));
            }
        }
Example #8
0
 public override Task ProcessRequest(ITransportConnection connection)
 {
     if (IsAbortRequest)
     {
         Context.Response.ContentType = "text/plain";
         return(connection.Abort(ConnectionId));
     }
     else
     {
         return(AcceptWebSocketRequest(socket =>
         {
             return ProcessRequestCore(connection);
         }));
     }
 }
Example #9
0
        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();
            }
        }
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort(ConnectionId));
            }
            else
            {
                return(InitializePersistentState()
                       .Then((t, c) => t.ProcessReceiveRequest(c), this, connection));
            }
        }
Example #11
0
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (Context.Request.Url.LocalPath.EndsWith("/send"))
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort(ConnectionId));
            }
            else
            {
                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));
            }
        }
Example #12
0
        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);
                }));
            }
        }
Example #13
0
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return(ProcessSendRequest());
            }
            else if (IsAbortRequest)
            {
                return(Connection.Abort(ConnectionId));
            }
            else
            {
                InitializePersistentState();

                return(ProcessReceiveRequest(connection));
            }
        }
Example #14
0
        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);
                });
            }
        }
Example #15
0
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

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

                return(ProcessReceiveRequest(connection));
            }
        }
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

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

                return ProcessReceiveRequest(connection);
            }
        }
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort(ConnectionId);
            }
            else
            {
                return InitializePersistentState()
                    .Then((t, c) => t.ProcessReceiveRequest(c), this, connection);
            }
        }
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort(ConnectionId);
            }
            else
            {
                InitializePersistentState();

                Task task = null;

                if (IsConnectRequest)
                {
                    task = ProcessConnectRequest(connection);
                }
                else if (MessageId != null)
                {
                    if (IsReconnectRequest && 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());
                        task = TaskAsyncHelper.Interleave(ProcessReceiveRequest, reconnected, connection, Completed);
                    }
                    else
                    {
                        task = ProcessReceiveRequest(connection);
                    }
                }

                if (task != null)
                {
                    // Mark the request as completed once it's done
                    return task.Finally(() => CompleteRequest());
                }
            }

            return null;
        }
Example #19
0
        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);
            }
        }
 public override Task ProcessRequest(ITransportConnection connection)
 {
     if (IsAbortRequest)
     {
         return connection.Abort(ConnectionId);
     }
     else
     {
         return AcceptWebSocketRequest(connection);
     }
 }
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort(ConnectionId);
            }
            else
            {
                if (IsConnectRequest)
                {
                    return ProcessConnectRequest(connection);
                }
                else if (MessageId != null)
                {
                    if (IsReconnectRequest && Reconnected != null)
                    {
                        // Return a task that completes when the reconnected event task & the receive loop task are both finished
                        return TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection, Completed);
                    }

                    return ProcessReceiveRequest(connection);
                }
            }

            return null;
        }
Example #22
0
        protected Task ProcessRequestCore(ITransportConnection connection)
        {
            Connection = connection;

            if (Context.Request.Url.LocalPath.EndsWith("/send"))
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort();
            }
            else
            {
                if (IsConnectRequest)
                {
                    if (Connected != null)
                    {
                        // Return a task that completes when the connected event task & the receive loop task are both finished
                        return TaskAsyncHelper.Interleave(ProcessReceiveRequest, Connected, connection);
                    }

                    return ProcessReceiveRequest(connection);
                }

                if (Reconnected != null)
                {
                    // Return a task that completes when the reconnected event task & the receive loop task are both finished
                    return TaskAsyncHelper.Interleave(ProcessReceiveRequest, Reconnected, connection);
                }

                return ProcessReceiveRequest(connection);
            }
        }
        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();
            }
        }
        public Task ProcessRequest(ITransportConnection connection)
        {
            Connection = connection;

            if (IsSendRequest)
            {
                return ProcessSendRequest();
            }
            else if (IsAbortRequest)
            {
                return Connection.Abort(ConnectionId);
            }
            else
            {
                InitializePersistentState();

                return ProcessReceiveRequest(connection);
            }
        }