/// <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)); } }
/// <summary> /// Writes a frame to the pipe /// </summary> /// <param name="frame"></param> /// <returns></returns> public bool WriteFrame(PipeFrame frame) { if (_isDisposed) { throw new ObjectDisposedException("_stream"); } //Write the frame. We are assuming proper duplex connection here if (_isClosed || !IsConnected) { Logger.Error("Failed to write frame because the stream is closed"); return(false); } try { //Write the pipe //This can only happen on the main thread so it should be fine. 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); }