/// <summary> /// Deserialize data from the parameters with the provided configuration. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns>Deserialized message</returns> /// <exception cref="System.FormatException"> /// </exception> public override IMessage Deserialize(MessageSinkParameters parameters) { if (parameters == null) { ThrowHelper.ThrowArgumentNullException("parameters"); } if ((parameters.ConfigurationToDeserialize as MessageSinkConfiguration) == null) { throw new FormatException(string.Format("Configuration class type is not {0}", typeof(MessageSinkConfiguration).FullName)); } IMessage result = null; try { MessageSinkConfiguration config = (MessageSinkConfiguration)parameters.ConfigurationToDeserialize; using (MemoryStream ms = new MemoryStream(config.DecompressData ? Decompress(parameters.SerializedData) : parameters.SerializedData)) { ms.Position = 0; result = mFormatter.Read(ms); } } catch (Exception ex) { throw new FormatException(ex.Message, ex); } return(result); }
/// <summary> /// Serialize data and save it into the return object. Return object optionaly stores information to deserialization. /// </summary> /// <param name="message">The message.</param> /// <returns>Message Sink parameters</returns> /// <exception cref="System.FormatException"></exception> public override MessageSinkParameters Serialize(IMessage message) { if (message == null) { ThrowHelper.ThrowArgumentNullException("message"); } MessageSinkParameters result = null; using (MemoryStream ms = new MemoryStream()) { try { mFormatter.Write(ms, message); byte[] finalData = null; bool comp = false; if (mCompressData) { if (ms.Length > this.mCompressDataOverSize && this.mCompressDataOverSize >= 0) { comp = true; finalData = Compress(ms.ToArray()); } else { finalData = ms.ToArray(); } } else { finalData = ms.ToArray(); } result = new MessageSinkParameters(new MessageSinkConfiguration(mMessageSinkId, comp), finalData); } catch (Exception ex) { throw new FormatException(ex.Message, ex); } } return(result); }
/// <summary> /// Deserialize data from the parameters with the provided configuration. /// </summary> /// <param name="parameters">The parameters.</param> /// <returns> /// Deserialized message content /// </returns> public abstract IMessage Deserialize(MessageSinkParameters parameters);