예제 #1
0
        protected IteratorAsyncResult(TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
        {
            this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout, true);
            IteratorAsyncResult <TIteratorAsyncResult> iteratorAsyncResult = this;

            iteratorAsyncResult.OnCompleting = (Action <AsyncResult, Exception>)Delegate.Combine(iteratorAsyncResult.OnCompleting, IteratorAsyncResult <TIteratorAsyncResult> .onFinally);
        }
 public CloseEntityCollectionAsyncResult(IList <ClientEntity> clientEntities, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.timeoutHelper    = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     this.interlockedCount = clientEntities.Count;
     if (this.interlockedCount <= 0)
     {
         base.Complete(true);
     }
     else
     {
         foreach (ClientEntity clientEntity in clientEntities)
         {
             try
             {
                 IAsyncResult asyncResult = clientEntity.BeginClose(this.timeoutHelper.RemainingTime(), CloseEntityCollectionAsyncResult.onObjectClosed, new CloseEntityCollectionAsyncResult.CallbackState(this, clientEntity));
                 if (asyncResult.CompletedSynchronously)
                 {
                     this.CompleteClose(clientEntity, asyncResult);
                 }
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 this.Decrement(true, exception);
                 clientEntity.Abort();
             }
         }
     }
 }
예제 #3
0
            public OpenAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel duplexChannel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                IAsyncResult asyncResult;

                this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                this.duplexChannel = duplexChannel;
                try
                {
                    asyncResult = duplexChannel.connectionPoolHelper.BeginEstablishConnection(this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OpenAsyncResult.onEstablishConnection, this);
                }
                catch (TimeoutException timeoutException1)
                {
                    TimeoutException timeoutException = timeoutException1;
                    ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                    string           timeoutOnOpen    = Resources.TimeoutOnOpen;
                    object[]         objArray         = new object[] { timeout };
                    throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(timeoutOnOpen, objArray), timeoutException));
                }
                if (!asyncResult.CompletedSynchronously)
                {
                    return;
                }
                if (this.HandleEstablishConnection(asyncResult))
                {
                    base.Complete(true);
                }
            }
                public OpenAsyncResult(Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel channel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
                {
                    this.channel       = channel;
                    this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                    bool flag  = false;
                    bool flag1 = false;

                    try
                    {
                        channel.ValidateContentType(ref this.timeoutHelper);
                        flag  = this.ContinueReading();
                        flag1 = true;
                    }
                    finally
                    {
                        if (!flag1)
                        {
                            this.CleanupOnError();
                        }
                    }
                    if (flag)
                    {
                        base.Complete(true);
                    }
                }
예제 #5
0
        private int ReadCore(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing)
        {
            int num;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            try
            {
                this.SetReadTimeout(timeoutHelper.RemainingTime(), true, closing);
                num = this.socket.Receive(buffer, offset, size, SocketFlags.None);
            }
            catch (SocketException socketException1)
            {
                SocketException socketException = socketException1;
                throw Fx.Exception.TraceException <Exception>(this.ConvertReceiveException(socketException, timeoutHelper.RemainingTime()), this.ExceptionEventType, this.Activity);
            }
            catch (ObjectDisposedException objectDisposedException1)
            {
                ObjectDisposedException objectDisposedException = objectDisposedException1;
                Exception exception = this.ConvertObjectDisposedException(objectDisposedException);
                if (!object.ReferenceEquals(exception, objectDisposedException))
                {
                    throw Fx.Exception.TraceException <Exception>(exception, this.ExceptionEventType, this.Activity);
                }
                Fx.Exception.TraceException <ObjectDisposedException>(objectDisposedException, this.ExceptionEventType, this.Activity);
                throw;
            }
            return(num);
        }
예제 #6
0
 public CloseCollectionAsyncResult(IEnumerable <ICommunicationObject> communicationObjects, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.timeoutHelper        = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     this.communicationObjects = new List <ICommunicationObject>(communicationObjects);
     this.count = this.communicationObjects.Count;
     if (this.count <= 0)
     {
         base.Complete(true);
     }
     else
     {
         foreach (ICommunicationObject communicationObject in this.communicationObjects)
         {
             try
             {
                 IAsyncResult asyncResult = communicationObject.BeginClose(this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Messaging.CloseCollectionAsyncResult.onObjectClosed, new Microsoft.ServiceBus.Messaging.CloseCollectionAsyncResult.CallbackState(this, communicationObject));
                 if (asyncResult.CompletedSynchronously)
                 {
                     this.CompleteClose(communicationObject, asyncResult);
                 }
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 MessagingClientEtwProvider.Provider.EventWriteExceptionAsInformation(exception.ToString());
                 this.Decrement(true, exception);
                 communicationObject.Abort();
             }
         }
     }
 }
 public BatchedObjectsAsyncResult(TrackingContext trackingContext, IEnumerable <TItem> batchedObjects, int batchSize, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.TrackingContext = trackingContext;
     this.BatchedObjects  = batchedObjects;
     this.BatchSize       = batchSize;
     this.timeoutHelper   = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
 }
예제 #8
0
            public SynchronizedAsyncResult(Microsoft.ServiceBus.Channels.SynchronizedMessageSource syncSource, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                bool flag;

                this.syncSource    = syncSource;
                this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                if (!syncSource.sourceLock.Enter(Microsoft.ServiceBus.Channels.SynchronizedMessageSource.SynchronizedAsyncResult <T> .onEnterComplete, this))
                {
                    return;
                }
                this.exitLock = true;
                bool flag1 = false;

                try
                {
                    flag  = this.PerformOperation(this.timeoutHelper.RemainingTime());
                    flag1 = true;
                }
                finally
                {
                    if (!flag1)
                    {
                        this.ExitLock();
                    }
                }
                if (flag)
                {
                    this.CompleteWithUnlock(true);
                }
            }
예제 #9
0
 public void Write(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout)
 {
     Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size);
     Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     try
     {
         this.SetImmediate(immediate);
         int num = size;
         while (num > 0)
         {
             this.SetWriteTimeout(timeoutHelper.RemainingTime(), true);
             size = Math.Min(num, 16777216);
             this.socket.Send(buffer, offset, size, SocketFlags.None);
             num    = num - size;
             offset = offset + size;
         }
     }
     catch (SocketException socketException1)
     {
         SocketException socketException = socketException1;
         throw Fx.Exception.TraceException <Exception>(this.ConvertSendException(socketException, timeoutHelper.RemainingTime()), this.ExceptionEventType, this.Activity);
     }
     catch (ObjectDisposedException objectDisposedException1)
     {
         ObjectDisposedException objectDisposedException = objectDisposedException1;
         Exception exception = this.ConvertObjectDisposedException(objectDisposedException);
         if (!object.ReferenceEquals(exception, objectDisposedException))
         {
             throw Fx.Exception.TraceException <Exception>(exception, this.ExceptionEventType, this.Activity);
         }
         throw;
     }
 }
