Ejemplo n.º 1
0
        protected override void OnSend(Message message, TimeSpan timeout)
        {
            base.ThrowIfDisposedOrNotOpen();
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (!this.sendLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility  = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           sendToViaTimedOut = Resources.SendToViaTimedOut;
                object[]         via = new object[] { this.Via, timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(sendToViaTimedOut, via), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                base.ThrowIfDisposedOrNotOpen();
                this.ThrowIfOutputSessionClosed();
                bool flag = false;
                try
                {
                    bool allowOutputBatching = message.Properties.AllowOutputBatching;
                    ArraySegment <byte> nums = this.EncodeMessage(message);
                    this.Connection.Write(nums.Array, nums.Offset, nums.Count, !allowOutputBatching, timeoutHelper.RemainingTime(), this.bufferManager);
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        base.Fault();
                    }
                }
            }
            finally
            {
                this.sendLock.Exit();
            }
        }
Ejemplo n.º 2
0
        private void CloseOutputSession(TimeSpan timeout)
        {
            this.ThrowIfNotOpened();
            this.ThrowIfFaulted();
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (!this.sendLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           closeTimedOut    = Resources.CloseTimedOut;
                object[]         objArray         = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(closeTimedOut, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                this.ThrowIfFaulted();
                if (!this.isOutputSessionClosed)
                {
                    this.isOutputSessionClosed = true;
                    bool flag = true;
                    try
                    {
                        this.Connection.Write(Microsoft.ServiceBus.Channels.SessionEncoder.EndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.EndBytes.Length, true, timeoutHelper.RemainingTime());
                        this.OnOutputSessionClosed(ref timeoutHelper);
                        flag = false;
                    }
                    finally
                    {
                        if (flag)
                        {
                            base.Fault();
                        }
                    }
                }
            }
            finally
            {
                this.sendLock.Exit();
            }
        }
Ejemplo n.º 3
0
        public Message Receive(TimeSpan timeout)
        {
            Message message;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility = DiagnosticUtility.ExceptionUtility;
                string           receiveTimedOut2 = Resources.ReceiveTimedOut2;
                object[]         objArray         = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(receiveTimedOut2, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                message = this.source.Receive(timeoutHelper.RemainingTime());
            }
            finally
            {
                this.sourceLock.Exit();
            }
            return(message);
        }
Ejemplo n.º 4
0
        public bool WaitForMessage(TimeSpan timeout)
        {
            bool flag;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility       = DiagnosticUtility.ExceptionUtility;
                string           waitForMessageTimedOut = Resources.WaitForMessageTimedOut;
                object[]         objArray = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(waitForMessageTimedOut, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                flag = this.source.WaitForMessage(timeoutHelper.RemainingTime());
            }
            finally
            {
                this.sourceLock.Exit();
            }
            return(flag);
        }
Ejemplo n.º 5
0
 public void Enter(TimeSpan timeout)
 {
     if (!this.TryEnter(timeout))
     {
         throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout));
     }
 }