Example #1
0
        /// <summary>
        /// Creates an EloquentObjects client with ability to specify custom settings and dependencies.
        /// </summary>
        /// <param name="serverAddress">Address of the server that hosts object. Can be prefixed with 'tcp://' for TCP binding or 'pipe://' for Named Pipes binding</param>
        /// <param name="clientAddress">Client-side address that is used to send server-to-client events. Can be prefixed with 'tcp://' for TCP binding or 'pipe://' for Named Pipes binding</param>
        /// <param name="settings">Custom settings</param>
        /// <param name="serializerFactory">Factory that can create serializer to be used for serializing/deserializing data sent between server and client</param>
        /// <exception cref="ArgumentException">Client Uri scheme should match server Uri scheme</exception>
        public EloquentClient(string serverAddress, string clientAddress, EloquentSettings settings, [CanBeNull] ISerializerFactory serializerFactory = null)
        {
            _serializerFactory = serializerFactory ?? new DefaultSerializerFactory();

            var serverUri = new Uri(serverAddress);
            var clientUri = new Uri(clientAddress);

            var serverScheme = serverUri.GetComponents(UriComponents.Scheme, UriFormat.Unescaped);
            var clientScheme = clientUri.GetComponents(UriComponents.Scheme, UriFormat.Unescaped);

            if (serverScheme != clientScheme)
            {
                throw new ArgumentException("Client Uri scheme should match server Uri scheme");
            }

            var binding = new BindingFactory().Create(serverScheme, settings);

            var serverHostAddress = HostAddress.CreateFromUri(serverUri);

            _clientHostAddress = HostAddress.CreateFromUri(clientUri);

            _contractDescriptionFactory = new CachedContractDescriptionFactory(new ContractDescriptionFactory());

            _proxyGenerator = new ProxyGenerator();

            try
            {
                _inputChannel = binding.CreateInputChannel(_clientHostAddress);
            }
            catch (Exception e)
            {
                throw new IOException("Failed creating input channel", e);
            }

            try
            {
                _outputChannel = binding.CreateOutputChannel(serverHostAddress);
            }
            catch (Exception e)
            {
                throw new IOException("Connection failed. Server not found.", e);
            }

            _inputChannel.Start();

            //Send HelloMessage to create a session
            var helloMessage = new HelloMessage(_clientHostAddress);

            _outputChannel.SendWithAck(helloMessage);

            _eventHandlersRepository = new EventHandlersRepository(_outputChannel, _clientHostAddress, this);
            _sessionAgent            = new SessionAgent(binding, _inputChannel, _outputChannel, _clientHostAddress, _eventHandlersRepository);
        }
Example #2
0
 public Connection(string objectId,
                   object outerProxy,
                   IEventHandlersRepository eventHandlersRepository,
                   IContractDescription contractDescription,
                   ISerializer serializer,
                   IEloquentClient eloquentClient,
                   IOutputChannel outputChannel,
                   IHostAddress clientHostAddress)
 {
     _objectId   = objectId;
     _outerProxy = outerProxy;
     _eventHandlersRepository = eventHandlersRepository;
     _contractDescription     = contractDescription;
     _serializer        = serializer;
     _eloquentClient    = eloquentClient;
     _outputChannel     = outputChannel;
     _clientHostAddress = clientHostAddress;
 }
Example #3
0
        public SessionAgent(IBinding binding, IInputChannel inputChannel, IOutputChannel outputChannel,
                            IHostAddress clientHostAddress, IEventHandlersRepository eventHandlersRepository)
        {
            _inputChannel            = inputChannel;
            _outputChannel           = outputChannel;
            _clientHostAddress       = clientHostAddress;
            _eventHandlersRepository = eventHandlersRepository;

            _inputChannel.FrameReceived += InputChannelOnFrameReceived;

            //Start sending heartbeats. When HeartBeatMs is 0 then no heart beats are sent.
            lock (_heartbeatTimerLock)
            {
                if (binding.HeartBeatMs != 0)
                {
                    _heartbeatTimer = new Timer(Heartbeat, null, 0, binding.HeartBeatMs);
                }
            }

            _logger = Logger.Factory.Create(GetType());
            _logger.Info(() => $"Created (clientHostAddress = {_clientHostAddress})");
        }