예제 #10
0
        public IAsyncResult BeginWrite(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout, AsyncCallback callback, object state)
        {
            IAsyncResult asyncResult;

            Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size);
            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            try
            {
                lock (this.ThisLock)
                {
                    if (this.writeConnectionQueue.Count > 0)
                    {
                        this.writeConnection.Shutdown(timeoutHelper.RemainingTime());
                        this.writeConnection = this.writeConnectionQueue.Dequeue();
                    }
                }
                IAsyncResult asyncResult1 = this.writeConnection.BeginWrite(buffer, offset, size, immediate, timeoutHelper.RemainingTime(), callback, state);
                asyncResult = asyncResult1;
            }
            catch (ObjectDisposedException objectDisposedException1)
            {
                ObjectDisposedException objectDisposedException = objectDisposedException1;
                Exception exception = this.ConvertObjectDisposedException(objectDisposedException);
                if (!object.ReferenceEquals(exception, objectDisposedException))
                {
                    throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType);
                }
                throw;
            }
            return(asyncResult);
        }
예제 #11
0
            public CloseAsyncResult(SingletonDictionaryManager <TKey, TInstance> owner, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                List <TKey> tKeys;

                this.owner         = owner;
                this.syncRoot      = new object();
                this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                lock (this.owner.ThisLock)
                {
                    tKeys = new List <TKey>(this.owner.instances.Keys);
                }
                this.IncreaseWaitCount();
                foreach (TKey tKey in tKeys)
                {
                    try
                    {
                        this.IncreaseWaitCount();
                        (new SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult(this.owner, tKey, null, false, this.timeoutHelper.RemainingTime(), SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult.OnUnloadCompletedCallback, this)).Start();
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        this.DecreaseWaitCount(exception, true);
                    }
                }
                this.DecreaseWaitCount(null, true);
            }
 public void StartReading(OnViaDelegate viaDelegate, TimeSpan receiveTimeout)
 {
     this.viaDelegate          = viaDelegate;
     this.receiveTimeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(receiveTimeout);
     this.connectionBuffer     = base.Connection.AsyncReadBuffer;
     this.ContinueReading();
 }
        public void StartReading(TimeSpan receiveTimeout, Action connectionDequeuedCallback)
        {
            this.decoder = new ServerModeDecoder();
            this.receiveTimeoutHelper       = new Microsoft.ServiceBus.Common.TimeoutHelper(receiveTimeout);
            base.ConnectionDequeuedCallback = connectionDequeuedCallback;
            bool      flag      = false;
            Exception exception = null;

            try
            {
                flag = this.ContinueReading();
            }
            catch (Exception exception2)
            {
                Exception exception1 = exception2;
                if (Fx.IsFatal(exception1))
                {
                    throw;
                }
                flag      = true;
                exception = exception1;
            }
            if (flag)
            {
                this.Complete(exception);
            }
        }
