Beispiel #1
0
        /// <summary>
        /// Adds given connection to the scope.
        /// </summary>
        /// <param name="connection">Connection object.</param>
        /// <param name="parameters">Parameters passed.</param>
        /// <returns>
        /// true on success, false if the specified connection already belongs to this scope.
        /// </returns>
        public bool Connect(IConnection connection, object[] parameters)
        {
            if (HasParent && !Parent.Connect(connection, parameters))
            {
                return(false);
            }
            if (HasHandler && !Handler.Connect(connection, this, parameters))
            {
                return(false);
            }
            IClient client = connection.Client;

            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }
            //We would not get this far if there is no handler
            if (HasHandler && !Handler.Join(client, this))
            {
                return(false);
            }
            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }

            CopyOnWriteArraySet <IConnection> connections;

            if (_clients.ContainsKey(client))
            {
                connections = _clients[client];
            }
            else
            {
                connections      = new CopyOnWriteArraySet <IConnection>();
                _clients[client] = connections;
            }
            connections.Add(connection);
            _clientStats.Increment();
            AddEventListener(connection);
            _connectionStats.Increment();
            return(true);
        }