private int ReceiveCoreDtcTransacted(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
        {
            int             num2;
            IDtcTransaction nativeTransaction = this.GetNativeTransaction(transactionMode);
            int             num        = TimeoutHelper.ToMilliseconds(timeout);
            IntPtr          properties = message.Pin();

            try
            {
                if (nativeTransaction != null)
                {
                    try
                    {
                        return(UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), num, action, properties, null, IntPtr.Zero, IntPtr.Zero, nativeTransaction));
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(nativeTransaction);
                    }
                }
                num2 = UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), num, action, properties, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)this.GetTransactionConstant(transactionMode));
            }
            finally
            {
                message.Unpin();
            }
            return(num2);
        }
Пример #2
0
        int SendDtcTransacted(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode);

            MsmqQueueHandle handle = GetHandle();
            IntPtr          nativePropertiesPointer = message.Pin();

            try
            {
                if (dtcTransaction != null)
                {
                    try
                    {
                        return(UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                                 dtcTransaction));
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(dtcTransaction);
                    }
                }
                else
                {
                    return(UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                             (IntPtr)GetTransactionConstant(transactionMode)));
                }
            }
            finally
            {
                message.Unpin();
            }
        }
Пример #3
0
        unsafe int ReceiveCoreDtcTransacted(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
        {
            IDtcTransaction dtcTransaction        = GetNativeTransaction(transactionMode);
            int             timeoutInMilliseconds = TimeoutHelper.ToMilliseconds(timeout);

            IntPtr nativePropertiesPointer = message.Pin();

            try
            {
                if (dtcTransaction != null)
                {
                    try
                    {
                        return(UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                                    action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, dtcTransaction));
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(dtcTransaction);
                    }
                }
                else
                {
                    return(UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                                action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode)));
                }
            }
            finally
            {
                message.Unpin();
            }
        }
        public void Send(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            int error = 0;

            if (this.RequiresDtcTransaction(transactionMode))
            {
                error = this.SendDtcTransacted(message, transactionMode);
            }
            else
            {
                MsmqQueueHandle handle     = this.GetHandle();
                IntPtr          properties = message.Pin();
                try
                {
                    error = UnsafeNativeMethods.MQSendMessage(handle, properties, (IntPtr)this.GetTransactionConstant(transactionMode));
                }
                finally
                {
                    message.Unpin();
                }
            }
            if (error != 0)
            {
                if (IsErrorDueToStaleHandle(error))
                {
                    this.HandleIsStale(this.handle);
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqSendError", new object[] { MsmqError.GetErrorString(error) }), error));
            }
        }
        private int SendDtcTransacted(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            int             num;
            IDtcTransaction nativeTransaction = this.GetNativeTransaction(transactionMode);
            MsmqQueueHandle handle            = this.GetHandle();
            IntPtr          properties        = message.Pin();

            try
            {
                if (nativeTransaction != null)
                {
                    try
                    {
                        return(UnsafeNativeMethods.MQSendMessage(handle, properties, nativeTransaction));
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(nativeTransaction);
                    }
                }
                num = UnsafeNativeMethods.MQSendMessage(handle, properties, (IntPtr)this.GetTransactionConstant(transactionMode));
            }
            finally
            {
                message.Unpin();
            }
            return(num);
        }
        private ReceiveResult TryReceiveInternal(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
        {
            TimeoutHelper   helper = new TimeoutHelper(timeout);
            MsmqQueueHandle handle = this.GetHandle();

            while (true)
            {
                int error = this.ReceiveCore(handle, message, helper.RemainingTime(), transactionMode, action);
                if (error == 0)
                {
                    return(ReceiveResult.MessageReceived);
                }
                if (!IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    if (error == -1072824293)
                    {
                        return(ReceiveResult.Timeout);
                    }
                    if (error == -1072824312)
                    {
                        return(ReceiveResult.OperationCancelled);
                    }
                    if (error == -1072824313)
                    {
                        return(ReceiveResult.OperationCancelled);
                    }
                    if (IsErrorDueToStaleHandle(error))
                    {
                        this.HandleIsStale(handle);
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqReceiveError", new object[] { MsmqError.GetErrorString(error) }), error));
                }
                message.GrowBuffers();
            }
        }
Пример #7
0
        public void Send(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            int error = 0;

            if (RequiresDtcTransaction(transactionMode))
            {
                error = SendDtcTransacted(message, transactionMode);
            }
            else
            {
                MsmqQueueHandle handle = GetHandle();
                IntPtr          nativePropertiesPointer = message.Pin();
                try
                {
                    error = UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                              (IntPtr)GetTransactionConstant(transactionMode));
                }
                finally
                {
                    message.Unpin();
                }
            }

            if (error != 0)
            {
                if (IsErrorDueToStaleHandle(error))
                {
                    HandleIsStale(handle);
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqSendError, MsmqError.GetErrorString(error)), error));
            }
        }
 protected MsmqProperty(NativeMsmqMessage message, int id, ushort vt)
 {
     this.variants = message.variants;
     this.index    = message.nativeProperties.count++;
     message.variants[this.index].vt = vt;
     message.ids[this.index]         = id;
     message.properties[this.index]  = this;
 }
 public unsafe TryReceiveAsyncResult(MsmqQueue msmqQueue, NativeMsmqMessage message, TimeSpan timeout, int action, AsyncCallback callback, object state) : base(callback, state)
 {
     this.nativeOverlapped = null;
     this.msmqQueue        = msmqQueue;
     this.message          = message;
     this.action           = action;
     this.timeoutHelper    = new TimeoutHelper(timeout);
     this.StartReceive(true);
 }