예제 #14
0
 public void Write(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout)
 {
     Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size);
     Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     try
     {
         lock (this.ThisLock)
         {
             if (this.writeConnectionQueue.Count > 0)
             {
                 this.writeConnection.Shutdown(timeoutHelper.RemainingTime());
                 this.writeConnection = this.writeConnectionQueue.Dequeue();
             }
         }
         int num = size;
         while (num > 0)
         {
             size = Math.Min(num, 65536);
             this.writeConnection.Write(buffer, offset, size, immediate, timeoutHelper.RemainingTime());
             num     = num - size;
             offset  = offset + size;
             timeout = timeoutHelper.RemainingTime();
         }
     }
     catch (ObjectDisposedException objectDisposedException1)
     {
         ObjectDisposedException objectDisposedException = objectDisposedException1;
         Exception exception = this.ConvertObjectDisposedException(objectDisposedException);
         if (!object.ReferenceEquals(exception, objectDisposedException))
         {
             throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType);
         }
         throw;
     }
 }
예제 #15
0
 public void SendRequest(Message message, TimeSpan timeout)
 {
     Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     try
     {
         this.connection = this.connectionPoolHelper.EstablishConnection(timeoutHelper.RemainingTime());
         MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(this.Activity, this.connection.Activity);
         bool flag = false;
         try
         {
             Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessage(message, this.connection, true, this.channel.settings, ref timeoutHelper);
             flag = true;
         }
         finally
         {
             if (!flag)
             {
                 this.connectionPoolHelper.Abort();
             }
         }
     }
     catch (TimeoutException timeoutException1)
     {
         TimeoutException timeoutException = timeoutException1;
         ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
         string           timeoutOnRequest = Resources.TimeoutOnRequest;
         object[]         objArray         = new object[] { timeout };
         throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(timeoutOnRequest, objArray), timeoutException));
     }
 }
