|
5 | 5 |
|
6 | 6 | namespace System.Net.Mqtt.Server
|
7 | 7 | {
|
8 |
| - public class ServerFactory : IFactory<Server> |
9 |
| - { |
10 |
| - readonly ITracerManager tracerManager; |
11 |
| - readonly ITracer tracer; |
12 |
| - readonly IProtocolBinding binding; |
13 |
| - readonly IAuthenticationProvider authenticationProvider; |
| 8 | + public class ServerFactory : IFactory<Server> |
| 9 | + { |
| 10 | + readonly ITracerManager tracerManager; |
| 11 | + readonly ITracer tracer; |
| 12 | + readonly IProtocolBinding binding; |
| 13 | + readonly IAuthenticationProvider authenticationProvider; |
14 | 14 |
|
15 |
| - public ServerFactory (IProtocolBinding binding, IAuthenticationProvider authenticationProvider = null) |
16 |
| - { |
17 |
| - tracerManager = new DiagnosticsTracerManager (); |
18 |
| - tracer = tracerManager.Get<ServerFactory> (); |
19 |
| - this.binding = binding; |
20 |
| - this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance; |
21 |
| - } |
| 15 | + public ServerFactory (IProtocolBinding binding, IAuthenticationProvider authenticationProvider = null) |
| 16 | + : this (binding, new DefaultTracerManager (), authenticationProvider) |
| 17 | + { |
| 18 | + this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance; |
| 19 | + } |
22 | 20 |
|
23 |
| - /// <exception cref="ServerException">ServerException</exception> |
24 |
| - public Server Create (ProtocolConfiguration configuration) |
25 |
| - { |
26 |
| - try { |
27 |
| - var topicEvaluator = new TopicEvaluator (configuration); |
28 |
| - var channelProvider = binding.GetChannelProvider (tracerManager, configuration); |
29 |
| - var channelFactory = new PacketChannelFactory (topicEvaluator, tracerManager, configuration); |
30 |
| - var repositoryProvider = new InMemoryRepositoryProvider (); |
31 |
| - var connectionProvider = new ConnectionProvider (tracerManager); |
32 |
| - var packetIdProvider = new PacketIdProvider (); |
33 |
| - var eventStream = new EventStream (); |
34 |
| - var flowProvider = new ServerProtocolFlowProvider (authenticationProvider, connectionProvider, topicEvaluator, |
35 |
| - repositoryProvider, packetIdProvider, eventStream, tracerManager, configuration); |
| 21 | + public ServerFactory (IProtocolBinding binding, ITracerManager tracerManager, IAuthenticationProvider authenticationProvider = null) |
| 22 | + { |
| 23 | + tracer = tracerManager.Get<ServerFactory> (); |
| 24 | + this.tracerManager = tracerManager; |
| 25 | + this.binding = binding; |
| 26 | + this.authenticationProvider = authenticationProvider ?? NullAuthenticationProvider.Instance; |
| 27 | + } |
36 | 28 |
|
37 |
| - return new Server (channelProvider, channelFactory, |
38 |
| - flowProvider, connectionProvider, eventStream, tracerManager, configuration); |
39 |
| - } catch (Exception ex) { |
40 |
| - tracer.Error (ex, Properties.Resources.Server_InitializeError); |
| 29 | + /// <exception cref="ServerException">ServerException</exception> |
| 30 | + public Server Create (ProtocolConfiguration configuration) |
| 31 | + { |
| 32 | + try { |
| 33 | + var topicEvaluator = new TopicEvaluator (configuration); |
| 34 | + var channelProvider = binding.GetChannelProvider (tracerManager, configuration); |
| 35 | + var channelFactory = new PacketChannelFactory (topicEvaluator, tracerManager, configuration); |
| 36 | + var repositoryProvider = new InMemoryRepositoryProvider (); |
| 37 | + var connectionProvider = new ConnectionProvider (tracerManager); |
| 38 | + var packetIdProvider = new PacketIdProvider (); |
| 39 | + var eventStream = new EventStream (); |
| 40 | + var flowProvider = new ServerProtocolFlowProvider (authenticationProvider, connectionProvider, topicEvaluator, |
| 41 | + repositoryProvider, packetIdProvider, eventStream, tracerManager, configuration); |
41 | 42 |
|
42 |
| - throw new ServerException (Properties.Resources.Server_InitializeError, ex); |
43 |
| - } |
44 |
| - } |
45 |
| - } |
| 43 | + return new Server (channelProvider, channelFactory, |
| 44 | + flowProvider, connectionProvider, eventStream, tracerManager, configuration); |
| 45 | + } catch (Exception ex) { |
| 46 | + tracer.Error (ex, Properties.Resources.Server_InitializeError); |
| 47 | + |
| 48 | + throw new ServerException (Properties.Resources.Server_InitializeError, ex); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
46 | 52 | }
|
0 commit comments