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); }
public bool WriteFrame(PipeFrame frame) { if (this._isDisposed) { throw new ObjectDisposedException("_stream"); } if (!this._isClosed) { if (this.IsConnected) { try { frame.WriteStream((Stream)this._stream); return(true); } catch (IOException ex) { this.Logger.Error("Failed to write frame because of a IO Exception: {0}", (object)ex.Message); } catch (ObjectDisposedException ex) { this.Logger.Warning("Failed to write frame as the stream was already disposed"); } catch (InvalidOperationException ex) { this.Logger.Warning("Failed to write frame because of a invalid operation"); } return(false); } } this.Logger.Error("Failed to write frame because the stream is closed"); return(false); }
public bool WriteFrame(PipeFrame frame) { if (!this.IsConnected) { throw new InvalidPipeException("Cannot write Native Stream as pipe is not connected"); } using (MemoryStream memoryStream = new MemoryStream()) { frame.WriteStream((Stream)memoryStream); byte[] array = memoryStream.ToArray(); return(NativePipe.WriteFrame(array, array.Length)); } }
/// <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) { Console.WriteLine("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) { Console.WriteLine($"Failed to write frame because of a IO Exception: {io.Message}"); } catch (ObjectDisposedException) { Console.WriteLine("Failed to write frame as the stream was already disposed"); } catch (InvalidOperationException) { Console.WriteLine("Failed to write frame because of a invalid operation"); } //We must have failed the try catch return(false); }