public void RemoveRequest(Request request)
		{
            _request = null;
		}
		public void AddRequest(Request request)
		{
            _request = request;
		}
        private IEnumerable<Message> CreateEndRequestMessages(Request request)
        {
            yield return new Message(MessageType.StandardError, request.Id, ByteArray.Empty);
			yield return new Message(MessageType.StandardOutput, request.Id, ByteArray.Empty);

            var body = new EndRequestMessageBody(request.ExitCode, ProtocolStatus.RequestComplete);
			yield return new Message(MessageType.EndRequest, request.Id, body.ToArray());
        }
		/// <summary>
		/// Send a request output data to the output or error stream
		/// </summary>
		/// <param name="request">Request</param>
		/// <param name="streamType"></param>
		/// <param name="data"></param>
		protected virtual void SendRequestOutput(Request request, MessageType streamType, ByteArray data)
		{
			if (streamType != MessageType.StandardError &&
				streamType != MessageType.StandardOutput)
					throw new ArgumentException("streamType");

			while (data.Count > 0)
			{
				ushort length = (ushort)Math.Min(data.Count, Consts.MaxMessageBodySize);
				this.SendMessage(new Message(streamType, request.Id, data.SubArray(0, length)));
				data = data.SubArray(length, true);
			}
		}
		/// <summary>
		/// Ends a request
		/// </summary>
		/// <param name="request"><typeparamref name="Request"/> to end</param>
		protected virtual void EndRequest(Request request)
		{
            this.SendMessages(this.CreateEndRequestMessages(request));
            _requestsRepository.RemoveRequest(request);
		}