internal bool TryReceive(MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, out MsmqMessageProperty property) { property = null; MsmqQueue.ReceiveResult receiveResult = this.Queue.TryReceive(msmqMessage, timeout, transactionMode); if (MsmqQueue.ReceiveResult.OperationCancelled == receiveResult) { return(true); } if (MsmqQueue.ReceiveResult.Timeout == receiveResult) { return(false); } else { property = new MsmqMessageProperty(msmqMessage); if (this.Transactional) { if (this.PoisonHandler.CheckAndHandlePoisonMessage(property)) { long lookupId = property.LookupId; property = null; throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new MsmqPoisonMessageException(lookupId)); } } return(true); } }
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)); } }
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); }
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(); } }
internal IAsyncResult BeginTryReceive(MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state) { if (!this.receiveParameters.ExactlyOnce && !(this.queue is ILockingQueue)) { return new TryNonTransactedReceiveAsyncResult(this, msmqMessage, timeout, callback, state); } return new TryTransactedReceiveAsyncResult(this, msmqMessage, timeout, transactionMode, callback, state); }
internal TryTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state) : base(callback, state) { this.timeoutHelper = new TimeoutHelper(timeout); this.txCurrent = Transaction.Current; this.receiver = receiver; this.msmqMessage = msmqMessage; this.transactionMode = transactionMode; ActionItem.Schedule(onComplete, this); }
protected IDtcTransaction GetNativeTransaction(MsmqTransactionMode transactionMode) { Transaction transaction = Transaction.Current; if (transaction != null) { return(TransactionInterop.GetDtcTransaction(transaction)); } if (transactionMode == MsmqTransactionMode.CurrentOrThrow) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTransactionRequired))); } return(null); }
protected IDtcTransaction GetNativeTransaction(MsmqTransactionMode transactionMode) { Transaction current = Transaction.Current; if (current != null) { return(TransactionInterop.GetDtcTransaction(current)); } if (transactionMode == MsmqTransactionMode.CurrentOrThrow) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MsmqTransactionRequired"))); } return(null); }
private int GetTransactionConstant(MsmqTransactionMode transactionMode) { switch (transactionMode) { case MsmqTransactionMode.None: case MsmqTransactionMode.CurrentOrNone: return(0); case MsmqTransactionMode.Single: case MsmqTransactionMode.CurrentOrSingle: return(3); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("transactionMode")); }
private bool RequiresDtcTransaction(MsmqTransactionMode transactionMode) { switch (transactionMode) { case MsmqTransactionMode.None: case MsmqTransactionMode.Single: return(false); case MsmqTransactionMode.CurrentOrSingle: case MsmqTransactionMode.CurrentOrNone: case MsmqTransactionMode.CurrentOrThrow: return(true); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("transactionMode")); }
int GetTransactionConstant(MsmqTransactionMode transactionMode) { switch (transactionMode) { case MsmqTransactionMode.CurrentOrNone: case MsmqTransactionMode.None: return(UnsafeNativeMethods.MQ_NO_TRANSACTION); case MsmqTransactionMode.Single: case MsmqTransactionMode.CurrentOrSingle: return(UnsafeNativeMethods.MQ_SINGLE_MESSAGE); default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("transactionMode")); } }
private void OpenQueue() { try { this.msmqQueue = new MsmqQueue(this.factory.AddressTranslator.UriToFormatName(this.RemoteAddress.Uri), 2); } catch (MsmqException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Normalized); } if (this.factory.ExactlyOnce) { this.transactionMode = MsmqTransactionMode.CurrentOrSingle; } else { this.transactionMode = MsmqTransactionMode.None; } }
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 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); }
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); }
protected unsafe int ReceiveByLookupIdCoreDtcTransacted(MsmqQueueHandle handle, long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action) { IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode); IntPtr nativePropertiesPointer = message.Pin(); try { if (dtcTransaction != null) { try { return UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, nativePropertiesPointer, null, IntPtr.Zero, dtcTransaction); } finally { Marshal.ReleaseComObject(dtcTransaction); } } else { return UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, nativePropertiesPointer, null, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode)); } } finally { message.Unpin(); } }
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)); } }
// internal IAsyncResult BeginTryReceive(MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state) { if (this.receiveParameters.ExactlyOnce || this.queue is ILockingQueue) { return(new TryTransactedReceiveAsyncResult(this, msmqMessage, timeout, transactionMode, callback, state)); } else { return(new TryNonTransactedReceiveAsyncResult(this, msmqMessage, timeout, callback, state)); } }
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)); } }
internal TryTransactedReceiveAsyncResult(MsmqReceiveHelper receiver, MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, AsyncCallback callback, object state) : base(callback, state) { this.timeoutHelper = new TimeoutHelper(timeout); this.txCurrent = Transaction.Current; this.receiver = receiver; this.msmqMessage = msmqMessage; this.transactionMode = transactionMode; ActionItem.Schedule(onComplete, this); }
internal bool TryReceive(MsmqInputMessage msmqMessage, TimeSpan timeout, MsmqTransactionMode transactionMode, out MsmqMessageProperty property) { property = null; MsmqQueue.ReceiveResult receiveResult = this.Queue.TryReceive(msmqMessage, timeout, transactionMode); if (MsmqQueue.ReceiveResult.OperationCancelled == receiveResult) return true; if (MsmqQueue.ReceiveResult.Timeout == receiveResult) return false; else { property = new MsmqMessageProperty(msmqMessage); if (this.Transactional) { if (this.PoisonHandler.CheckAndHandlePoisonMessage(property)) { long lookupId = property.LookupId; property = null; throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new MsmqPoisonMessageException(lookupId)); } } return true; } }
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)); } }
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(); } }
int GetTransactionConstant(MsmqTransactionMode transactionMode) { switch (transactionMode) { case MsmqTransactionMode.CurrentOrNone: case MsmqTransactionMode.None: return UnsafeNativeMethods.MQ_NO_TRANSACTION; case MsmqTransactionMode.Single: case MsmqTransactionMode.CurrentOrSingle: return UnsafeNativeMethods.MQ_SINGLE_MESSAGE; default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("transactionMode")); } }
bool RequiresDtcTransaction(MsmqTransactionMode transactionMode) { switch (transactionMode) { case MsmqTransactionMode.None: case MsmqTransactionMode.Single: return false; case MsmqTransactionMode.CurrentOrSingle: case MsmqTransactionMode.CurrentOrNone: case MsmqTransactionMode.CurrentOrThrow: return true; default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("transactionMode")); } }
protected IDtcTransaction GetNativeTransaction(MsmqTransactionMode transactionMode) { Transaction transaction = Transaction.Current; if (transaction != null) { return TransactionInterop.GetDtcTransaction(transaction); } if (transactionMode == MsmqTransactionMode.CurrentOrThrow) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqTransactionRequired))); } return null; }
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 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(); } }
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)); } }
public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode) { // we ignore transaction mode for receive context receives TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); bool receivedMessage = false; long lookupId = 0; // peek for new message, move it to the lock queue and then receive the full message // if move fails because another thread moved it ahead of us then peek again while (!receivedMessage) { ReceiveResult result; MoveReceiveResult moveResult; using (MsmqMessageLookupId emptyMessage = new MsmqMessageLookupId()) { result = this.TryPeek(emptyMessage, timeoutHelper.RemainingTime()); if (result != ReceiveResult.MessageReceived) { return(result); } lookupId = emptyMessage.lookupId.Value; } try { moveResult = this.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None); if (moveResult == MoveReceiveResult.Succeeded) { receivedMessage = true; } } catch (MsmqException ex) { MsmqDiagnostics.ExpectedException(ex); } } MoveReceiveResult lookupIdReceiveResult; try { lookupIdReceiveResult = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, UnsafeNativeMethods.MQ_LOOKUP_PEEK_CURRENT); } catch (MsmqException ex) { this.UnlockMessage(lookupId, TimeSpan.Zero); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex); } if (lookupIdReceiveResult == MoveReceiveResult.Succeeded) { return(ReceiveResult.MessageReceived); } else { this.UnlockMessage(lookupId, TimeSpan.Zero); return(ReceiveResult.OperationCancelled); } }
protected unsafe int ReceiveByLookupIdCoreDtcTransacted(MsmqQueueHandle handle, long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode, int action) { IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode); IntPtr nativePropertiesPointer = message.Pin(); try { if (dtcTransaction != null) { try { return(UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, nativePropertiesPointer, null, IntPtr.Zero, dtcTransaction)); } finally { Marshal.ReleaseComObject(dtcTransaction); } } else { return(UnsafeNativeMethods.MQReceiveMessageByLookupId(handle, lookupId, action, nativePropertiesPointer, null, IntPtr.Zero, (IntPtr)GetTransactionConstant(transactionMode))); } } finally { message.Unpin(); } }
int TryMoveMessageDtcTransacted(long lookupId, MsmqQueueHandle sourceQueueHandle, MsmqQueueHandle destinationQueueHandle, MsmqTransactionMode transactionMode) { IDtcTransaction dtcTransaction = GetNativeTransaction(transactionMode); if (dtcTransaction != null) { try { return UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, destinationQueueHandle, lookupId, dtcTransaction); } finally { Marshal.ReleaseComObject(dtcTransaction); } } else { return UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, destinationQueueHandle, lookupId, (IntPtr)GetTransactionConstant(transactionMode)); } }
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(); } } }
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(); } }
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(); } } }
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(); } } }
public override MsmqQueue.ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode) { TimeoutHelper helper = new TimeoutHelper(timeout); MsmqQueueHandle handle = base.GetHandle(); while (true) { int error = this.PeekLockCore(handle, (MsmqInputMessage) message, helper.RemainingTime()); if (error == 0) { return MsmqQueue.ReceiveResult.MessageReceived; } if (!MsmqQueue.IsReceiveErrorDueToInsufficientBuffer(error)) { if (error == -1072824293) { return MsmqQueue.ReceiveResult.Timeout; } if (error == -1072824312) { return MsmqQueue.ReceiveResult.OperationCancelled; } if (error == -1072824313) { return MsmqQueue.ReceiveResult.OperationCancelled; } if (MsmqQueue.IsErrorDueToStaleHandle(error)) { base.HandleIsStale(handle); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqReceiveError", new object[] { MsmqError.GetErrorString(error) }), error)); } message.GrowBuffers(); } }
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 MoveReceiveResult TryMoveMessage(long lookupId, MsmqQueue destinationQueue, MsmqTransactionMode transactionMode) { int num; MsmqQueueHandle sourceQueueHandle = this.GetHandle(); MsmqQueueHandle handle = destinationQueue.GetHandle(); try { if (this.RequiresDtcTransaction(transactionMode)) { num = this.TryMoveMessageDtcTransacted(lookupId, sourceQueueHandle, handle, transactionMode); } else { num = UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, handle, lookupId, (IntPtr)this.GetTransactionConstant(transactionMode)); } } catch (ObjectDisposedException exception) { MsmqDiagnostics.ExpectedException(exception); return(MoveReceiveResult.Succeeded); } switch (num) { case 0: return(MoveReceiveResult.Succeeded); case -1072824184: return(MoveReceiveResult.MessageNotFound); case -1072824164: return(MoveReceiveResult.MessageLockedUnderTransaction); } if (IsErrorDueToStaleHandle(num)) { this.HandleIsStale(sourceQueueHandle); destinationQueue.HandleIsStale(handle); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(System.ServiceModel.SR.GetString("MsmqSendError", new object[] { MsmqError.GetErrorString(num) }), num)); }
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); }
public virtual ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode) { return(this.TryReceiveInternal(message, timeout, transactionMode, 0)); }
public override ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode) { // we ignore transaction mode for receive context receives TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); bool receivedMessage = false; long lookupId = 0; // peek for new message, move it to the lock queue and then receive the full message // if move fails because another thread moved it ahead of us then peek again while (!receivedMessage) { ReceiveResult result; MoveReceiveResult moveResult; using (MsmqMessageLookupId emptyMessage = new MsmqMessageLookupId()) { result = this.TryPeek(emptyMessage, timeoutHelper.RemainingTime()); if (result != ReceiveResult.MessageReceived) { return result; } lookupId = emptyMessage.lookupId.Value; } try { moveResult = this.TryMoveMessage(lookupId, this.lockQueueForMove, MsmqTransactionMode.None); if (moveResult == MoveReceiveResult.Succeeded) { receivedMessage = true; } } catch (MsmqException ex) { MsmqDiagnostics.ExpectedException(ex); } } MoveReceiveResult lookupIdReceiveResult; try { lookupIdReceiveResult = this.lockQueueForReceive.TryReceiveByLookupId(lookupId, message, MsmqTransactionMode.None, UnsafeNativeMethods.MQ_LOOKUP_PEEK_CURRENT); } catch (MsmqException ex) { this.UnlockMessage(lookupId, TimeSpan.Zero); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex); } if (lookupIdReceiveResult == MoveReceiveResult.Succeeded) { return ReceiveResult.MessageReceived; } else { this.UnlockMessage(lookupId, TimeSpan.Zero); return ReceiveResult.OperationCancelled; } }
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(); } }
void OpenQueue() { try { this.msmqQueue = new MsmqQueue(this.factory.AddressTranslator.UriToFormatName(this.RemoteAddress.Uri), UnsafeNativeMethods.MQ_SEND_ACCESS); } catch (MsmqException ex) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex.Normalized); } if (this.factory.ExactlyOnce) { this.transactionMode = MsmqTransactionMode.CurrentOrSingle; } else { this.transactionMode = MsmqTransactionMode.None; } }
public virtual ReceiveResult TryReceive(NativeMsmqMessage message, TimeSpan timeout, MsmqTransactionMode transactionMode) { return TryReceiveInternal(message, timeout, transactionMode, UnsafeNativeMethods.MQ_ACTION_RECEIVE); }
private int TryMoveMessageDtcTransacted(long lookupId, MsmqQueueHandle sourceQueueHandle, MsmqQueueHandle destinationQueueHandle, MsmqTransactionMode transactionMode) { IDtcTransaction nativeTransaction = this.GetNativeTransaction(transactionMode); if (nativeTransaction != null) { try { return(UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, destinationQueueHandle, lookupId, nativeTransaction)); } finally { Marshal.ReleaseComObject(nativeTransaction); } } return(UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, destinationQueueHandle, lookupId, (IntPtr)this.GetTransactionConstant(transactionMode))); }
public MoveReceiveResult TryMoveMessage(long lookupId, MsmqQueue destinationQueue, MsmqTransactionMode transactionMode) { MsmqQueueHandle sourceQueueHandle = GetHandle(); MsmqQueueHandle destinationQueueHandle = destinationQueue.GetHandle(); int error; try { if (RequiresDtcTransaction(transactionMode)) { error = TryMoveMessageDtcTransacted(lookupId, sourceQueueHandle, destinationQueueHandle, transactionMode); } else { error = UnsafeNativeMethods.MQMoveMessage(sourceQueueHandle, destinationQueueHandle, lookupId, (IntPtr)GetTransactionConstant(transactionMode)); } } catch (ObjectDisposedException ex) { MsmqDiagnostics.ExpectedException(ex); return MoveReceiveResult.Succeeded; } if (error != 0) { if (error == UnsafeNativeMethods.MQ_ERROR_MESSAGE_NOT_FOUND) return MoveReceiveResult.MessageNotFound; else if (error == UnsafeNativeMethods.MQ_ERROR_MESSAGE_LOCKED_UNDER_TRANSACTION) return MoveReceiveResult.MessageLockedUnderTransaction; else if (IsErrorDueToStaleHandle(error)) { HandleIsStale(sourceQueueHandle); destinationQueue.HandleIsStale(destinationQueueHandle); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MsmqException(SR.GetString(SR.MsmqSendError, MsmqError.GetErrorString(error)), error)); } return MoveReceiveResult.Succeeded; }
public MoveReceiveResult TryReceiveByLookupId(long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode) { return(this.TryReceiveByLookupId(lookupId, message, transactionMode, 0x40000020)); }
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; }
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(); } }
public MoveReceiveResult TryReceiveByLookupId(long lookupId, NativeMsmqMessage message, MsmqTransactionMode transactionMode) { return this.TryReceiveByLookupId(lookupId, message, transactionMode, UnsafeNativeMethods.MQ_LOOKUP_RECEIVE_CURRENT); }