public ProtoChannelTestClient(IStatistics statistics, TestClientSettings settings)
                : base(statistics, settings)
            {
                _stopwatch.Start();

                _callbackService = new ClientCallbackService();

                _callbackService.StreamReceived += _callbackService_StreamReceived;

                var configuration = new ProtoClientConfiguration
                {
                    CallbackObject = _callbackService
                };

                _service = new ClientService(settings.Host, Constants.ProtoChannelPort, configuration);
            }
Ejemplo n.º 2
0
        public static ProtoClient CreateClient(string hostname, int port, ProtoClientConfiguration configuration, int protocolVersion)
        {
            // The protocol version may be read before our constructor completes.
            // Because of this we use a ThreadStatic here to alternatively
            // provide the protocol number.

            _currentProtocolVersion = protocolVersion;

            try
            {
                return new ProtoClient(hostname, port, configuration, protocolVersion);
            }
            finally
            {
                _currentProtocolVersion = null;
            }
        }
        public void ExpectMemoryStream()
        {
            var configuration = new ProtoClientConfiguration
            {
                StreamManager = new HybridStreamManager(Path.GetTempPath(), 50)
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                var response = client.StreamRequest(new StreamRequest { Length = 10 });

                using (var stream = client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                    Assert.That(stream.Stream, Is.InstanceOf<MemoryStream>());
                }
            }
        }
Ejemplo n.º 4
0
        public void SecureConnect()
        {
            var hostConfig = new ProtoHostConfiguration
            {
                Secure = true,
                Certificate = GetCertificate()
            };

            var clientConfig = new ProtoClientConfiguration
            {
                Secure = true
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0), hostConfig))
            using (new ClientService(host.LocalEndPoint, clientConfig))
            {
            }
        }
        public void StreamTooLong()
        {
            var configuration = new ProtoClientConfiguration
            {
                StreamManager = new HybridStreamManager(Path.GetTempPath(), 50, 100)
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                // TODO: Communicating that the stream was rejected isn't yet
                // communicated clearly.

                var response = client.StreamRequest(new StreamRequest { Length = 200 });

                using (client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                }
            }
        }
Ejemplo n.º 6
0
        public void LargeSendStream()
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new MemoryStream(new byte[1 << 20]),
                    "Payload.txt",
                    "text/plain"
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));
            }
        }
Ejemplo n.º 7
0
        private ProtoClientConfiguration BuildConfiguration()
        {
            var config = (ProtoConfigurationSection)WebConfigurationManager.GetSection("protoChannel");

            var configuration = new ProtoClientConfiguration
            {
                ServiceAssembly = _serviceAssembly,
                Secure = config.Secure
            };

            if (config.MaxMessageSize > 0)
                configuration.MaxMessageSize = config.MaxMessageSize;

            if (config.MaxStreamSize > 0)
                configuration.MaxStreamSize = config.MaxStreamSize;

            if (config.SkipCertificateValidations)
                configuration.ValidationCallback = (p1, p2, p3, p4) => true;

            int streamManagers =
                (config.DiskStreamManager.ElementInformation.IsPresent ? 1 : 0) +
                (config.MemoryStreamManager.ElementInformation.IsPresent ? 1 : 0) +
                (config.HybridStreamManager.ElementInformation.IsPresent ? 1 : 0);

            if (streamManagers > 1)
                throw new ProtoChannelException("Specify ether a diskStreamManager, memoryStreamManager or hybridStreamManager");

            if (config.DiskStreamManager.ElementInformation.IsPresent)
            {
                if (config.DiskStreamManager.MaxStreamSize > 0)
                    configuration.StreamManager = new DiskStreamManager(config.DiskStreamManager.Path, config.MaxStreamSize);
                else
                    configuration.StreamManager = new DiskStreamManager(config.DiskStreamManager.Path);
            }

            if (config.MemoryStreamManager.ElementInformation.IsPresent)
            {
                if (config.MemoryStreamManager.MaxStreamSize > 0)
                    configuration.StreamManager = new MemoryStreamManager(config.MemoryStreamManager.MaxStreamSize);
                else
                    configuration.StreamManager = new MemoryStreamManager();
            }

            if (config.HybridStreamManager.ElementInformation.IsPresent)
            {
                if (config.HybridStreamManager.MaxStreamSize > 0)
                    configuration.StreamManager = new HybridStreamManager(config.HybridStreamManager.Path, config.HybridStreamManager.MaxMemoryStreamSize, config.HybridStreamManager.MaxStreamSize);
                else
                    configuration.StreamManager = new HybridStreamManager(config.HybridStreamManager.Path, config.HybridStreamManager.MaxMemoryStreamSize);
            }

            return configuration;
        }
Ejemplo n.º 8
0
        private void SendWithStreamFailure(long length, StreamFailureType type, bool expectFailure)
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new FailingStream(length, type),
                    "Payload.txt",
                    "text/plain"
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));

                if (expectFailure)
                    Assert.AreEqual("Receive stream failed", callback.OneWayPingPayload);
                else
                    Assert.AreNotEqual("Receive stream failed", callback.OneWayPingPayload);
            }
        }
Ejemplo n.º 9
0
        private void SendStream(StreamDisposition disposition)
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new MemoryStream(Encoding.UTF8.GetBytes("Payload")),
                    "Payload.txt",
                    "text/plain",
                    disposition
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));
                Assert.True(callback.OneWayPingPayload.Contains(disposition.ToString()));
            }
        }
Ejemplo n.º 10
0
 private ProtoClient(string hostname, int port, ProtoClientConfiguration configuration, int protocolVersion)
     : base(hostname, port, configuration)
 {
     _protocolVersion = protocolVersion;
 }