Пример #10
0
        public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            MsmqQueue.MoveReceiveResult result3;
            TimeoutHelper helper   = new TimeoutHelper(timeout);
            bool          flag     = false;
            long          lookupId = 0L;

            while (!flag)
            {
                using (MsmqMessageLookupId id = new MsmqMessageLookupId())
                {
                    MsmqQueue.ReceiveResult result = base.TryPeek(id, helper.RemainingTime());
                    if (result != MsmqQueue.ReceiveResult.MessageReceived)
                    {
                        return(result);
                    }
                    lookupId = id.lookupId.Value;
                }
                try
                {
                    if (base.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None) == MsmqQueue.MoveReceiveResult.Succeeded)
                    {
                        flag = true;
                    }
                    continue;
                }
                catch (MsmqException exception)
                {
                    MsmqDiagnostics.ExpectedException(exception);
                    continue;
                }
            }
            try
            {
                result3 = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, 0x40000010);
            }
            catch (MsmqException exception2)
            {
                this.UnlockMessage(lookupId, TimeSpan.Zero);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2);
            }
            if (result3 == MsmqQueue.MoveReceiveResult.Succeeded)
            {
                return(MsmqQueue.ReceiveResult.MessageReceived);
            }
            this.UnlockMessage(lookupId, TimeSpan.Zero);
            return(MsmqQueue.ReceiveResult.OperationCancelled);
        }
Пример #11
0
        public MoveReceiveResult TryReceiveByLookupId(long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action)
        {
            MsmqQueueHandle handle = GetHandle();
            int             error  = 0;

            while (true)
            {
                try
                {
                    error = ReceiveByLookupIdCore(handle, lookupId, message, transactionMode, action);
                }
                catch (ObjectDisposedException ex)
                {
                    // ---- with Close
                    MsmqDiagnostics.ExpectedException(ex);
                    return(MoveReceiveResult.Succeeded);
                }

                if (0 == error)
                {
                    return(MoveReceiveResult.Succeeded);
                }

                if (IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    message.GrowBuffers();
                    continue;
                }
                else if (UnsafeNativeMethods.MQ_ERROR_MESSAGE_NOT_FOUND == error)
                {
                    return(MoveReceiveResult.MessageNotFound);
                }
                else if (UnsafeNativeMethods.MQ_ERROR_MESSAGE_LOCKED_UNDER_TRANSACTION == error)
                {
                    return(MoveReceiveResult.MessageLockedUnderTransaction);
                }
                else if (IsErrorDueToStaleHandle(error))
                {
                    HandleIsStale(handle);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqReceiveError, MsmqError.GetErrorString(error)), error));
            }
        }
Пример #12
0
 unsafe int ReceiveByLookupIdCore(MsmqQueueHandle handle, long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action)
 {
     if (RequiresDtcTransaction(transactionMode))
     {
         return(ReceiveByLookupIdCoreDtcTransacted(handle, lookupId, message, transactionMode, action));
     }
     else
     {
         IntPtr nativePropertiesPointer = message.Pin();
         try
         {
             return(UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, nativePropertiesPointer, null, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode)));
         }
         finally
         {
             message.Unpin();
         }
     }
 }
        private int ReceiveByLookupIdCore(MsmqQueueHandle handle, long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action)
        {
            int num;

            if (this.RequiresDtcTransaction(transactionMode))
            {
                return(this.ReceiveByLookupIdCoreDtcTransacted(handle, lookupId, message, transactionMode, action));
            }
            IntPtr properties = message.Pin();

            try
            {
                num = UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, properties, null, IntPtr.Zero, (IntPtr)this.GetTransactionConstant(transactionMode));
            }
            finally
            {
                message.Unpin();
            }
            return(num);
        }
        public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            // ignore the transactionMode
            TimeoutHelper   timeoutHelper = new TimeoutHelper(timeout);
            MsmqQueueHandle handle        = GetHandle();

            while (true)
            {
                int error = PeekLockCore(handle, (MsmqInputMessage)message, timeoutHelper.RemainingTime());

                if (error == 0)
                {
                    return(ReceiveResult.MessageReceived);
                }

                if (IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    message.GrowBuffers();
                    continue;
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_IO_TIMEOUT)
                {
                    return(ReceiveResult.Timeout);
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_OPERATION_CANCELLED)
                {
                    return(ReceiveResult.OperationCancelled);
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_INVALID_HANDLE)
                {
                    // should happen only if racing with Close
                    return(ReceiveResult.OperationCancelled);
                }
                else if (IsErrorDueToStaleHandle(error))
                {
                    HandleIsStale(handle);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqReceiveError, MsmqError.GetErrorString(error)), error));
            }
        }
        public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
        {
            // ignore the transactionMode
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            MsmqQueueHandle handle = GetHandle();

            while (true)
            {
                int error = PeekLockCore(handle, (MsmqInputMessage)message, timeoutHelper.RemainingTime());

                if (error == 0)
                {
                    return ReceiveResult.MessageReceived;
                }

                if (IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    message.GrowBuffers();
                    continue;
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_IO_TIMEOUT)
                {
                    return ReceiveResult.Timeout;
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_OPERATION_CANCELLED)
                {
                    return ReceiveResult.OperationCancelled;
                }
                else if (error == UnsafeNativeMethods.MQ_ERROR_INVALID_HANDLE)
                {
                    // should happen only if racing with Close
                    return ReceiveResult.OperationCancelled;
                }
                else if (IsErrorDueToStaleHandle(error))
                {
                    HandleIsStale(handle);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqReceiveError, MsmqError.GetErrorString(error)), error));
            }
        }
        private int ReceiveCore(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
        {
            int num2;

            if (this.RequiresDtcTransaction(transactionMode))
            {
                return(this.ReceiveCoreDtcTransacted(handle, message, timeout, transactionMode, action));
            }
            int    num        = TimeoutHelper.ToMilliseconds(timeout);
            IntPtr properties = message.Pin();

            try
            {
                num2 = UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), num, action, properties, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)this.GetTransactionConstant(transactionMode));
            }
            finally
            {
                message.Unpin();
            }
            return(num2);
        }
