public bool WriteFrame(PipeFrame frame) { //Write the frame. We are assuming proper duplex connection here if (!IsConnected) { Logger.Error("Failed to write frame because the stream is closed"); return(false); } try { //Write the pipe frame.WriteStream(_stream); return(true); } catch (IOException io) { Logger.Error("Failed to write frame because of a IO Exception: {0}", io.Message); } catch (ObjectDisposedException) { Logger.Warning("Failed to write frame as the stream was already disposed"); } catch (InvalidOperationException) { Logger.Warning("Failed to write frame because of a invalid operation"); } //We must have failed the try catch return(false); }
/// <summary> /// Attempts to write a frame /// </summary> /// <param name="frame"></param> /// <returns></returns> public bool WriteFrame(PipeFrame frame) { if (!IsConnected) { throw new InvalidPipeException("Cannot write Native Stream as pipe is not connected"); } //Create a memory stream so we can write it to the pipe using (MemoryStream stream = new MemoryStream()) { //Write the stream and the send it to the pipe frame.WriteStream(stream); //Get the bytes and send it byte[] bytes = stream.ToArray(); return(NativePipe.WriteFrame(bytes, bytes.Length)); } }