Add Async suffix to everything
This commit is contained in:
parent
a175609bb1
commit
7db1eb8f25
|
|
@ -28,7 +28,7 @@ namespace ChatSample.Hubs
|
||||||
|
|
||||||
public async Task Send(string message)
|
public async Task Send(string message)
|
||||||
{
|
{
|
||||||
await Clients.All.Invoke("Send", $"{Context.User.Identity.Name}: {message}");
|
await Clients.All.InvokeAsync("Send", $"{Context.User.Identity.Name}: {message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace SocketsSample
|
||||||
{
|
{
|
||||||
public ConnectionList Connections { get; } = new ConnectionList();
|
public ConnectionList Connections { get; } = new ConnectionList();
|
||||||
|
|
||||||
public override async Task OnConnected(Connection connection)
|
public override async Task OnConnectedAsync(Connection connection)
|
||||||
{
|
{
|
||||||
Connections.Add(connection);
|
Connections.Add(connection);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,17 @@ namespace SocketsSample.Hubs
|
||||||
{
|
{
|
||||||
public override async Task OnConnectedAsync()
|
public override async Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
await Clients.All.Invoke("Send", Context.Connection.ConnectionId + " joined");
|
await Clients.All.InvokeAsync("Send", Context.Connection.ConnectionId + " joined");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnDisconnectedAsync()
|
public override async Task OnDisconnectedAsync()
|
||||||
{
|
{
|
||||||
await Clients.All.Invoke("Send", Context.Connection.ConnectionId + " left");
|
await Clients.All.InvokeAsync("Send", Context.Connection.ConnectionId + " left");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Send(string message)
|
public Task Send(string message)
|
||||||
{
|
{
|
||||||
return Clients.All.Invoke("Send", Context.ConnectionId + ": " + message);
|
return Clients.All.InvokeAsync("Send", Context.ConnectionId + ": " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace SocketsSample
|
||||||
{
|
{
|
||||||
public class LineInvocationAdapter : IInvocationAdapter
|
public class LineInvocationAdapter : IInvocationAdapter
|
||||||
{
|
{
|
||||||
public async Task<InvocationDescriptor> ReadInvocationDescriptor(Stream stream, Func<string, Type[]> getParams)
|
public async Task<InvocationDescriptor> ReadInvocationDescriptorAsync(Stream stream, Func<string, Type[]> getParams)
|
||||||
{
|
{
|
||||||
var streamReader = new StreamReader(stream);
|
var streamReader = new StreamReader(stream);
|
||||||
var line = await streamReader.ReadLineAsync();
|
var line = await streamReader.ReadLineAsync();
|
||||||
|
|
@ -30,13 +30,13 @@ namespace SocketsSample
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream)
|
public async Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
var msg = $"CI{invocationDescriptor.Id},M{invocationDescriptor.Method},{string.Join(",", invocationDescriptor.Arguments.Select(a => a.ToString()))}\n";
|
var msg = $"CI{invocationDescriptor.Id},M{invocationDescriptor.Method},{string.Join(",", invocationDescriptor.Arguments.Select(a => a.ToString()))}\n";
|
||||||
await WriteAsync(msg, stream);
|
await WriteAsync(msg, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream)
|
public async Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(resultDescriptor.Error))
|
if (string.IsNullOrEmpty(resultDescriptor.Error))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace SocketsSample.Protobuf
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<InvocationDescriptor> ReadInvocationDescriptor(Stream stream, Func<string, Type[]> getParams)
|
public async Task<InvocationDescriptor> ReadInvocationDescriptorAsync(Stream stream, Func<string, Type[]> getParams)
|
||||||
{
|
{
|
||||||
return await Task.Run(() => CreateInvocationDescriptorInt(stream, getParams));
|
return await Task.Run(() => CreateInvocationDescriptorInt(stream, getParams));
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ namespace SocketsSample.Protobuf
|
||||||
return Task.FromResult(invocationDescriptor);
|
return Task.FromResult(invocationDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream)
|
public async Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
var outputStream = new CodedOutputStream(stream, leaveOpen: true);
|
var outputStream = new CodedOutputStream(stream, leaveOpen: true);
|
||||||
outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Result });
|
outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Result });
|
||||||
|
|
@ -101,7 +101,7 @@ namespace SocketsSample.Protobuf
|
||||||
await stream.FlushAsync();
|
await stream.FlushAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream)
|
public async Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
var outputStream = new CodedOutputStream(stream, leaveOpen: true);
|
var outputStream = new CodedOutputStream(stream, leaveOpen: true);
|
||||||
outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Invocation });
|
outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Invocation });
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
_bus = _redisServerConnection.GetSubscriber();
|
_bus = _redisServerConnection.GetSubscriber();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeAll(string methodName, params object[] args)
|
public override Task InvokeAllAsync(string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
var message = new InvocationDescriptor
|
var message = new InvocationDescriptor
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
return PublishAsync(typeof(THub).Name, message);
|
return PublishAsync(typeof(THub).Name, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeConnection(string connectionId, string methodName, params object[] args)
|
public override Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
var message = new InvocationDescriptor
|
var message = new InvocationDescriptor
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
return PublishAsync(typeof(THub) + "." + connectionId, message);
|
return PublishAsync(typeof(THub) + "." + connectionId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeGroup(string groupName, string methodName, params object[] args)
|
public override Task InvokeGroupAsync(string groupName, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
var message = new InvocationDescriptor
|
var message = new InvocationDescriptor
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
return PublishAsync(typeof(THub) + "." + groupName, message);
|
return PublishAsync(typeof(THub) + "." + groupName, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeUser(string userId, string methodName, params object[] args)
|
public override Task InvokeUserAsync(string userId, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
var message = new InvocationDescriptor
|
var message = new InvocationDescriptor
|
||||||
{
|
{
|
||||||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
// BAD
|
// BAD
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
invocationAdapter.WriteInvocationDescriptor(message, ms);
|
invocationAdapter.WriteInvocationDescriptorAsync(message, ms);
|
||||||
|
|
||||||
return _bus.PublishAsync(channel, ms.ToArray());
|
return _bus.PublishAsync(channel, ms.ToArray());
|
||||||
}
|
}
|
||||||
|
|
@ -113,13 +113,13 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task AddGroup(Connection connection, string groupName)
|
public override Task AddGroupAsync(Connection connection, string groupName)
|
||||||
{
|
{
|
||||||
var key = typeof(THub).Name + "." + groupName;
|
var key = typeof(THub).Name + "." + groupName;
|
||||||
return SubscribeAsync(key, connection);
|
return SubscribeAsync(key, connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task RemoveGroup(Connection connection, string groupName)
|
public override Task RemoveGroupAsync(Connection connection, string groupName)
|
||||||
{
|
{
|
||||||
var key = typeof(THub) + "." + groupName;
|
var key = typeof(THub) + "." + groupName;
|
||||||
return UnsubscribeAsync(key, connection);
|
return UnsubscribeAsync(key, connection);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_registry = registry;
|
_registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task AddGroup(Connection connection, string groupName)
|
public override Task AddGroupAsync(Connection connection, string groupName)
|
||||||
{
|
{
|
||||||
var groups = connection.Metadata.GetOrAdd("groups", k => new HashSet<string>());
|
var groups = connection.Metadata.GetOrAdd("groups", k => new HashSet<string>());
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task RemoveGroup(Connection connection, string groupName)
|
public override Task RemoveGroupAsync(Connection connection, string groupName)
|
||||||
{
|
{
|
||||||
var groups = connection.Metadata.Get<HashSet<string>>("groups");
|
var groups = connection.Metadata.Get<HashSet<string>>("groups");
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeAll(string methodName, params object[] args)
|
public override Task InvokeAllAsync(string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
return InvokeAllWhere(methodName, args, c => true);
|
return InvokeAllWhere(methodName, args, c => true);
|
||||||
}
|
}
|
||||||
|
|
@ -65,13 +65,13 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
|
|
||||||
var invocationAdapter = _registry.GetInvocationAdapter((string)connection.Metadata["formatType"]);
|
var invocationAdapter = _registry.GetInvocationAdapter((string)connection.Metadata["formatType"]);
|
||||||
|
|
||||||
tasks.Add(invocationAdapter.WriteInvocationDescriptor(message, connection.Channel.GetStream()));
|
tasks.Add(invocationAdapter.WriteInvocationDescriptorAsync(message, connection.Channel.GetStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.WhenAll(tasks);
|
return Task.WhenAll(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeConnection(string connectionId, string methodName, params object[] args)
|
public override Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
var connection = _connections[connectionId];
|
var connection = _connections[connectionId];
|
||||||
|
|
||||||
|
|
@ -83,10 +83,10 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
Arguments = args
|
Arguments = args
|
||||||
};
|
};
|
||||||
|
|
||||||
return invocationAdapter.WriteInvocationDescriptor(message, connection.Channel.GetStream());
|
return invocationAdapter.WriteInvocationDescriptorAsync(message, connection.Channel.GetStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeGroup(string groupName, string methodName, params object[] args)
|
public override Task InvokeGroupAsync(string groupName, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
return InvokeAllWhere(methodName, args, connection =>
|
return InvokeAllWhere(methodName, args, connection =>
|
||||||
{
|
{
|
||||||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeUser(string userId, string methodName, params object[] args)
|
public override Task InvokeUserAsync(string userId, string methodName, params object[] args)
|
||||||
{
|
{
|
||||||
return InvokeAllWhere(methodName, args, connection =>
|
return InvokeAllWhere(methodName, args, connection =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
public class HubEndPoint<THub> : RpcEndpoint<THub> where THub : Hub
|
public class HubEndPoint<THub> : RpcEndpoint<THub> where THub : Hub
|
||||||
{
|
{
|
||||||
private readonly AllClientProxy<THub> _all;
|
|
||||||
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
||||||
private readonly IHubContext<THub> _hubContext;
|
private readonly IHubContext<THub> _hubContext;
|
||||||
|
|
||||||
|
|
@ -23,7 +22,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_hubContext = hubContext;
|
_hubContext = hubContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnConnected(Connection connection)
|
public override async Task OnConnectedAsync(Connection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
await hub.OnConnectedAsync();
|
await hub.OnConnectedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await base.OnConnected(connection);
|
await base.OnConnectedAsync(connection);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -62,10 +61,5 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
hub.Context = new HubCallerContext(connection);
|
hub.Context = new HubCallerContext(connection);
|
||||||
hub.Groups = new GroupManager<THub>(connection, _lifetimeManager);
|
hub.Groups = new GroupManager<THub>(connection, _lifetimeManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AfterInvoke(Connection connection, THub endpoint)
|
|
||||||
{
|
|
||||||
// Poison the hub make sure it can't be used after invocation
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,17 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
|
|
||||||
public abstract Task OnDisconnectedAsync(Connection connection);
|
public abstract Task OnDisconnectedAsync(Connection connection);
|
||||||
|
|
||||||
public abstract Task InvokeAll(string methodName, params object[] args);
|
public abstract Task InvokeAllAsync(string methodName, params object[] args);
|
||||||
|
|
||||||
public abstract Task InvokeConnection(string connectionId, string methodName, params object[] args);
|
public abstract Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args);
|
||||||
|
|
||||||
public abstract Task InvokeGroup(string groupName, string methodName, params object[] args);
|
public abstract Task InvokeGroupAsync(string groupName, string methodName, params object[] args);
|
||||||
|
|
||||||
public abstract Task InvokeUser(string userId, string methodName, params object[] args);
|
public abstract Task InvokeUserAsync(string userId, string methodName, params object[] args);
|
||||||
|
|
||||||
public abstract Task AddGroup(Connection connection, string groupName);
|
public abstract Task AddGroupAsync(Connection connection, string groupName);
|
||||||
|
|
||||||
public abstract Task RemoveGroup(Connection connection, string groupName);
|
public abstract Task RemoveGroupAsync(Connection connection, string groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
/// <param name="method">name of the method to invoke</param>
|
/// <param name="method">name of the method to invoke</param>
|
||||||
/// <param name="args">argumetns to pass to the client</param>
|
/// <param name="args">argumetns to pass to the client</param>
|
||||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||||
Task Invoke(string method, params object[] args);
|
Task InvokeAsync(string method, params object[] args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
public interface IInvocationAdapter
|
public interface IInvocationAdapter
|
||||||
{
|
{
|
||||||
Task<InvocationDescriptor> ReadInvocationDescriptor(Stream stream, Func<string, Type[]> getParams);
|
Task<InvocationDescriptor> ReadInvocationDescriptorAsync(Stream stream, Func<string, Type[]> getParams);
|
||||||
|
|
||||||
Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream);
|
Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream);
|
||||||
|
|
||||||
Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream);
|
Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,20 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<InvocationDescriptor> ReadInvocationDescriptor(Stream stream, Func<string, Type[]> getParams)
|
public async Task<InvocationDescriptor> ReadInvocationDescriptorAsync(Stream stream, Func<string, Type[]> getParams)
|
||||||
{
|
{
|
||||||
var reader = new JsonTextReader(new StreamReader(stream));
|
var reader = new JsonTextReader(new StreamReader(stream));
|
||||||
// REVIEW: Task.Run()
|
// REVIEW: Task.Run()
|
||||||
return await Task.Run(() => _serializer.Deserialize<InvocationDescriptor>(reader));
|
return await Task.Run(() => _serializer.Deserialize<InvocationDescriptor>(reader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream)
|
public Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
Write(resultDescriptor, stream);
|
Write(resultDescriptor, stream);
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream)
|
public Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream)
|
||||||
{
|
{
|
||||||
Write(invocationDescriptor, stream);
|
Write(invocationDescriptor, stream);
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_userId = userId;
|
_userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Invoke(string method, params object[] args)
|
public Task InvokeAsync(string method, params object[] args)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.InvokeUser(_userId, method, args);
|
return _lifetimeManager.InvokeUserAsync(_userId, method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,9 +33,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_groupName = groupName;
|
_groupName = groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Invoke(string method, params object[] args)
|
public Task InvokeAsync(string method, params object[] args)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.InvokeGroup(_groupName, method, args);
|
return _lifetimeManager.InvokeGroupAsync(_groupName, method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,9 +48,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_lifetimeManager = lifetimeManager;
|
_lifetimeManager = lifetimeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Invoke(string method, params object[] args)
|
public Task InvokeAsync(string method, params object[] args)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.InvokeAll(method, args);
|
return _lifetimeManager.InvokeAllAsync(method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,9 +66,9 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
_connectionId = connectionId;
|
_connectionId = connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Invoke(string method, params object[] args)
|
public Task InvokeAsync(string method, params object[] args)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.InvokeConnection(_connectionId, method, args);
|
return _lifetimeManager.InvokeConnectionAsync(_connectionId, method, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,12 +85,12 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
|
|
||||||
public Task Add(string groupName)
|
public Task Add(string groupName)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.AddGroup(_connection, groupName);
|
return _lifetimeManager.AddGroupAsync(_connection, groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Remove(string groupName)
|
public Task Remove(string groupName)
|
||||||
{
|
{
|
||||||
return _lifetimeManager.RemoveGroup(_connection, groupName);
|
return _lifetimeManager.RemoveGroupAsync(_connection, groupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
RegisterRPCEndPoint();
|
RegisterRPCEndPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnConnected(Connection connection)
|
public override async Task OnConnectedAsync(Connection connection)
|
||||||
{
|
{
|
||||||
// TODO: Dispatch from the caller
|
// TODO: Dispatch from the caller
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var invocationDescriptor =
|
var invocationDescriptor =
|
||||||
await invocationAdapter.ReadInvocationDescriptor(
|
await invocationAdapter.ReadInvocationDescriptorAsync(
|
||||||
stream, methodName =>
|
stream, methodName =>
|
||||||
{
|
{
|
||||||
Type[] types;
|
Type[] types;
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await invocationAdapter.WriteInvocationResult(result, stream);
|
await invocationAdapter.WriteInvocationResultAsync(result, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using static Microsoft.AspNetCore.Builder.HttpDispatcherAppBuilderExtensions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connection">The new <see cref="Connection"/></param>
|
/// <param name="connection">The new <see cref="Connection"/></param>
|
||||||
/// <returns>A <see cref="Task"/> that represents the connection lifetime. When the task completes, the connection is complete.</returns>
|
/// <returns>A <see cref="Task"/> that represents the connection lifetime. When the task completes, the connection is complete.</returns>
|
||||||
public abstract Task OnConnected(Connection connection);
|
public abstract Task OnConnectedAsync(Connection connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
_channelFactory = factory;
|
_channelFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Execute<TEndPoint>(string path, HttpContext context) where TEndPoint : EndPoint
|
public async Task ExecuteAsync<TEndPoint>(string path, HttpContext context) where TEndPoint : EndPoint
|
||||||
{
|
{
|
||||||
if (context.Request.Path.StartsWithSegments(path + "/getid"))
|
if (context.Request.Path.StartsWithSegments(path + "/getid"))
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
var longPolling = new LongPolling(state.Connection);
|
var longPolling = new LongPolling(state.Connection);
|
||||||
|
|
||||||
// Start the transport
|
// Start the transport
|
||||||
var transportTask = longPolling.ProcessRequest(context);
|
var transportTask = longPolling.ProcessRequestAsync(context);
|
||||||
|
|
||||||
Task endpointTask = null;
|
Task endpointTask = null;
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
await endpointTask;
|
await endpointTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
endpointTask = endpoint.OnConnected(state.Connection);
|
endpointTask = endpoint.OnConnectedAsync(state.Connection);
|
||||||
state.Connection.Metadata["endpoint"] = endpointTask;
|
state.Connection.Metadata["endpoint"] = endpointTask;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -145,10 +145,10 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
RegisterDisconnect(context, connection);
|
RegisterDisconnect(context, connection);
|
||||||
|
|
||||||
// Start the transport
|
// Start the transport
|
||||||
var transportTask = transport.ProcessRequest(context);
|
var transportTask = transport.ProcessRequestAsync(context);
|
||||||
|
|
||||||
// Call into the end point passing the connection
|
// Call into the end point passing the connection
|
||||||
var endpointTask = endpoint.OnConnected(connection);
|
var endpointTask = endpoint.OnConnectedAsync(connection);
|
||||||
|
|
||||||
// Wait for any of them to end
|
// Wait for any of them to end
|
||||||
await Task.WhenAny(endpointTask, transportTask);
|
await Task.WhenAny(endpointTask, transportTask);
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,22 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
app.UseRouter(routes.Build());
|
app.UseRouter(routes.Build());
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SocketRouteBuilder
|
public class SocketRouteBuilder
|
||||||
|
{
|
||||||
|
private readonly HttpConnectionDispatcher _dispatcher;
|
||||||
|
private readonly RouteBuilder _routes;
|
||||||
|
|
||||||
|
public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher)
|
||||||
{
|
{
|
||||||
private readonly HttpConnectionDispatcher _dispatcher;
|
_routes = routes;
|
||||||
private readonly RouteBuilder _routes;
|
_dispatcher = dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher)
|
public void MapSocketEndpoint<TEndPoint>(string path) where TEndPoint : EndPoint
|
||||||
{
|
{
|
||||||
_routes = routes;
|
_routes.AddPrefixRoute(path, new RouteHandler(c => _dispatcher.ExecuteAsync<TEndPoint>(path, c)));
|
||||||
_dispatcher = dispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MapSocketEndpoint<TEndPoint>(string path) where TEndPoint : EndPoint
|
|
||||||
{
|
|
||||||
_routes.AddPrefixRoute(path, new RouteHandler(c => _dispatcher.Execute<TEndPoint>(path, c)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
/// <returns>A <see cref="Task"/> that completes when the transport has finished processing</returns>
|
/// <returns>A <see cref="Task"/> that completes when the transport has finished processing</returns>
|
||||||
Task ProcessRequest(HttpContext context);
|
Task ProcessRequestAsync(HttpContext context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
_channel = (HttpChannel)connection.Channel;
|
_channel = (HttpChannel)connection.Channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessRequest(HttpContext context)
|
public async Task ProcessRequestAsync(HttpContext context)
|
||||||
{
|
{
|
||||||
var result = await _channel.Output.ReadAsync();
|
var result = await _channel.Output.ReadAsync();
|
||||||
var buffer = result.Buffer;
|
var buffer = result.Buffer;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
_channel = (HttpChannel)connection.Channel;
|
_channel = (HttpChannel)connection.Channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessRequest(HttpContext context)
|
public async Task ProcessRequestAsync(HttpContext context)
|
||||||
{
|
{
|
||||||
context.Response.ContentType = "text/event-stream";
|
context.Response.ContentType = "text/event-stream";
|
||||||
context.Response.Headers["Cache-Control"] = "no-cache";
|
context.Response.Headers["Cache-Control"] = "no-cache";
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
_messageType = format == Format.Binary ? WebSocketMessageType.Binary : WebSocketMessageType.Text;
|
_messageType = format == Format.Binary ? WebSocketMessageType.Binary : WebSocketMessageType.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessRequest(HttpContext context)
|
public async Task ProcessRequestAsync(HttpContext context)
|
||||||
{
|
{
|
||||||
if (!context.WebSockets.IsWebSocketRequest)
|
if (!context.WebSockets.IsWebSocketRequest)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
context.Request.Path = "/getid";
|
context.Request.Path = "/getid";
|
||||||
context.Response.Body = ms;
|
context.Response.Body = ms;
|
||||||
await dispatcher.Execute<TestEndPoint>("", context);
|
await dispatcher.ExecuteAsync<TestEndPoint>("", context);
|
||||||
|
|
||||||
var id = Encoding.UTF8.GetString(ms.ToArray());
|
var id = Encoding.UTF8.GetString(ms.ToArray());
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
context.Request.Query = qs;
|
context.Request.Query = qs;
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||||
{
|
{
|
||||||
await dispatcher.Execute<TestEndPoint>("", context);
|
await dispatcher.ExecuteAsync<TestEndPoint>("", context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
context.Request.Query = qs;
|
context.Request.Query = qs;
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||||
{
|
{
|
||||||
await dispatcher.Execute<TestEndPoint>("", context);
|
await dispatcher.ExecuteAsync<TestEndPoint>("", context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
context.Request.Path = "/send";
|
context.Request.Path = "/send";
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
|
||||||
{
|
{
|
||||||
await dispatcher.Execute<TestEndPoint>("", context);
|
await dispatcher.ExecuteAsync<TestEndPoint>("", context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
||||||
public class TestEndPoint : EndPoint
|
public class TestEndPoint : EndPoint
|
||||||
{
|
{
|
||||||
public override Task OnConnected(Connection connection)
|
public override Task OnConnectedAsync(Connection connection)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
channel.Output.CompleteWriter();
|
||||||
|
|
||||||
await poll.ProcessRequest(context);
|
await poll.ProcessRequestAsync(context);
|
||||||
|
|
||||||
Assert.Equal(204, context.Response.StatusCode);
|
Assert.Equal(204, context.Response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
channel.Output.CompleteWriter();
|
||||||
|
|
||||||
await poll.ProcessRequest(context);
|
await poll.ProcessRequestAsync(context);
|
||||||
|
|
||||||
Assert.Equal("Hello World", Encoding.UTF8.GetString(ms.ToArray()));
|
Assert.Equal("Hello World", Encoding.UTF8.GetString(ms.ToArray()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
channel.Output.CompleteWriter();
|
||||||
|
|
||||||
await sse.ProcessRequest(context);
|
await sse.ProcessRequestAsync(context);
|
||||||
|
|
||||||
Assert.Equal("text/event-stream", context.Response.ContentType);
|
Assert.Equal("text/event-stream", context.Response.ContentType);
|
||||||
Assert.Equal("no-cache", context.Response.Headers["Cache-Control"]);
|
Assert.Equal("no-cache", context.Response.Headers["Cache-Control"]);
|
||||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
channel.Output.CompleteWriter();
|
||||||
|
|
||||||
await sse.ProcessRequest(context);
|
await sse.ProcessRequestAsync(context);
|
||||||
|
|
||||||
var expected = "data: Hello World\n\n";
|
var expected = "data: Hello World\n\n";
|
||||||
Assert.Equal(expected, Encoding.UTF8.GetString(ms.ToArray()));
|
Assert.Equal(expected, Encoding.UTF8.GetString(ms.ToArray()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue