Beispiel #1
0
        private static bool OperationComplete(IAsyncResult asyncResult)
        {
            AcceptMessageSessionAsyncResult asyncState = (AcceptMessageSessionAsyncResult)asyncResult.AsyncState;
            Message message = asyncState.MessagingFactory.Channel.EndRequest(asyncResult);
            AcceptMessageSessionResponseCommand body = message.GetBody <AcceptMessageSessionResponseCommand>();
            SessionState      sessionState           = body.SessionState;
            MessageCollection messages       = body.Messages;
            DateTime          lockedUntilUtc = body.LockedUntilUtc;

            asyncState.createLinkSettings.LinkInfo.LinkId    = (body.LinkId != null ? body.LinkId : asyncState.createLinkSettings.LinkInfo.LinkId);
            asyncState.createLinkSettings.LinkInfo.SessionId = body.SessionId;
            SbmpMessageReceiver sbmpMessageReceiver = new SbmpMessageReceiver(asyncState.createLinkSettings.EntityName, false, asyncState.createLinkSettings.MessagingFactory, asyncState.createLinkSettings.MessageCreator, asyncState.createLinkSettings.ControlMessageCreator, asyncState.createLinkSettings.LinkInfo, true, asyncState.retryPolicy, messages);

            sbmpMessageReceiver.Open();
            asyncState.result = new SbmpMessageSession(body.SessionId, lockedUntilUtc, sessionState, sbmpMessageReceiver)
            {
                PrefetchCount = asyncState.prefetchCount
            };
            return(true);
        }
        protected override IAsyncResult OnBeginAcceptMessageSession(string sessionId, ReceiveMode receiveMode, TimeSpan serverWaitTime, TimeSpan timeout, AsyncCallback callback, object state)
        {
            IAsyncResult acceptMessageSessionAsyncResult;

            try
            {
                acceptMessageSessionAsyncResult = new AcceptMessageSessionAsyncResult((SbmpMessagingFactory)base.MessagingFactory, base.SubscriptionPath, sessionId, new MessagingEntityType?(MessagingEntityType.Subscriber), receiveMode, base.PrefetchCount, this.ControlMessageCreator, base.RetryPolicy, serverWaitTime, timeout, callback, state);
            }
            catch (CommunicationException communicationException1)
            {
                CommunicationException communicationException = communicationException1;
                throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(MessagingExceptionHelper.Unwrap(communicationException, base.IsClosedOrClosing), null);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!Fx.IsFatal(exception) && base.IsClosedOrClosing)
                {
                    throw new OperationCanceledException(SRClient.EntityClosedOrAborted, exception);
                }
                throw;
            }
            return(acceptMessageSessionAsyncResult);
        }
        protected override MessageSession OnEndAcceptMessageSession(IAsyncResult result)
        {
            MessageSession messageSession;

            try
            {
                messageSession = AcceptMessageSessionAsyncResult.End(result);
            }
            catch (CommunicationException communicationException1)
            {
                CommunicationException communicationException = communicationException1;
                throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsError(MessagingExceptionHelper.Unwrap(communicationException, base.IsClosedOrClosing), null);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!Fx.IsFatal(exception) && base.IsClosedOrClosing)
                {
                    throw new OperationCanceledException(SRClient.EntityClosedOrAborted, exception);
                }
                throw;
            }
            return(messageSession);
        }