/// <summary> /// Initializes a new instance of the <see cref="ChatServer" /> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param> /// <param name="loggerFactory">The logger factory.</param> /// <param name="plugInManager">The plug in manager.</param> public ChatServer(ChatServerSettings settings, IIpAddressResolver addressResolver, ILoggerFactory loggerFactory, PlugInManager plugInManager) { this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger <ChatServer>(); this.settings = settings; this.addressResolver = addressResolver; this.manager = new ChatRoomManager(loggerFactory); this.randomNumberGenerator = RandomNumberGenerator.Create(); this.clientCleanupTimer = new Timer(this.settings.ClientCleanUpInterval.TotalMilliseconds); this.clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients; this.clientCleanupTimer.Start(); this.roomCleanupTimer = new Timer(this.settings.RoomCleanUpInterval.TotalMilliseconds); this.roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms; this.roomCleanupTimer.Start(); foreach (var endpoint in this.settings.Endpoints) { var listener = new ChatServerListener(endpoint, plugInManager, loggerFactory); listener.ClientAccepted += this.ChatClientAccepted; listener.ClientAccepting += this.ChatClientAccepting; this.listeners.Add(listener); } }
/// <summary> /// Initializes a new instance of the <see cref="ChatServer" /> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param> public ChatServer(ChatServerSettings settings, IIpAddressResolver addressResolver) { this.settings = settings; this.addressResolver = addressResolver; this.manager = new ChatRoomManager(); this.randomNumberGenerator = RandomNumberGenerator.Create(); this.clientCleanupTimer = new Timer(this.settings.ClientCleanUpInterval.TotalMilliseconds); this.clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients; this.clientCleanupTimer.Start(); this.roomCleanupTimer = new Timer(this.settings.RoomCleanUpInterval.TotalMilliseconds); this.roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms; this.roomCleanupTimer.Start(); var plugInManager = new PlugInManager(); plugInManager.DiscoverAndRegisterPlugInsOf <INetworkEncryptionFactoryPlugIn>(); foreach (var endpoint in this.settings.Endpoints) { var listener = new ChatServerListener(endpoint, plugInManager); listener.ClientAccepted += this.ChatClientAccepted; listener.ClientAccepting += this.ChatClientAccepting; this.listeners.Add(listener); } }