internal void ForceRollback()
 {
     try
     {
         this.transaction.Rollback();
     }
     catch (ObjectDisposedException exception)
     {
         MsmqDiagnostics.ExpectedException(exception);
     }
     catch (TransactionException exception2)
     {
         MsmqDiagnostics.ExpectedException(exception2);
     }
     this.batchFinished = true;
 }
예제 #2
0
        internal void ForceCommit()
        {
            try
            {
                this.transaction.Commit();
            }
            catch (ObjectDisposedException ex)
            {
                MsmqDiagnostics.ExpectedException(ex);
            }
            catch (TransactionException ex)
            {
                MsmqDiagnostics.ExpectedException(ex);
            }

            this.batchFinished = true;
        }
예제 #3
0
            void OnPeekCompleted(IAsyncResult result)
            {
                bool shouldContinue = true;

                try
                {
                    MQMessage message = this.queue.EndPeek(result);

                    Debug.Print("MsmqActivation.QueueMonitor.OnPeekCompleted: message available");
                    shouldContinue = this.group.NotifyMessageAvailable();
                }
                catch (MQException ex)
                {
                    MsmqDiagnostics.CannotPeekOnQueue(this.queue.FormatName, ex);
                    this.group.ScheduleRetry(this);
                    return;
                }
                catch (Exception ex)
                {
                    DiagnosticUtility.TraceHandledException(ex, TraceEventType.Error);

                    if (!Fx.IsFatal(ex))
                    {
                        this.group.ScheduleRetry(this);
                    }

                    throw;
                }

                lock (this.thisLock)
                {
                    if ((this.disposed == 0) && shouldContinue)
                    {
                        this.queue.BeginPeek(InfiniteTimeout, null, Fx.ThunkCallback(new AsyncCallback(OnPeekCompleted)));
                    }
                    else
                    {
                        this.peeking = false;
                    }
                }
            }
예제 #4
0
        static DeliveryFailure?TryGetDeliveryFailure(string messageId, int acknowledgment)
        {
            // DeliveryFailure definintion explains these bit manipulations
            int bit15 = (1 << 15) & acknowledgment;

            if (0 == bit15)
            {
                return(null);
            }
            int bit14     = (1 << 14) & acknowledgment;
            int otherBits = ~((1 << 15) | (1 << 14)) & acknowledgment;

            if ((0 == bit14 && otherBits >= 0 && otherBits <= 0x0A) ||
                (0 != bit14 && otherBits >= 0 && otherBits <= 0x02))
            {
                return((DeliveryFailure)acknowledgment);
            }
            else
            {
                MsmqDiagnostics.UnexpectedAcknowledgment(messageId, acknowledgment);
                return(System.ServiceModel.Channels.DeliveryFailure.Unknown);
            }
        }
        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();
                    }
                }
            }
        }
예제 #6
0
 public override object MatchFound(string host, string name, bool isPrivate)
 {
     MsmqDiagnostics.MatchedApplicationFound(host, name, isPrivate, this.CanonicalPrefix);
     return(this.group.AddQueueToGroup(CreateServiceUri(host, name, isPrivate)));
 }
        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();
                    }
                }
            }
        }