Пример #17
0
 unsafe int ReceiveCore(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
 {
     if (RequiresDtcTransaction(transactionMode))
     {
         return(ReceiveCoreDtcTransacted(handle, message, timeout, transactionMode, action));
     }
     else
     {
         int    timeoutInMilliseconds   = TimeoutHelper.ToMilliseconds(timeout);
         IntPtr nativePropertiesPointer = message.Pin();
         try
         {
             return(UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                         action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode)));
         }
         finally
         {
             message.Unpin();
         }
     }
 }
 private static void DatagramSentOrReceived(NativeMsmqMessage.BufferProperty messageId, Message message, int traceCode, string traceDescription)
 {
     if (DiagnosticUtility.ShouldTraceVerbose)
     {
         Guid guid = MessageIdToGuid(messageId);
         UniqueId id = message.Headers.MessageId;
         TraceRecord extendedData = null;
         if (null == id)
         {
             extendedData = new StringTraceRecord("MSMQMessageId", guid.ToString());
         }
         else
         {
             Dictionary<string, string> dictionary2 = new Dictionary<string, string>(2);
             dictionary2.Add("MSMQMessageId", guid.ToString());
             dictionary2.Add("WCFMessageId", id.ToString());
             Dictionary<string, string> dictionary = dictionary2;
             extendedData = new DictionaryTraceRecord(dictionary);
         }
         TraceUtility.TraceEvent(TraceEventType.Verbose, traceCode, traceDescription, extendedData, null, null);
     }
 }
        public MoveReceiveResult TryReceiveByLookupId(long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action)
        {
            MsmqQueueHandle handle = this.GetHandle();
            int             error  = 0;

            while (true)
            {
                try
                {
                    error = this.ReceiveByLookupIdCore(handle, lookupId, message, transactionMode, action);
                }
                catch (ObjectDisposedException exception)
                {
                    MsmqDiagnostics.ExpectedException(exception);
                    return(MoveReceiveResult.Succeeded);
                }
                if (error == 0)
                {
                    return(MoveReceiveResult.Succeeded);
                }
                if (!IsReceiveErrorDueToInsufficientBuffer(error))
                {
                    if (-1072824184 == error)
                    {
                        return(MoveReceiveResult.MessageNotFound);
                    }
                    if (-1072824164 == error)
                    {
                        return(MoveReceiveResult.MessageLockedUnderTransaction);
                    }
                    if (IsErrorDueToStaleHandle(error))
                    {
                        this.HandleIsStale(handle);
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqReceiveError", new object[] { MsmqError.GetErrorString(error) }), error));
                }
                message.GrowBuffers();
            }
        }
        protected int ReceiveByLookupIdCoreDtcTransacted(MsmqQueueHandle handle, long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action)
        {
            int             num;
            IDtcTransaction nativeTransaction = this.GetNativeTransaction(transactionMode);
            IntPtr          properties        = message.Pin();

            try
            {
                if (nativeTransaction != null)
                {
                    try
                    {
                        return(UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, properties, null, IntPtr.Zero, nativeTransaction));
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(nativeTransaction);
                    }
                }
                num = UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, properties, null, IntPtr.Zero, (IntPtr)this.GetTransactionConstant(transactionMode));
            }
            finally
            {
                message.Unpin();
            }
            return(num);
        }
 public BooleanProperty(NativeMsmqMessage message, int id) : base(message, id, 11)
 {
 }
 internal StringProperty(NativeMsmqMessage message, int id, string value)
     : this(message, id, value.Length + 1)
 {
     CopyValueToBuffer(value);
 }
 public BufferProperty(NativeMsmqMessage message, int id, byte[] buffer)
     : this(message, id, buffer.Length)
 {
     System.Buffer.BlockCopy(buffer, 0, this.Buffer, 0, buffer.Length);
 }
 public LongProperty(NativeMsmqMessage message, int id, long value)
     : this(message, id)
 {
     this.Value = value;
 }
