Ejemplo n.º 1
0
        /// <summary>
        /// Helper static method, allowing to duplicate a message instance.
        /// It will duplicate the message, ONLY if the message is marked as "TransportByReference == false"
        /// or mandatoryDuplication is true.
        /// </summary>
        public static Message DuplicateMessage(Message message, bool mandatoryDuplication)
        {
            //if (mandatoryDuplication == false && message.TransportByReference)
            //{
            //    return message;
            //}

            //if (message is ICloneable)
            //{
            //    return (Message)((ICloneable)message).Clone();
            //}

            MessageContainer container;

            try
            {
                container = new MessageContainer();
                container.SerializeMessage(message);
            }
            catch (Exception exception)
            {
                TracerHelper.TraceError("Exception in message duplication [" + exception.Message + "].");
                throw;
            }

            return(container.CreateMessageInstance());
        }
        /// <summary>
        /// Helper static method, allowing to duplicate a message instance.
        /// It will duplicate the message, ONLY if the message is marked as "TransportByReference == false"
        /// or mandatoryDuplication is true.
        /// </summary>
        public static Message DuplicateMessage(Message message, bool mandatoryDuplication)
        {
            //if (mandatoryDuplication == false && message.TransportByReference)
            //{
            //    return message;
            //}

            //if (message is ICloneable)
            //{
            //    return (Message)((ICloneable)message).Clone();
            //}

            MessageContainer container;
            try
            {
                container = new MessageContainer();
                container.SerializeMessage(message);
            }
            catch (Exception exception)
            {
                TracerHelper.TraceError("Exception in message duplication [" + exception.Message + "].");
                throw;
            }

            return container.CreateMessageInstance();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Message received from the "Pipe".
        /// </summary>
        void _transport_MessageReceivedEvent(string operationContextSessionID, MessageContainer messageContainer)
        {
            TransportMessage message = (TransportMessage)messageContainer.CreateMessageInstance();

            TracerHelper.Trace("[" + message.GetType().Name + "], length [" + messageContainer.MessageStreamLength + "]");

            if (message.IsRequest)
            {     // Request requestMessage.
                { // Mark the request requestMessage with additional fragment in the transportation stack.
                    ArbiterClientId senderID = new ArbiterClientId("PipeChannelID", null, null);
                    senderID.SessionTag = operationContextSessionID;
                    message.TransportInfo.AddTransportInfoUnit(new TransportInfoUnit(Guid.NewGuid(), senderID, this.SubscriptionClientID));
                }

                if (MandatoryRequestMessageReceiverID.HasValue)
                {// There is a default receiver assigned for all messages from this integrator.
                    DoSendCustom(true, Guid.NewGuid(), null, 0, MandatoryRequestMessageReceiverID.Value, this.SubscriptionClientID, message, TimeSpan.Zero);
                }
                else
                {// No explicit mandatory receiver.
                    if (message.TransportInfo.ForwardTransportInfoCount > 0)
                    {
                        // First pop the Session stack, than send the cleared requestMessage.
                        ArbiterClientId?receiverID = message.TransportInfo.PopForwardTransportInfo();
                        DoSendCustom(true, Guid.NewGuid(), null, 0, receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);
                    }
                    else
                    {
                        DoSendCustom(true, Guid.NewGuid(), null, 0, null, this.SubscriptionClientID, message, TimeSpan.Zero);
                    }
                }
            }
            else
            {// Responce requestMessage - send back to whoever sent it to us before.
                // And clear off the initial request information, we are responding now to.
                Guid            sessionID  = message.TransportInfo.CurrentTransportInfo.Value.Id;
                ArbiterClientId?receiverID = message.TransportInfo.CurrentTransportInfo.Value.SenderID;
                message.TransportInfo.PopTransportInfo();

                this.DoSendCustom(false, sessionID, null, 0,
                                  receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);
            }
        }
        /// <summary>
        /// Handle a requestMessage received trough the transport pipe.
        /// </summary>
        /// <param name="messageContainer"></param>
        void _transport_MessageReceivedEvent(MessageContainer messageContainer)
        {
            TransportMessage message = (TransportMessage)messageContainer.CreateMessageInstance();
            TracerHelper.Trace("[" + message.GetType().Name + "], length [" + messageContainer.MessageStreamLength + "]");

            if (message.IsRequest)
            {// Request requestMessage.

                if (MandatoryRequestMessageReceiverID.HasValue)
                {// There is a default receiver assigned for all messages from this integrator.
                    DoSendCustom(true, Guid.NewGuid(), null, 0, MandatoryRequestMessageReceiverID.Value, this.SubscriptionClientID, message, TimeSpan.Zero);
                }
                else
                {// No explicit mandatory receiver.

                    if (message.TransportInfo.ForwardTransportInfoCount > 0)
                    {
                        // First pop the Session stack, than send the cleared requestMessage.
                        ArbiterClientId? receiverID = message.TransportInfo.PopForwardTransportInfo();
                        DoSendCustom(true, Guid.NewGuid(), null, 0, receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);

                    }
                    else
                    {
                        DoSendCustom(true, Guid.NewGuid(), null, 0, null, this.SubscriptionClientID, message, TimeSpan.Zero);
                    }
                }

            }
            else
            {// Responce requestMessage - send back to whoever sent it to us before.

                // And clear off the initial request information, we are responding now to.
                Guid sessionID = message.TransportInfo.CurrentTransportInfo.Value.Id;
                ArbiterClientId? receiverID = message.TransportInfo.CurrentTransportInfo.Value.SenderID;
                message.TransportInfo.PopTransportInfo();

                this.DoSendCustom(false, sessionID, null, 0,
                    receiverID, this.SubscriptionClientID, message, TimeSpan.Zero);

            }
        }