コード例 #1
0
        public Controller(SocketConnection socketConnection,
                          IProtocolVersion protocolVersion,
                          int heartbeatInterval,
                          IControlMessageHandler messageHandler,
                          IConfigurationHandler configurationHandler,
                          IHeartbeatInformer heartbeatInformer,
                          IErrorHandler errorHandler,
                          ILog logger)
        {
            if (messageHandler == null)
            {
                throw new ArgumentNullException(nameof(messageHandler));
            }
            if (heartbeatInterval <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(heartbeatInterval));
            }

            _socketConnection  = socketConnection ?? throw new ArgumentNullException(nameof(socketConnection));
            _protocolVersion   = protocolVersion ?? throw new ArgumentNullException(nameof(protocolVersion));
            _heartbeatInterval = heartbeatInterval;
            _errorHandler      = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            _heartbeatInformer = heartbeatInformer ?? throw new ArgumentNullException(nameof(heartbeatInformer));
            _messageProcessor  = _protocolVersion.GetControlMessageProcessor(messageHandler, configurationHandler);

            _inputReader  = _socketConnection.InputReader;
            _outputWriter = _socketConnection.OutputWriter;

            _task = Task.Run(() => RunController());
        }
コード例 #2
0
 public ControlMessageProcessor(IConfigurationReader configurationReader,
                                IControlMessageHandler messageHandler,
                                IConfigurationHandler configurationHandler,
                                IErrorHandler errorHandler)
 {
     _configurationReader  = configurationReader ?? throw new ArgumentNullException(nameof(configurationReader));
     _messageHandler       = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));
     _configurationHandler = configurationHandler ?? throw new ArgumentNullException(nameof(configurationHandler));
     _errorHandler         = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
 }
コード例 #3
0
 public IControlMessageProcessor GetControlMessageProcessor(IControlMessageHandler controlMessageHandler,
                                                            IConfigurationHandler configurationHandler)
 {
     return(new ControlMessageProcessor(ConfigurationReader, controlMessageHandler, configurationHandler, _errorHandler));
 }
コード例 #4
0
 /// <summary>
 /// Add an event handler to the control message consumer
 /// </summary>
 /// <param name="handler">Method to call when invoked. Parameters are the action to perform, and the message body</param>
 protected void AddControlHandler(IControlMessageHandler handler)
 {
     //(a, m) => action, message content
     _controlMessageConsumer.ControlEvent += handler.ControlMessageHandler;
 }