public PendingSendStream(long length, string streamName, string contentType, StreamDisposition disposition, int associationId, Stream stream)
            : base(length, streamName, contentType, disposition, associationId)
        {
            Require.NotNull(stream, "stream");

            Stream = stream;
        }
示例#2
0
 protected PendingStream(long length, string streamName, string contentType, StreamDisposition disposition, int associationId)
 {
     Length = length;
     StreamName = streamName;
     ContentType = contentType;
     Disposition = disposition;
     AssociationId = associationId;
 }
示例#3
0
        public ProtoStream(long length, string streamName, string contentType, StreamDisposition disposition, Stream stream)
        {
            Length = length;
            StreamName = streamName;
            ContentType = contentType;
            Disposition = disposition;

            _stream = stream;
        }
        public PendingReceiveStream(long length, string streamName, string contentType, StreamDisposition disposition, int associationId, Stream stream)
            : base(length, streamName, contentType, disposition, associationId)
        {
            Require.NotNull(stream, "stream");

            // Stream is not disposed. The receiving party is supposed to dispose
            // of the stream.

            Stream = stream;
        }
        public void RequestStream(StreamDisposition disposition)
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint))
            {
                var response = client.StreamRequest(new StreamRequest
                {
                    Attachment = disposition == StreamDisposition.Attachment
                });

                using (var protoStream = client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                    Assert.AreEqual(protoStream.Disposition, disposition);

                    using (var stream = protoStream.DetachStream())
                    using (var reader = new StreamReader(stream))
                    {
                        Console.WriteLine(reader.ReadToEnd());
                    }
                }
            }
        }
示例#6
0
        internal int SendStream(Stream stream, string streamName, string contentType, StreamDisposition disposition, int? associationId)
        {
            VerifyState();

            return _connection.SendStream(stream, streamName, contentType, disposition, associationId);
        }
示例#7
0
        public int SendStream(Stream stream, string streamName, string contentType, StreamDisposition disposition)
        {
            VerifyState();

            return SendStream(stream, streamName, contentType, disposition, null);
        }
        public int SendStream(Stream stream, string streamName, string contentType, StreamDisposition disposition, int? associationId)
        {
            lock (SyncRoot)
            {
                associationId = _sendStreamManager.RegisterStream(
                    stream, streamName, contentType, disposition, associationId
                );

                // Send the start of the stream.

                long packageStart = BeginSendPackage();

                // Construct the header.

                uint header = (uint)StreamPackageType.StartStream | (uint)associationId.Value << 3;

                var buffer = BitConverterEx.GetNetworkBytes(header);

                Write(buffer, 0, buffer.Length);

                // Write the details of the request.

                WriteMessage(TypeModel, new Messages.StartStream
                {
                    Length = (uint)stream.Length,
                    StreamName = streamName,
                    ContentType = contentType,
                    Attachment = disposition == StreamDisposition.Attachment
                });

                // Send the package.

                EndSendPackage(PackageType.Stream, packageStart);

                return associationId.Value;
            }
        }
        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()));
            }
        }
        public int RegisterStream(Stream stream, string streamName, string contentType, StreamDisposition disposition, int? associationId)
        {
            Require.NotNull(stream, "stream");

            if (_streams.Count == MaxAssociationId)
                throw new ProtoChannelException("No stream association ID's are available");

            // Setting the position throws when the stream cannot be seeked,
            // even when the position already is 0.

            if (stream.Position != 0)
                stream.Position = 0;

            var protoStream = new PendingSendStream(
                stream.Length, streamName, contentType, disposition, GetNextAssociationId(associationId), stream
            );

            _streams.Add(protoStream.AssociationId, protoStream);

            return protoStream.AssociationId;
        }
 public int SendStream(Stream stream, string streamName, string contentType, StreamDisposition disposition)
 {
     return Connection.SendStream(stream, streamName, contentType, disposition);
 }