Example #1
0
 public void SetMessageProperties(MsmqIntegrationMessageProperty property)
 {
     property.AcknowledgeType     = new AcknowledgeTypes?((AcknowledgeTypes)this.acknowledge.Value);
     property.Acknowledgment      = new Acknowledgment?((Acknowledgment)base.Class.Value);
     property.AdministrationQueue = GetQueueName(this.adminQueue.GetValue(this.adminQueueLength.Value));
     property.AppSpecific         = new int?(this.appSpecific.Value);
     property.ArrivedTime         = new DateTime?(MsmqDateTime.ToDateTime(this.arrivedTime.Value).ToLocalTime());
     property.Authenticated       = new bool?(this.authenticated.Value != 0);
     property.BodyType            = new int?(this.bodyType.Value);
     property.CorrelationId       = MsmqMessageId.ToString(this.correlationId.Buffer);
     property.DestinationQueue    = GetQueueName(this.destinationQueue.GetValue(this.destinationQueueLength.Value));
     property.Extension           = this.extension.GetBufferCopy(this.extensionLength.Value);
     property.Id    = MsmqMessageId.ToString(base.MessageId.Buffer);
     property.Label = this.label.GetValue(this.labelLength.Value);
     if (base.Class.Value == 0)
     {
         property.MessageType = 2;
     }
     else if (base.Class.Value == 1)
     {
         property.MessageType = 3;
     }
     else
     {
         property.MessageType = 1;
     }
     property.Priority      = new MessagePriority?((MessagePriority)this.priority.Value);
     property.ResponseQueue = GetQueueName(this.responseFormatName.GetValue(this.responseFormatNameLength.Value));
     property.SenderId      = base.SenderId.GetBufferCopy(base.SenderIdLength.Value);
     property.SentTime      = new DateTime?(MsmqDateTime.ToDateTime(this.sentTime.Value).ToLocalTime());
     property.InternalSetTimeToReachQueue(MsmqDuration.ToTimeSpan(this.timeToReachQueue.Value));
 }
        public void SetMessageProperties(MsmqIntegrationMessageProperty property)
        {
            property.AcknowledgeType     = (System.Messaging.AcknowledgeTypes) this.acknowledge.Value;
            property.Acknowledgment      = (System.Messaging.Acknowledgment) this.Class.Value;
            property.AdministrationQueue = GetQueueName(this.adminQueue.GetValue(this.adminQueueLength.Value));
            property.AppSpecific         = this.appSpecific.Value;
            property.ArrivedTime         = MsmqDateTime.ToDateTime(this.arrivedTime.Value).ToLocalTime();
            property.Authenticated       = this.authenticated.Value != 0;
            property.BodyType            = this.bodyType.Value;
            property.CorrelationId       = MsmqMessageId.ToString(this.correlationId.Buffer);
            property.DestinationQueue    = GetQueueName(this.destinationQueue.GetValue(this.destinationQueueLength.Value));
            property.Extension           = this.extension.GetBufferCopy(this.extensionLength.Value);
            property.Id    = MsmqMessageId.ToString(this.MessageId.Buffer);
            property.Label = this.label.GetValue(this.labelLength.Value);

            if (this.Class.Value == UnsafeNativeMethods.MQMSG_CLASS_NORMAL)
            {
                property.MessageType = System.Messaging.MessageType.Normal;
            }
            else if (this.Class.Value == UnsafeNativeMethods.MQMSG_CLASS_REPORT)
            {
                property.MessageType = System.Messaging.MessageType.Report;
            }
            else
            {
                property.MessageType = System.Messaging.MessageType.Acknowledgment;
            }

            property.Priority      = (System.Messaging.MessagePriority) this.priority.Value;
            property.ResponseQueue = GetQueueName(this.responseFormatName.GetValue(this.responseFormatNameLength.Value));
            property.SenderId      = this.SenderId.GetBufferCopy(this.SenderIdLength.Value);
            property.SentTime      = MsmqDateTime.ToDateTime(this.sentTime.Value).ToLocalTime();
            property.InternalSetTimeToReachQueue(MsmqDuration.ToTimeSpan(this.timeToReachQueue.Value));
        }
