Exemplo n.º 1
0
        public void GetBytes()
        {
            var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null);

            var bytes = request.GetBytes();

            var expectedBytesLength = 0;
#if TUNING
            expectedBytesLength += 4; // Length
#endif
            expectedBytesLength += 1; // Type
            expectedBytesLength += 4; // RequestId
            expectedBytesLength += 4; // Handle length
            expectedBytesLength += _handle.Length; // Handle

            Assert.AreEqual(expectedBytesLength, bytes.Length);

            var sshDataStream = new SshDataStream(bytes);

#if TUNING
            Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32());
#endif
            Assert.AreEqual((byte)SftpMessageTypes.Close, sshDataStream.ReadByte());
            Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());

            Assert.AreEqual((uint)_handle.Length, sshDataStream.ReadUInt32());
            var actualHandle = new byte[_handle.Length];
            sshDataStream.Read(actualHandle, 0, actualHandle.Length);
            Assert.IsTrue(_handle.SequenceEqual(actualHandle));

            Assert.IsTrue(sshDataStream.IsEndOfData);
        }
Exemplo n.º 2
0
        public void Constructor()
        {
            var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null);

            Assert.AreSame(_handle, request.Handle);
            Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
            Assert.AreEqual(_requestId, request.RequestId);
            Assert.AreEqual(SftpMessageTypes.Close, request.SftpMessageType);
        }
Exemplo n.º 3
0
        public void Complete_SftpStatusResponse()
        {
            IList<SftpStatusResponse> statusActionInvocations = new List<SftpStatusResponse>();

            Action<SftpStatusResponse> statusAction = statusActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs SSH_FXP_CLOSE request.
        /// </summary>
        /// <param name="handle">The handle.</param>
        internal void RequestClose(byte[] handle)
        {
            SshException exception = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpCloseRequest(this.ProtocolVersion, this.NextRequestId, handle,
                    (response) =>
                    {
                        exception = this.GetSftpException(response);
                        wait.Set();
                    });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }

            if (exception != null)
            {
                throw exception;
            }
        }
        /// <summary>
        /// Performs SSH_FXP_CLOSE request.
        /// </summary>
        /// <param name="handle">The handle.</param>
        internal void RequestClose(byte[] handle)
        {
            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpCloseRequest(this.NextRequestId, handle,
                    (response) =>
                    {
                        if (response.StatusCode == StatusCodes.Ok)
                        {
                            wait.Set();
                        }
                        else
                        {
                            this.ThrowSftpException(response);
                        }
                    });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs SSH_FXP_CLOSE request.
        /// </summary>
        /// <param name="handle">The handle.</param>
        public void RequestClose(byte[] handle)
        {
            SshException exception = null;

            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpCloseRequest(ProtocolVersion, NextRequestId, handle,
                    response =>
                        {
                            exception = GetSftpException(response);
                            wait.Set();
                        });

                SendRequest(request);

                WaitOnHandle(wait, OperationTimeout);
            }

            if (exception != null)
            {
                throw exception;
            }
        }