Esempio n. 1
0
        /// <summary>
        /// Creates an EloquentObjects server with ability to specify custom settings and dependencies.
        /// </summary>
        /// <param name="address">Address of the server that hosts object. 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>
        public EloquentServer(string address, EloquentSettings settings, [CanBeNull] ISerializerFactory serializerFactory = null)
        {
            _serializerFactory = serializerFactory ?? new DefaultSerializerFactory();

            var uri = new Uri(address);

            var scheme = uri.GetComponents(UriComponents.Scheme, UriFormat.Unescaped);

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

            var serverHostAddress = HostAddress.CreateFromUri(uri);

            _contractDescriptionFactory = new CachedContractDescriptionFactory(new ContractDescriptionFactory());

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

            _objectsRepository = new ObjectsRepository();

            _server = new Server(binding, _inputChannel, _objectsRepository);
        }
Esempio n. 2
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);
        }