Пример #25
0
 unsafe int ReceiveCore(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
 {
     if (RequiresDtcTransaction(transactionMode))
     {
         return ReceiveCoreDtcTransacted(handle, message, timeout, transactionMode, action);
     }
     else
     {
         int timeoutInMilliseconds = TimeoutHelper.ToMilliseconds(timeout);
         IntPtr nativePropertiesPointer = message.Pin();
         try
         {
             return UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                         action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode));
         }
         finally
         {
             message.Unpin();
         }
     }
 }
 public ReceiveResult TryPeek(NativeMsmqMessage message, TimeSpan timeout)
 {
     return(this.TryReceiveInternal(message, timeout, MsmqTransactionMode.None, -2147483648));
 }
 public BooleanProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_BOOL)
 {
 }
 public ShortProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI2)
 {
 }
 public ByteProperty(NativeMsmqMessage message, int id, byte value)
     : this(message, id)
 {
     this.Value = value;
 }
 public ByteProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI1)
 {
 }
 protected MsmqProperty(NativeMsmqMessage message, int id, ushort vt)
 {
     this.variants = message.variants;
     this.index = message.nativeProperties.count++;
     message.variants[this.index].vt = vt;
     message.ids[this.index] = id;
     message.properties[this.index] = this;
 }
 public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
 {
     MsmqQueue.MoveReceiveResult result3;
     TimeoutHelper helper = new TimeoutHelper(timeout);
     bool flag = false;
     long lookupId = 0L;
     while (!flag)
     {
         using (MsmqMessageLookupId id = new MsmqMessageLookupId())
         {
             MsmqQueue.ReceiveResult result = base.TryPeek(id, helper.RemainingTime());
             if (result != MsmqQueue.ReceiveResult.MessageReceived)
             {
                 return result;
             }
             lookupId = id.lookupId.Value;
         }
         try
         {
             if (base.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None) == MsmqQueue.MoveReceiveResult.Succeeded)
             {
                 flag = true;
             }
             continue;
         }
         catch (MsmqException exception)
         {
             MsmqDiagnostics.ExpectedException(exception);
             continue;
         }
     }
     try
     {
         result3 = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, 0x40000010);
     }
     catch (MsmqException exception2)
     {
         this.UnlockMessage(lookupId, TimeSpan.Zero);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2);
     }
     if (result3 == MsmqQueue.MoveReceiveResult.Succeeded)
     {
         return MsmqQueue.ReceiveResult.MessageReceived;
     }
     this.UnlockMessage(lookupId, TimeSpan.Zero);
     return MsmqQueue.ReceiveResult.OperationCancelled;
 }
 public IntProperty(NativeMsmqMessage message, int id) : base(message, id, 0x13)
 {
 }
Пример #34
0
        public void Send(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            int error = 0;
            if (RequiresDtcTransaction(transactionMode))
            {
                error = SendDtcTransacted(message, transactionMode);
            }
            else
            {
                MsmqQueueHandle handle = GetHandle();
                IntPtr nativePropertiesPointer = message.Pin();
                try
                {
                    error = UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                              (IntPtr)GetTransactionConstant(transactionMode));
                }
                finally
                {
                    message.Unpin();
                }
            }

            if (error != 0)
            {
                if (IsErrorDueToStaleHandle(error))
                {
                    HandleIsStale(handle);
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqSendError, MsmqError.GetErrorString(error)), error));
            }
        }
Пример #35
0
        int SendDtcTransacted(NativeMsmqMessage message, MsmqTransactionMode transactionMode)
        {
            IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode);

            MsmqQueueHandle handle = GetHandle();
            IntPtr nativePropertiesPointer = message.Pin();
            try
            {
                if (dtcTransaction != null)
                {
                    try
                    {
                        return UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                                 dtcTransaction);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(dtcTransaction);
                    }
                }
                else
                {
                    return UnsafeNativeMethods.MQSendMessage(handle, nativePropertiesPointer,
                                                             (IntPtr)GetTransactionConstant(transactionMode));
                }
            }
            finally
            {
                message.Unpin();
            }
        }
 public BooleanProperty(NativeMsmqMessage message, int id, bool value)
     : this(message, id)
 {
     this.Value = value;
 }
 public MoveReceiveResult TryReceiveByLookupId(long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode)
 {
     return(this.TryReceiveByLookupId(lookupId, message, transactionMode, 0x40000020));
 }
 public IntProperty(NativeMsmqMessage message, int id, int value)
     : this(message, id)
 {
     this.Value = value;
 }
 public LongProperty(NativeMsmqMessage message, int id) : base(message, id, 0x15)
 {
 }
 public LongProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI8)
 {
 }
 public BufferProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI1 | UnsafeNativeMethods.VT_VECTOR)
 {
     bufferHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
 }
