/// <summary> /// Handles the error, occured during the input message handling. /// try to send an error message to remote side /// </summary> ///<exception cref="InvalidOperationException">Critical implementation exception</exception> public void HandleRequestProcessingError(ErrorMessage errorInfo, bool isFatal) { if (!_channel.IsConnected) { return; } try { _sender.SendError(errorInfo); if (isFatal) { _channel.DisconnectBecauseOf(errorInfo); } } catch (LocalSerializationException e) { throw new InvalidOperationException("Error-serializer exception", e); } catch (ConnectionIsNotEstablishedYet) { throw new InvalidOperationException("Channel implementation error. Chanel " + _channel.GetType().Name + " throws ConnectionIsNotEstablishedYet when it was connected"); } catch (ConnectionIsLostException) { _channel.Disconnect(); } }
/// <summary> /// Serializes data to the stream and sends it /// </summary> ///<exception cref="ConnectionIsLostException"></exception> ///<exception cref="LocalSerializationException">specified serializer does not fit the arguments</exception> private void Write(object[] values, ISerializer serializer, MemoryStream stream) { try { if (values.Length == 1) { serializer.Serialize(values[0], stream); } else if (values.Length > 1) { serializer.Serialize(values, stream); } } catch (Exception e) { _channel.Disconnect(); throw new LocalSerializationException(null, null, "Serialization failed", e); } stream.Position = 0; _channel.Write(stream); }