Message System.ServiceModel.Channels.IInputChannel.EndReceive(IAsyncResult result) { AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult tryReceiveAsyncResult = AsyncResult <AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult> .End(result); if (!tryReceiveAsyncResult.Outcome) { throw new TimeoutException(SRCore.TimeoutOnOperation(tryReceiveAsyncResult.OriginalTimeout)); } return(tryReceiveAsyncResult.Message); }
public Message Receive(TimeSpan timeout) { AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult tryReceiveAsyncResult = new AmqpChannelListener.AmqpInputSessionChannel.TryReceiveAsyncResult(this, timeout, null, null); tryReceiveAsyncResult.RunSynchronously(); if (!tryReceiveAsyncResult.Outcome) { throw new TimeoutException(SRCore.TimeoutOnOperation(timeout)); } return(tryReceiveAsyncResult.Message); }
protected override IEnumerator <IteratorAsyncResult <AmqpMessageReceiver.ReceiveAsyncResult> .AsyncStep> GetAsyncSteps() { if (!this.parent.receiveLink.TryGetOpenedObject(out this.amqpLink)) { Microsoft.ServiceBus.Messaging.Amqp.Framing.Error error = this.parent.GetSessionLockLostError(); if (error == null) { AmqpMessageReceiver.ReceiveAsyncResult receiveAsyncResult = this; IteratorAsyncResult <AmqpMessageReceiver.ReceiveAsyncResult> .BeginCall beginCall = (AmqpMessageReceiver.ReceiveAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.parent.receiveLink.BeginGetInstance(t, c, s); yield return(receiveAsyncResult.CallAsync(beginCall, (AmqpMessageReceiver.ReceiveAsyncResult thisPtr, IAsyncResult r) => thisPtr.amqpLink = thisPtr.parent.receiveLink.EndGetInstance(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); if (base.LastAsyncStepException == null) { goto Label1; } if (this.shouldThrowTimeout || !(base.LastAsyncStepException is TimeoutException)) { base.Complete(ExceptionHelper.GetClientException(base.LastAsyncStepException, this.parent.messagingFactory.RemoteContainerId)); goto Label0; } else { base.Complete(null); goto Label0; } } else { base.Complete(ExceptionHelper.ToMessagingContract(error)); goto Label0; } } Label1: bool flag = true; do { Label3: if (!flag) { goto Label0; } AmqpMessageReceiver.ReceiveAsyncResult receiveAsyncResult1 = this; IteratorAsyncResult <AmqpMessageReceiver.ReceiveAsyncResult> .BeginCall beginCall1 = (AmqpMessageReceiver.ReceiveAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.BeginReceive(thisPtr.amqpLink, t, c, s); yield return(receiveAsyncResult1.CallAsync(beginCall1, (AmqpMessageReceiver.ReceiveAsyncResult thisPtr, IAsyncResult r) => thisPtr.AmqpMessages = thisPtr.EndReceive(thisPtr.amqpLink, r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue)); if (base.LastAsyncStepException == null) { try { flag = false; if (this.AmqpMessages != null && this.AmqpMessages.Any <AmqpMessage>()) { flag = !this.ProcessMessage(this.AmqpMessages); } } catch (AmqpException amqpException) { base.Complete(ExceptionHelper.ToMessagingContract(amqpException.Error)); goto Label0; } if (base.RemainingTime() <= TimeSpan.Zero) { flag = false; } else { goto Label3; } } else { base.Complete(ExceptionHelper.GetClientException(base.LastAsyncStepException, this.amqpLink.GetTrackingId())); goto Label0; } }while (!this.shouldThrowTimeout); goto Label2; Label0: yield break; Label2: base.Complete(new TimeoutException(SRCore.TimeoutOnOperation(base.OriginalTimeout))); goto Label0; }
private AcquireContextAsyncResult(InstanceHandle handle, Transaction hostTransaction, TimeSpan timeout, out bool setOperationPending, bool synchronous, AsyncCallback callback, object state) : base(callback, state) { InstanceHandle.AcquireContextAsyncResult currentTransactionalAsyncResult; setOperationPending = false; this.handle = handle; this.HostTransaction = hostTransaction; this.timeoutHelper = new TimeoutHelper(timeout); bool flag = false; lock (this.handle.ThisLock) { if (!this.handle.IsValid) { throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed)); } if (this.handle.OperationPending) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.CommandExecutionCannotOverlap)); } setOperationPending = true; this.handle.OperationPending = true; currentTransactionalAsyncResult = this.handle.CurrentTransactionalAsyncResult; if (currentTransactionalAsyncResult != null) { if (currentTransactionalAsyncResult.HostTransaction.Equals(hostTransaction) && !this.handle.TooLateToEnlist) { flag = true; this.executionContext = currentTransactionalAsyncResult.ReuseContext(); this.handle.CurrentExecutionContext = this.executionContext; } else { this.handle.AcquirePending = this; } } } if (currentTransactionalAsyncResult != null) { if (flag) { base.Complete(true); return; } TimeSpan span = this.timeoutHelper.RemainingTime(); if (synchronous) { if (!currentTransactionalAsyncResult.WaitForHostTransaction.Wait(span)) { throw Fx.Exception.AsError(new TimeoutException(SRCore.TimeoutOnOperation(span))); } } else if (!currentTransactionalAsyncResult.WaitForHostTransaction.WaitAsync(onHostTransaction, this, span)) { return; } } if (this.DoAfterTransaction()) { base.Complete(true); } }
protected override IEnumerator <IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .AsyncStep> GetAsyncSteps() { while (true) { Monitor.Enter(this.owner.ThisLock); this.shouldReleaseLock = true; try { this.owner.ThrowIfDisposedOrNotOpen(); if (!this.owner.instances.TryGetValue(this.key, out this.singletonContext)) { this.singletonContext = new SingletonDictionaryManager <TKey, TInstance> .SingletonContext(SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading); this.owner.instances.Add(this.key, this.singletonContext); this.ownsLoading = true; break; } else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded) { this.Instance = this.singletonContext.Instance; break; } else if (base.RemainingTime() <= TimeSpan.Zero) { base.Complete(new TimeoutException(SRCore.TimeoutOnOperation(base.OriginalTimeout))); goto Label0; } else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading || this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading) { SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult = this; IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => { IAsyncResult asyncResult; try { thisPtr.shouldReleaseLock = false; asyncResult = thisPtr.owner.BeginWaitPendingOperation(thisPtr.key, t, c, s); } finally { Monitor.Exit(thisPtr.owner.ThisLock); } return(asyncResult); }; yield return(loadInstanceAsyncResult.CallAsync(beginCall, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.EndWaitPendingOperation(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); } else { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] state = new object[] { this.singletonContext.State, typeof(SingletonDictionaryManager <TKey, TInstance>).Name }; string str = string.Format(invariantCulture, "{0} was not recognized. This is likely a bug in {1}.", state); Fx.AssertAndFailFastService(str); break; } } finally { if (this.shouldReleaseLock) { Monitor.Exit(this.owner.ThisLock); } } } if (!this.ownsLoading) { this.owner.OnGetInstance(this.singletonContext, this.key, this.singletonContext.Instance, this.loadingContext); } else { SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult1 = this; IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall1 = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginCreateInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.loadingContext, t, c, s); IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .EndCall instance = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.singletonContext.Instance = thisPtr.owner.OnEndCreateInstance(r); yield return(loadInstanceAsyncResult1.CallAsync(beginCall1, instance, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.singletonContext.Instance = thisPtr.owner.OnCreateInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.loadingContext, t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.created = true; SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult2 = this; IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall2 = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginOpenInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.singletonContext.Instance, t, c, s); IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .EndCall endCall = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndOpenInstance(r); yield return(loadInstanceAsyncResult2.CallAsync(beginCall2, endCall, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.owner.OnOpenInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.singletonContext.Instance, t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); } Label0: yield break; }