Example #3
0
 internal MsmqMessageProperty(MsmqInputMessage msmqMessage)
 {
     if (null == msmqMessage)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("msmqMessage");
     }
     this.lookupId = msmqMessage.LookupId.Value;
     if (msmqMessage.AbortCount != null)
     {
         this.abortCount = msmqMessage.AbortCount.Value;
     }
     if (msmqMessage.MoveCount != null)
     {
         this.moveCount = msmqMessage.MoveCount.Value;
     }
     this.acknowledge = (int)(ushort)msmqMessage.Class.Value;
     this.messageId   = MsmqMessageId.ToString(msmqMessage.MessageId.Buffer);
 }
 public MsmqIntegrationOutputMessage(MsmqChannelFactoryBase <IOutputChannel> factory, int bodySize, EndpointAddress remoteAddress, MsmqIntegrationMessageProperty property) : base(factory, bodySize, remoteAddress, 8)
 {
     if (property.AcknowledgeType.HasValue)
     {
         this.EnsureAcknowledgeProperty((byte)property.AcknowledgeType.Value);
     }
     if (null != property.AdministrationQueue)
     {
         this.EnsureAdminQueueProperty(property.AdministrationQueue, false);
     }
     if (property.AppSpecific.HasValue)
     {
         this.appSpecific = new NativeMsmqMessage.IntProperty(this, 8, property.AppSpecific.Value);
     }
     if (property.BodyType.HasValue)
     {
         base.EnsureBodyTypeProperty(property.BodyType.Value);
     }
     if (property.CorrelationId != null)
     {
         this.correlationId = new NativeMsmqMessage.BufferProperty(this, 3, MsmqMessageId.FromString(property.CorrelationId));
     }
     if (property.Extension != null)
     {
         this.extension = new NativeMsmqMessage.BufferProperty(this, 0x23, property.Extension);
     }
     if (property.Label != null)
     {
         this.label = new NativeMsmqMessage.StringProperty(this, 11, property.Label);
     }
     if (property.Priority.HasValue)
     {
         this.priority = new NativeMsmqMessage.ByteProperty(this, 4, (byte)property.Priority.Value);
     }
     if (null != property.ResponseQueue)
     {
         this.EnsureResponseQueueProperty(property.ResponseQueue);
     }
     if (property.TimeToReachQueue.HasValue)
     {
         base.EnsureTimeToReachQueueProperty(MsmqDuration.FromTimeSpan(property.TimeToReachQueue.Value));
     }
 }
        protected override void OnSend(Message message, TimeSpan timeout)
        {
            int length;
            MessageProperties properties            = message.Properties;
            Stream            stream                = null;
            MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message);

            if (property == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("MsmqMessageDoesntHaveIntegrationProperty")));
            }
            if (property.Body != null)
            {
                stream = this.factory.Serialize(property);
            }
            if (stream == null)
            {
                length = 0;
            }
            else
            {
                if (stream.Length > 0x7fffffffL)
                {
                    throw TraceUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("MessageSizeMustBeInIntegerRange")), message);
                }
                length = (int)stream.Length;
            }
            using (MsmqIntegrationOutputMessage message2 = new MsmqIntegrationOutputMessage(this.factory, length, this.RemoteAddress, property))
            {
                message2.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout);
                if (stream != null)
                {
                    int num3;
                    stream.Position = 0L;
                    for (int i = length; i > 0; i -= num3)
                    {
                        num3 = stream.Read(message2.Body.Buffer, 0, i);
                    }
                }
                bool lockHeld = false;
                try
                {
                    Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel);
                    this.msmqQueue.Send(message2, this.transactionMode);
                    MsmqDiagnostics.DatagramSent(message2.MessageId, message);
                    property.Id = MsmqMessageId.ToString(message2.MessageId.Buffer);
                }
                catch (MsmqException exception)
                {
                    if (exception.FaultSender)
                    {
                        base.Fault();
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized);
                }
                finally
                {
                    if (lockHeld)
                    {
                        Msmq.LeaveXPSendLock();
                    }
                }
            }
        }
            public MsmqIntegrationOutputMessage(
                MsmqChannelFactoryBase <IOutputChannel> factory,
                int bodySize,
                EndpointAddress remoteAddress,
                MsmqIntegrationMessageProperty property)
                : base(factory, bodySize, remoteAddress, 8)
            {
                if (null == property)
                {
                    Fx.Assert("MsmqIntegrationMessageProperty expected");
                }

                if (property.AcknowledgeType.HasValue)
                {
                    EnsureAcknowledgeProperty((byte)property.AcknowledgeType.Value);
                }

                if (null != property.AdministrationQueue)
                {
                    EnsureAdminQueueProperty(property.AdministrationQueue, false);
                }

                if (property.AppSpecific.HasValue)
                {
                    this.appSpecific = new IntProperty(this, UnsafeNativeMethods.PROPID_M_APPSPECIFIC, property.AppSpecific.Value);
                }

                if (property.BodyType.HasValue)
                {
                    EnsureBodyTypeProperty(property.BodyType.Value);
                }

                if (null != property.CorrelationId)
                {
                    this.correlationId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_CORRELATIONID, MsmqMessageId.FromString(property.CorrelationId));
                }

                if (null != property.Extension)
                {
                    this.extension = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION, property.Extension);
                }

                if (null != property.Label)
                {
                    this.label = new StringProperty(this, UnsafeNativeMethods.PROPID_M_LABEL, property.Label);
                }

                if (property.Priority.HasValue)
                {
                    this.priority = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_PRIORITY, (byte)property.Priority.Value);
                }

                if (null != property.ResponseQueue)
                {
                    EnsureResponseQueueProperty(property.ResponseQueue);
                }

                if (property.TimeToReachQueue.HasValue)
                {
                    EnsureTimeToReachQueueProperty(MsmqDuration.FromTimeSpan(property.TimeToReachQueue.Value));
                }
            }
        protected override void OnSend(Message message, TimeSpan timeout)
        {
            MessageProperties properties = message.Properties;
            Stream            stream     = null;

            MsmqIntegrationMessageProperty property = MsmqIntegrationMessageProperty.Get(message);

            if (null == property)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.MsmqMessageDoesntHaveIntegrationProperty)));
            }
            if (null != property.Body)
            {
                stream = this.factory.Serialize(property);
            }

            int size;

            if (stream == null)
            {
                size = 0;
            }
            else
            {
                if (stream.Length > int.MaxValue)
                {
                    throw TraceUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.MessageSizeMustBeInIntegerRange)), message);
                }

                size = (int)stream.Length;
            }

            using (MsmqIntegrationOutputMessage msmqMessage = new MsmqIntegrationOutputMessage(this.factory, size, this.RemoteAddress, property))
            {
                msmqMessage.ApplyCertificateIfNeeded(this.certificateTokenProvider, this.factory.MsmqTransportSecurity.MsmqAuthenticationMode, timeout);

                if (stream != null)
                {
                    stream.Position = 0;
                    for (int bytesRemaining = size; bytesRemaining > 0;)
                    {
                        int bytesRead = stream.Read(msmqMessage.Body.Buffer, 0, bytesRemaining);
                        bytesRemaining -= bytesRead;
                    }
                }

                bool lockHeld = false;
                try
                {
                    Msmq.EnterXPSendLock(out lockHeld, this.factory.MsmqTransportSecurity.MsmqProtectionLevel);
                    this.msmqQueue.Send(msmqMessage, this.transactionMode);
                    MsmqDiagnostics.DatagramSent(msmqMessage.MessageId, message);
                    property.Id = MsmqMessageId.ToString(msmqMessage.MessageId.Buffer);
                }
                catch (MsmqException ex)
                {
                    if (ex.FaultSender)
                    {
                        this.Fault();
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized);
                }
                finally
                {
                    if (lockHeld)
                    {
                        Msmq.LeaveXPSendLock();
                    }
                }
            }
        }