Skip to content

Commit 2d004b7

Browse files
gedemgedem
authored andcommitted
Command map
1 parent eda251c commit 2d004b7

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

src/NetCoreStack.WebSockets.ProxyClient/ClientWebSocketConnector.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NetCoreStack.WebSockets.Interfaces;
44
using NetCoreStack.WebSockets.Internal;
55
using System;
6+
using System.Collections.Generic;
67
using System.Linq;
78
using System.Net.WebSockets;
89
using System.Threading;
@@ -31,6 +32,19 @@ public ClientWebSocketConnector(IOptions<ProxyOptions> options,
3132
Options = options.Value;
3233
}
3334

35+
private WebSocketMessageContext CreateConnectionContext()
36+
{
37+
var context = new WebSocketMessageContext();
38+
context.MessageType = WebSocketMessageType.Text;
39+
context.Command = WebSocketCommands.Connect;
40+
context.Header = new Dictionary<string, object>
41+
{
42+
["Name"] = Options.ConnectorName
43+
};
44+
45+
return context;
46+
}
47+
3448
public async Task ConnectAsync()
3549
{
3650
try

src/NetCoreStack.WebSockets/Internal/InvocatorRegistry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public List<IWebSocketCommandInvocator> GetInvocators<TOptions>(WebSocketMessage
2323
var commands = context.Command.GetUniqueFlags().OfType<WebSocketCommands>().ToList();
2424
foreach (var value in commands)
2525
{
26-
Type type;
27-
if (options.Map.TryGetValue(value, out type))
26+
List<Type> types = options.Map.Where(c => c.Command == value).Select(x => x.Invocator).ToList();
27+
foreach (var type in types)
2828
{
2929
var service = _serviceProvider.GetService(type);
3030
var invocator = service as IWebSocketCommandInvocator;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace NetCoreStack.WebSockets.Internal
4+
{
5+
public class WebSocketCommandMap
6+
{
7+
public WebSocketCommands Command { get; }
8+
public Type Invocator { get; }
9+
10+
public WebSocketCommandMap(WebSocketCommands command, Type invocator)
11+
{
12+
Command = command;
13+
Invocator = invocator;
14+
}
15+
}
16+
}

src/NetCoreStack.WebSockets/SocketsOptions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
using System;
1+
using NetCoreStack.WebSockets.Internal;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45

56
namespace NetCoreStack.WebSockets
67
{
78
public class SocketsOptions
89
{
9-
internal readonly Dictionary<WebSocketCommands, Type> Map =
10-
new Dictionary<WebSocketCommands, Type>();
10+
internal readonly List<WebSocketCommandMap> Map;
1111

1212
public List<Type> Invocators { get; }
1313

1414
public SocketsOptions()
1515
{
16+
Map = new List<WebSocketCommandMap>();
1617
Invocators = new List<Type>();
1718
}
1819

@@ -22,7 +23,8 @@ protected void Registry(Type invocatorType, WebSocketCommands commands)
2223
var values = commands.GetUniqueFlags().OfType<WebSocketCommands>().ToList();
2324
foreach (var value in values)
2425
{
25-
Map.Add(value, invocatorType);
26+
var commandMap = new WebSocketCommandMap(value, invocatorType);
27+
Map.Add(commandMap);
2628
}
2729
}
2830
}

test/WebClientTestApp2/.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/WebClientTestApp2/bower.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)