예제 #16
0
        public Microsoft.ServiceBus.Channels.AsyncReceiveResult BeginReceive(TimeSpan timeout, WaitCallback callback, object state)
        {
            AsyncReadResult asyncReadResult;

            if (this.pendingMessage != null || this.pendingException != null)
            {
                return(Microsoft.ServiceBus.Channels.AsyncReceiveResult.Completed);
            }
            this.readTimeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            while (!this.isAtEOF)
            {
                if (this.size > 0)
                {
                    this.pendingMessage = this.DecodeMessage(this.readTimeoutHelper.RemainingTime());
                    if (this.pendingMessage != null)
                    {
                        this.PrepareMessage(this.pendingMessage);
                        return(Microsoft.ServiceBus.Channels.AsyncReceiveResult.Completed);
                    }
                    if (this.isAtEOF)
                    {
                        return(Microsoft.ServiceBus.Channels.AsyncReceiveResult.Completed);
                    }
                }
                if (this.size != 0)
                {
                    throw Fx.AssertAndThrow("BeginReceive: DecodeMessage() should consume the outstanding buffer or return a message.");
                }
                if (!this.usingAsyncReadBuffer)
                {
                    this.buffer = this.connection.AsyncReadBuffer;
                    this.usingAsyncReadBuffer = true;
                }
                this.pendingCallback      = callback;
                this.pendingCallbackState = state;
                bool flag = true;
                try
                {
                    asyncReadResult = this.connection.BeginRead(0, (int)this.buffer.Length, this.readTimeoutHelper.RemainingTime(), this.onAsyncReadComplete, null);
                    flag            = false;
                }
                finally
                {
                    if (flag)
                    {
                        this.pendingCallback      = null;
                        this.pendingCallbackState = null;
                    }
                }
                if (asyncReadResult == AsyncReadResult.Queued)
                {
                    return(Microsoft.ServiceBus.Channels.AsyncReceiveResult.Pending);
                }
                this.pendingCallback      = null;
                this.pendingCallbackState = null;
                this.HandleReadComplete(this.connection.EndRead(), false);
            }
            return(Microsoft.ServiceBus.Channels.AsyncReceiveResult.Completed);
        }
예제 #17
0
        public Message Request(Message message, TimeSpan timeout)
        {
            Message message1;
            Message message2;

            if (message == null)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            if (timeout < TimeSpan.Zero)
            {
                throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", (object)timeout, Microsoft.ServiceBus.SR.GetString(Resources.SFxTimeoutOutOfRange0, new object[0])));
            }
            base.ThrowIfDisposedOrNotOpen();
            this.AddHeadersTo(message);
            Microsoft.ServiceBus.Channels.IRequest request = this.CreateRequest(message);
            this.TrackRequest(request);
            try
            {
                Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                TimeSpan timeSpan = timeoutHelper.RemainingTime();
                try
                {
                    request.SendRequest(message, timeSpan);
                }
                catch (TimeoutException timeoutException1)
                {
                    TimeoutException timeoutException           = timeoutException1;
                    string           requestChannelSendTimedOut = Resources.RequestChannelSendTimedOut;
                    object[]         objArray = new object[] { timeSpan };
                    throw TraceUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(requestChannelSendTimedOut, objArray), timeoutException), message);
                }
                timeSpan = timeoutHelper.RemainingTime();
                try
                {
                    message1 = request.WaitForReply(timeSpan);
                }
                catch (TimeoutException timeoutException3)
                {
                    TimeoutException timeoutException2 = timeoutException3;
                    string           requestChannelWaitForReplyTimedOut = Resources.RequestChannelWaitForReplyTimedOut;
                    object[]         objArray1 = new object[] { timeSpan };
                    throw TraceUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(requestChannelWaitForReplyTimedOut, objArray1), timeoutException2), message);
                }
                if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.RequestChannelReplyReceived, message1);
                }
                message2 = message1;
            }
            finally
            {
                this.ReleaseRequest(request);
            }
            return(message2);
        }
            public DirectConnectWaiter(int bufferSize, Uri uri, TimeSpan timeout, Binding innerBinding)
            {
                this.bufferSize = bufferSize;
                ProbingClient probingClient = new ProbingClient(uri.Host, ConnectConstants.DefaultProbePorts);

                this.session        = new DirectConnectionSession(Guid.NewGuid(), probingClient, this);
                this.channelFactory = new DuplexChannelFactory <IDirectConnectionControl>(this.session, innerBinding, new EndpointAddress(uri, new AddressHeader[0]));
                this.timeoutHelper  = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                this.socketEvent    = new ManualResetEvent(false);
                this.mutex          = new object();
            }
