private static bool OperationComplete(IAsyncResult asyncResult) { AcceptMessageSessionForNamespaceAsyncResult asyncState = (AcceptMessageSessionForNamespaceAsyncResult)asyncResult.AsyncState; Message message = asyncState.MessagingFactory.Channel.EndRequest(asyncResult); AcceptMessageSessionForNamespaceResponseCommand body = message.GetBody <AcceptMessageSessionForNamespaceResponseCommand>(); SessionState sessionState = body.SessionState; MessageCollection messages = body.Messages; DateTime lockedUntilUtc = body.LockedUntilUtc; LinkInfo linkInfo = new LinkInfo() { ConnectionId = asyncState.MessagingFactory.ConnectionId, EntityName = body.EntityPath, IsSessionReceiver = true, LinkId = body.LinkId, ReceiveMode = asyncState.receiveMode, LinkType = LinkType.Receive, SessionId = body.SessionId }; LinkInfo linkInfo1 = linkInfo; CreateLinkSettings createLinkSetting = new CreateLinkSettings(asyncState.MessagingFactory, body.EntityPath, body.EntityPath, linkInfo1, null); SbmpMessageReceiver sbmpMessageReceiver = new SbmpMessageReceiver(createLinkSetting.EntityName, false, createLinkSetting.MessagingFactory, createLinkSetting.MessageCreator, createLinkSetting.ControlMessageCreator, createLinkSetting.LinkInfo, false, asyncState.MessagingFactory.RetryPolicy.Clone(), messages); sbmpMessageReceiver.Open(); asyncState.result = new SbmpMessageSession(body.SessionId, lockedUntilUtc, sessionState, sbmpMessageReceiver); return(true); }
public CreateReceiverLinkSettings(SbmpMessagingFactory messagingFactory, string entityPath, string entityName, MessagingEntityType?entityType, ReceiveMode receiveMode, Lazy <SbmpMessageCreator> controlMessageCreator, RetryPolicy retryPolicy, bool isSessionful, string fromOffset) : base(messagingFactory, entityPath, entityName, new Microsoft.ServiceBus.Messaging.Sbmp.LinkInfo() { LinkId = messagingFactory.GetNextLinkId(), ConnectionId = messagingFactory.ConnectionId, LinkType = LinkType.Receive, EntityName = entityName, EntityType = entityType, ReceiveMode = receiveMode, IsSessionReceiver = isSessionful, FromOffset = fromOffset }, controlMessageCreator) { this.MessageReceiver = new SbmpMessageReceiver(base.EntityPath, false, base.MessagingFactory, base.MessageCreator, base.ControlMessageCreator, base.LinkInfo, retryPolicy); }
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 IEnumerator <IteratorAsyncResult <SbmpBrowsableMessageSession.GetStateAsyncResult> .AsyncStep> GetAsyncSteps() { object obj = null; bool flag = false; if (this.sbmpMessageSession.InnerMessageReceiver == null) { bool flag1 = false; try { object thisLock = this.sbmpMessageSession.ThisLock; object obj1 = thisLock; obj = thisLock; Monitor.Enter(obj1, ref flag1); this.sbmpMessageSession.resetEvent.WaitOne(); } finally { if (flag1) { Monitor.Exit(obj); } } try { if (this.sbmpMessageSession.InnerMessageReceiver != null) { goto Label0; } flag = true; SbmpBrowsableMessageSession.GetStateAsyncResult getStateAsyncResult = this; IteratorAsyncResult <SbmpBrowsableMessageSession.GetStateAsyncResult> .BeginCall beginCall = (SbmpBrowsableMessageSession.GetStateAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.BeginAcceptMessageSessionBrowser(t, c, s); yield return(getStateAsyncResult.CallAsync(beginCall, (SbmpBrowsableMessageSession.GetStateAsyncResult thisPtr, IAsyncResult r) => thisPtr.EndAcceptMessageSessionBrowser(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); } finally { this.sbmpMessageSession.resetEvent.Set(); } } Label0: if (this.sbmpMessageSession.InnerMessageReceiver != null && !flag) { GetSessionStateCommand getSessionStateCommand = new GetSessionStateCommand() { SessionId = this.sbmpMessageSession.SessionId, Timeout = base.RemainingTime(), TransactionId = null, IsBrowseMode = true }; GetSessionStateCommand getSessionStateCommand1 = getSessionStateCommand; RequestInfo requestInfo1 = new RequestInfo() { ServerTimeout = new TimeSpan?(getSessionStateCommand1.Timeout) }; RequestInfo requestInfo = requestInfo1; SbmpMessageReceiver innerMessageReceiver = (SbmpMessageReceiver)this.sbmpMessageSession.InnerMessageReceiver; this.wcfMessage = innerMessageReceiver.MessageCreator.CreateWcfMessage("http://schemas.microsoft.com/netservices/2011/06/servicebus/SbmpMessageReceiver/GetSessionState", getSessionStateCommand1, null, this.sbmpMessageSession.RetryPolicy, this.trackingContext, requestInfo); yield return(base.CallAsync((SbmpBrowsableMessageSession.GetStateAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => innerMessageReceiver.SbmpMessagingFactory.Channel.BeginRequest(thisPtr.wcfMessage, SbmpProtocolDefaults.BufferTimeout(t, innerMessageReceiver.MessagingFactory.GetSettings().EnableAdditionalClientTimeout), c, s), (SbmpBrowsableMessageSession.GetStateAsyncResult thisPtr, IAsyncResult a) => thisPtr.Response = innerMessageReceiver.SbmpMessagingFactory.Channel.EndRequest(a), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); if (base.LastAsyncStepException == null) { this.SessionState = this.Response.GetBody <GetSessionStateResponseCommand>().SessionState; } } }
public SbmpMessageSession(string sessionId, DateTime lockedUntilUtc, SessionState sessionState, SbmpMessageReceiver innerReceiver) : base(innerReceiver.Mode, sessionId, lockedUntilUtc, innerReceiver) { this.sessionState = sessionState; this.parentLinkId = (innerReceiver.ControlMessageCreator == null ? string.Empty : innerReceiver.ControlMessageCreator.Value.LinkInfo.LinkId); this.CachedState = sessionState != null; this.messagingFactory = (SbmpMessagingFactory)innerReceiver.MessagingFactory; }