/// <summary> /// Adds a ClientConnection to the specified target /// </summary> /// <param name="target">The target to connect to</param> /// <returns> /// Returns the new ClientConnection or null, if the a connection could not be added /// </returns> public IClientConnection AddClientConnection(string target) { if (clientConnections.Count < AllowedConnectionCount || AllowedConnectionCount < 0) { //get a new ClientConneciton using the ComponentFactory IClientConnection connection = ConnectionFactory.GetClientConnection(); connection.Target = target; connection.ConnectionManager = this; connection.WtlpClient = new DefaultWtlpClient(this.messagingClients.First(), target); clientConnections.Add(target.ToLower(), connection); //subscribe to the connection's reset event, so it can be removed when it has been reset connection.ConnectionReset += connection_ConnectionReset; //raise the ClientConnectionAdded event onClientConnectionAdded(connection); //save new connection as known client if (knownClientsCache.ContainsKey(target)) { knownClientsCache[target] = connection.GetClientInfo(); } else { knownClientsCache.Add(target, connection.GetClientInfo()); } saveKnownClients(); return(connection); } else { return(null); } }