예제 #19
0
 public ReadBytesAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, int requestedCount, bool throwIfNotAllRead, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.connection        = connection;
     this.requestedCount    = requestedCount;
     this.throwIfNotAllRead = throwIfNotAllRead;
     this.timeoutHelper     = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     if (this.BeginRead() == AsyncReadResult.Completed)
     {
         this.ReadComplete(true);
     }
 }
 private void ValidateContentType(ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper)
 {
     base.MessageEncoder = this.channelListener.MessageEncoderFactory.CreateSessionEncoder();
     if (!base.MessageEncoder.IsContentTypeSupported(this.decoder.ContentType))
     {
         this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid", ref timeoutHelper);
         ExceptionUtility exceptionUtility    = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
         string           contentTypeMismatch = Resources.ContentTypeMismatch;
         object[]         contentType         = new object[] { this.decoder.ContentType, base.MessageEncoder.ContentType };
         throw exceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(contentTypeMismatch, contentType)));
     }
 }
예제 #21
0
            protected override IEnumerator <IteratorTask <object> .TaskStep> GetTasks()
            {
                Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(this.timeout);
                if (this.relay.tokenRenewer != null)
                {
                    yield return(base.CallTask(this.relay.tokenRenewer.GetTokenAsync(timeoutHelper.RemainingTime()), IteratorTask <TResult> .ExceptionPolicy.Transfer));

                    this.relay.tokenRenewer.TokenRenewed += new EventHandler <AmqpRelay.TokenEventArgs>(this.relay.OnTokenRenewed);
                }
                yield return(base.CallTask((new AmqpRelay.ConnectTask(this.relay, timeoutHelper.RemainingTime())).Start(), IteratorTask <TResult> .ExceptionPolicy.Transfer));

                this.relay.State = AmqpObjectState.Opened;
            }
예제 #22
0
 public static void RunSynchronously(TimeSpan timeout, params ICommunicationObject[] collection)
 {
     Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     ICommunicationObject[] communicationObjectArray         = collection;
     for (int i = 0; i < (int)communicationObjectArray.Length; i++)
     {
         ICommunicationObject communicationObject = communicationObjectArray[i];
         if (communicationObject != null)
         {
             communicationObject.Open(timeoutHelper.RemainingTime());
         }
     }
 }
 public CloseAsyncResult(DuplexRequestBindingElement.DuplexRequestSessionChannel correlator, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.correlator         = correlator;
     this.timeoutHelper      = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     this.shutdownWaitHandle = ThreadPool.RegisterWaitForSingleObject(this.correlator.serverShutdownEvent, DuplexRequestBindingElement.DuplexRequestSessionChannel.CloseAsyncResult.serverShutdownCallback, this, Microsoft.ServiceBus.Common.TimeoutHelper.ToMilliseconds(this.timeoutHelper.RemainingTime()), true);
     this.TryOperation(true, (DuplexRequestBindingElement.DuplexRequestSessionChannel.CloseAsyncResult t) => {
         IAsyncResult asyncResult = t.correlator.innerChannel.Session.BeginCloseOutputSession(t.timeoutHelper.RemainingTime(), DuplexRequestBindingElement.DuplexRequestSessionChannel.CloseAsyncResult.closeOutputSessionCallback, t);
         if (asyncResult.CompletedSynchronously)
         {
             t.correlator.innerChannel.Session.EndCloseOutputSession(asyncResult);
         }
     });
 }
 public DecodeFailedUpgradeAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Microsoft.ServiceBus.Channels.IConnection connection, Uri via, string contentType, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state)
 {
     Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateReadingFaultString(decoder);
     this.decoder       = decoder;
     this.connection    = connection;
     this.via           = via;
     this.contentType   = contentType;
     this.timeoutHelper = timeoutHelper;
     if (connection.BeginRead(0, Math.Min(256, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFailedUpgradeAsyncResult.onReadFaultData, this) == AsyncReadResult.Queued)
     {
         return;
     }
     this.CompleteReadFaultData();
 }
 public InitiateUpgradeAsyncResult(IDefaultCommunicationTimeouts timeouts, EndpointAddress remoteAddress, Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, StreamUpgradeInitiator upgradeInitiator, string contentType, Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state)
 {
     this.defaultTimeouts  = timeouts;
     this.decoder          = decoder;
     this.upgradeInitiator = upgradeInitiator;
     this.contentType      = contentType;
     this.timeoutHelper    = timeoutHelper;
     this.connection       = connection;
     this.remoteAddress    = remoteAddress;
     if (this.Begin())
     {
         base.Complete(true);
     }
 }
예제 #26
0
        private int ReadCore(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing)
        {
            int num = 0;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            try
            {
                while (true)
                {
                    try
                    {
                        num = this.readConnection.Read(buffer, offset, size, timeoutHelper.RemainingTime());
                    }
                    catch (CommunicationException communicationException)
                    {
                        if (this.readConnectionQueue.Count == 0)
                        {
                            throw;
                        }
                    }
                    if (num != 0 || this.readConnectionQueue.Count <= 0)
                    {
                        break;
                    }
                    if (this.role == HybridConnectionRole.Initiator)
                    {
                        this.readConnection.Close(timeoutHelper.RemainingTime());
                    }
                    this.readConnection = this.readConnectionQueue.Dequeue();
                    if (this.role == HybridConnectionRole.Listener)
                    {
                        this.writeConnectionQueue.Enqueue(this.readConnection);
                    }
                }
            }
            catch (ObjectDisposedException objectDisposedException1)
            {
                ObjectDisposedException objectDisposedException = objectDisposedException1;
                Exception exception = this.ConvertObjectDisposedException(objectDisposedException);
                if (!object.ReferenceEquals(exception, objectDisposedException))
                {
                    throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType);
                }
                throw;
            }
            return(num);
        }