Пример #42
0
        unsafe int ReceiveCoreDtcTransacted(MsmqQueueHandle handle, NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode, int action)
        {
            IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode);
            int timeoutInMilliseconds = TimeoutHelper.ToMilliseconds(timeout);

            IntPtr nativePropertiesPointer = message.Pin();
            try
            {
                if (dtcTransaction != null)
                {
                    try
                    {
                        return UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                                    action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, dtcTransaction);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(dtcTransaction);
                    }
                }
                else
                {
                    return UnsafeNativeMethods.MQReceiveMessage(handle.DangerousGetHandle(), timeoutInMilliseconds,
                                                                action, nativePropertiesPointer, null, IntPtr.Zero, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode));
                }
            }
            finally
            {
                message.Unpin();
            }
        }
 public BufferProperty(NativeMsmqMessage message, int id, int length)
     : this(message, id)
 {
     SetBufferReference(DiagnosticUtility.Utility.AllocateByteArray(length));
 }
 public BufferProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI1 | UnsafeNativeMethods.VT_VECTOR)
 {
     bufferHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
 }
 internal StringProperty(NativeMsmqMessage message, int id, int length)
     : base(message, id, UnsafeNativeMethods.VT_LPWSTR)
 {
     this.buffer       = DiagnosticUtility.Utility.AllocateCharArray(length);
     this.bufferHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
 }
 public BufferProperty(NativeMsmqMessage message, int id, byte[] buffer)
     : this(message, id, buffer.Length)
 {
     System.Buffer.BlockCopy(buffer, 0, this.Buffer, 0, buffer.Length);
 }
Пример #47
0
 public TryReceiveAsyncResult(MsmqQueue msmqQueue, NativeMsmqMessage message, TimeSpan timeout,
                              int action, AsyncCallback callback, object state)
     : base(callback, state)
 {
     this.msmqQueue = msmqQueue;
     this.message = message;
     this.action = action;
     this.timeoutHelper = new TimeoutHelper(timeout);
     StartReceive(true);
 }
 public BufferProperty(NativeMsmqMessage message, int id, int length)
     : this(message, id)
 {
     SetBufferReference(DiagnosticUtility.Utility.AllocateByteArray(length));
 }
Пример #49
0
 public IAsyncResult BeginPeek(NativeMsmqMessage message, TimeSpan timeout, 
                               AsyncCallback callback, object state)
 {
     return new TryReceiveAsyncResult(this, message, timeout, 
                                      UnsafeNativeMethods.MQ_ACTION_PEEK_CURRENT, callback, state);
 }
 internal StringProperty(NativeMsmqMessage message, int id, string value)
     : this(message, id, value.Length + 1)
 {
     CopyValueToBuffer(value);
 }
 public IAsyncResult BeginTryReceive(NativeMsmqMessage message, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(new TryReceiveAsyncResult(this, message, timeout, 0, callback, state));
 }
 internal StringProperty(NativeMsmqMessage message, int id, int length)
     : base(message, id, UnsafeNativeMethods.VT_LPWSTR)
 {
     this.buffer = DiagnosticUtility.Utility.AllocateCharArray(length);
     this.bufferHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
 }
Пример #53
0
 public ReceiveResult TryPeek(NativeMsmqMessage message, TimeSpan timeout)
 {
     return TryReceiveInternal(message, timeout, MsmqTransactionMode.None, 
                       UnsafeNativeMethods.MQ_ACTION_PEEK_CURRENT);
 }
 public ByteProperty(NativeMsmqMessage message, int id) : base(message, id, 0x11)
 {
 }
 public virtual ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode)
 {
     return(this.TryReceiveInternal(message, timeout, transactionMode, 0));
 }
 public BufferProperty(NativeMsmqMessage message, int id) : base(message, id, 0x1011)
 {
     this.bufferHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
 }
 public IntProperty(NativeMsmqMessage message, int id, int value)
     : this(message, id)
 {
     this.Value = value;
 }
 public LongProperty(NativeMsmqMessage message, int id)
     : base(message, id, UnsafeNativeMethods.VT_UI8)
 {
 }
 public LongProperty(NativeMsmqMessage message, int id, long value)
     : this(message, id)
 {
     this.Value = value;
 }
 public ShortProperty(NativeMsmqMessage message, int id) : base(message, id, 0x12)
 {
 }