/// <summary> /// Implementing the ISerializable to provide a faster, more optimized /// serialization for the class using the fast serialization elements. /// </summary> public Envelope(SerializationInfo info, StreamingContext context) { // Get from the info. SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[]))); _duplicationMode = (DuplicationModeEnum)reader.ReadInt32(); _executionModel = (ExecutionModelEnum)reader.ReadInt32(); _message = reader.ReadObject(); _transportHistory = (EnvelopeTransportation)reader.ReadObject(); _transportTargetAddress = (EnvelopeTransportation)reader.ReadObject(); }
/// <summary> /// Implementing the ISerializable to provide a faster, more optimized /// serialization for the class using the fast serialization elements. /// </summary> public Envelope(SerializationInfo info, StreamingContext context) { // Get from the info. SerializationReader reader = new SerializationReader((byte[])info.GetValue("data", typeof(byte[]))); _duplicationMode = (DuplicationModeEnum)reader.ReadInt32(); _executionModel = (ExecutionModelEnum)reader.ReadInt32(); _message = reader.ReadObject(); _transportHistory = (EnvelopeTransportation)reader.ReadObject(); _transportTargetAddress = (EnvelopeTransportation)reader.ReadObject(); }
/// <summary> /// This may actually *not* duplicate the object, since it follows the DuplicationMode. /// </summary> /// <returns></returns> public virtual Envelope Duplicate(ISerializer serializer) { Envelope newEnvelope = this; if (_duplicationMode == DuplicationModeEnum.DuplicateEnvelope || _duplicationMode == DuplicationModeEnum.DuplicateBoth) { //newObject = (Envelope)this.MemberwiseClone(); //newObject = (Envelope)serializer.Duplicate(this); newEnvelope = new Envelope() { _duplicationMode = this._duplicationMode }; EnvelopeTransportation transportHistory = _transportHistory; EnvelopeTransportation transportTargetAddress = _transportTargetAddress; if (transportHistory != null) { newEnvelope._transportHistory = transportHistory.Duplicate(); } if (transportTargetAddress != null) { newEnvelope._transportTargetAddress = transportTargetAddress.Duplicate(); } } if (_message != null && (_duplicationMode == DuplicationModeEnum.DuplicateMessage || _duplicationMode == DuplicationModeEnum.DuplicateBoth)) { if (_message is ICloneable) { newEnvelope._message = ((ICloneable)_message).Clone(); } else if (_message.GetType().IsClass) {// We need to use the slow cloning mechanism. newEnvelope._message = serializer.Duplicate(_message); #if Matrix_Diagnostics SystemMonitor.OperationErrorIf(newEnvelope._message == null, "Failed to serialize message [" + _message.GetType().Name + "]."); #endif } // Value type items are supposed to be copied by referencing. } return(newEnvelope); }
/// <summary> /// Create a responding envelope transport. /// </summary> public static EnvelopeTransportation CreateResponseTransport(EnvelopeTransportation transport) { EnvelopeTransportation result = new EnvelopeTransportation(); List <EnvelopeStamp> responseStamps = new List <EnvelopeStamp>(); lock (transport._stamps) { for (int i = transport._stamps.Count - 1; i >= 0; i--) { EnvelopeStamp sourceStamp = transport._stamps[i]; EnvelopeStamp newStamp = new EnvelopeStamp(sourceStamp.MessageBusStampId, sourceStamp.SenderIndex, sourceStamp.ReceiverIndex); result._stamps.Add(newStamp); } } return(result); }
/// <summary> /// Create a responding envelope transport. /// </summary> public static EnvelopeTransportation CreateResponseTransport(EnvelopeTransportation transport) { EnvelopeTransportation result = new EnvelopeTransportation(); List<EnvelopeStamp> responseStamps = new List<EnvelopeStamp>(); lock (transport._stamps) { for (int i = transport._stamps.Count - 1; i >= 0; i--) { EnvelopeStamp sourceStamp = transport._stamps[i]; EnvelopeStamp newStamp = new EnvelopeStamp(sourceStamp.MessageBusStampId, sourceStamp.SenderIndex, sourceStamp.ReceiverIndex); result._stamps.Add(newStamp); } } return result; }
/// <summary> /// Send a responce to an envelope received. /// </summary> /// <param name="receivedEnvelope">The enveloped received, we shall respond to it.</param> /// <param name="envelope">The new envelope, we are sending as responce.</param> /// <returns></returns> public Outcomes Respond(Envelope receivedEnvelope, Envelope envelope) { envelope.Address = EnvelopeTransportation.CreateResponseTransport(receivedEnvelope.History); return(Send(envelope)); }