예제 #27
0
        public OpenCollectionAsyncResult(TimeSpan timeout, AsyncCallback otherCallback, object state, IList <ICommunicationObject> collection) : base(otherCallback, state)
        {
            IAsyncResult asyncResult;

            this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            this.count         = collection.Count;
            if (this.count == 0)
            {
                base.Complete(true);
                return;
            }
            foreach (ICommunicationObject communicationObject in collection)
            {
                if (communicationObject == null)
                {
                    this.Decrement(true);
                }
                else if (this.exception == null)
                {
                    Microsoft.ServiceBus.Channels.OpenCollectionAsyncResult.CallbackState callbackState = new Microsoft.ServiceBus.Channels.OpenCollectionAsyncResult.CallbackState(this, communicationObject);
                    try
                    {
                        asyncResult = communicationObject.BeginOpen(this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.OpenCollectionAsyncResult.nestedCallback, callbackState);
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        this.Decrement(true, exception);
                        communicationObject.Abort();
                        continue;
                    }
                    if (!asyncResult.CompletedSynchronously)
                    {
                        continue;
                    }
                    this.CompleteOpen(communicationObject, asyncResult);
                }
                else
                {
                    return;
                }
            }
        }
예제 #28
0
                public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, AsyncCallback callback, object state) : base(callback, state)
                {
                    this.channel       = channel;
                    this.connection    = connection;
                    this.timeoutHelper = timeoutHelper;
                    this.decoder       = decoder;
                    IAsyncResult asyncResult = connection.BeginWrite(channel.Preamble, 0, (int)channel.Preamble.Length, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel.StreamedConnectionPoolHelper.SendPreambleAsyncResult.onWritePreamble, this);

                    if (!asyncResult.CompletedSynchronously)
                    {
                        return;
                    }
                    if (this.HandleWritePreamble(asyncResult))
                    {
                        base.Complete(true);
                    }
                }
