private void MessageReceived(IMessage message, ClientConnection clientConnection) { if (message != null) { if (message is Authentication) { Messages.Security.ICredentials credentials = ((Authentication)message).Credentials; if (Authenticator != null && credentials != null && credentials.AuthenticationType == Authenticator.AuthenticationType) { IClient client = Authenticator.Authenticate(credentials); clientConnection.Client = client != null ? client : new Client(false); } return; } foreach (IMessageHandler handler in messageHandlers) { IResponse response = handler.Handle(message, clientConnection.Client); if (response != null) { response.Id = Guid.NewGuid(); response.MessageId = message.Id; clientConnection.Connection.Send(response); } } } }
public void Authenticate(Messages.Security.ICredentials credentials) { if (credentials != null && connection.IsConnected) { connection.Send(new Authentication(credentials)); } }