예제 #29
0
        public Message Receive(TimeSpan timeout)
        {
            int     num;
            Message pendingMessage = this.GetPendingMessage();

            if (pendingMessage != null)
            {
                return(pendingMessage);
            }
            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            while (!this.isAtEOF)
            {
                if (this.size > 0)
                {
                    pendingMessage = this.DecodeMessage(timeoutHelper.RemainingTime());
                    if (pendingMessage != null)
                    {
                        this.PrepareMessage(pendingMessage);
                        return(pendingMessage);
                    }
                    if (this.isAtEOF)
                    {
                        return(null);
                    }
                }
                if (this.size != 0)
                {
                    throw Fx.AssertAndThrow("Receive: DecodeMessage() should consume the outstanding buffer or return a message.");
                }
                if (this.buffer == null)
                {
                    this.buffer = DiagnosticUtility.Utility.AllocateByteArray(this.connection.AsyncReadBufferSize);
                }
                if (this.EnvelopeBuffer == null || this.EnvelopeSize - this.EnvelopeOffset < (int)this.buffer.Length)
                {
                    num = this.connection.Read(this.buffer, 0, (int)this.buffer.Length, timeoutHelper.RemainingTime());
                    this.HandleReadComplete(num, false);
                }
                else
                {
                    num = this.connection.Read(this.EnvelopeBuffer, this.EnvelopeOffset, (int)this.buffer.Length, timeoutHelper.RemainingTime());
                    this.HandleReadComplete(num, true);
                }
            }
            return(null);
        }
예제 #30
0
            public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state)
            {
                this.channel       = channel;
                this.timeoutHelper = timeoutHelper;
                this.connection    = connection;
                channel.decoder    = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0);
                IAsyncResult asyncResult = connection.BeginWrite(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreamble, this);

                if (!asyncResult.CompletedSynchronously)
                {
                    return;
                }
                if (this.HandleWritePreamble(asyncResult))
                {
                    base.Complete(true);
                }
            }
예제 #31
0
        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            Utils.Trace(TraceLevel.Info, "{0}: Tls initiator start connecting...", this);
            this.callbackArgs = callbackArgs;
            this.timeoutHelper = new TimeoutHelper(timeout);
            TransportInitiator innerInitiator = this.transportSettings.InnerTransportSettings.CreateInitiator();

            TransportAsyncCallbackArgs innerArgs = new TransportAsyncCallbackArgs();
            innerArgs.CompletedCallback = OnInnerTransportConnected;
            innerArgs.UserToken = this;
            if (innerInitiator.ConnectAsync(timeout, innerArgs))
            {
                // pending
                return true;
            }
            else
            {
                this.HandleInnerTransportConnected(innerArgs);
                return !this.callbackArgs.CompletedSynchronously;
            }
        }
예제 #32
0
            protected OpenAsyncResult(AmqpStream parent, string address, bool listen, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.parent = parent;
                this.parent.isReceiver = listen;
                this.timeoutHelper = new TimeoutHelper(timeout);

                Uri addressUri = new Uri(address);
                this.parent.node = addressUri.PathAndQuery;
                int port = addressUri.Port;
                if (port == -1)
                {
                    port = AmqpConstants.DefaultPort;
                }

                TcpTransportSettings tcpSettings = new TcpTransportSettings();
                tcpSettings.TcpBacklog = 20;
                tcpSettings.TcpBufferSize = 4096;
                tcpSettings.SetEndPoint(addressUri.Host, port, listen);
                TransportSettings transportSettings = tcpSettings;

                this.Start(transportSettings);
            }
예제 #33
0
 TransportHandler(AmqpTransportListener parent, TransportAsyncCallbackArgs args)
 {
     this.parent = parent;
     this.args = args;
     this.buffer = new byte[ProtocolHeader.Size];
     this.bufferReader = new AsyncIO.AsyncBufferReader(args.Transport);
     this.bufferWriter = new AsyncIO.AsyncBufferWriter(args.Transport);
     this.readCompleteCallback = this.OnReadHeaderComplete;
     this.writeCompleteCallback = this.OnWriteHeaderComplete;
     this.timeoutHelper = new TimeoutHelper(TimeSpan.FromSeconds(AmqpConstants.DefaultTimeout));
 }