Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private static void Finally(AsyncResult result, Exception exception)
        {
            IteratorAsyncResult <TIteratorAsyncResult> iteratorAsyncResult = (IteratorAsyncResult <TIteratorAsyncResult>)result;

            try
            {
                IEnumerator <IteratorAsyncResult <TIteratorAsyncResult> .AsyncStep> enumerator = iteratorAsyncResult.steps;
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }
            }
            catch (Exception exception2)
            {
                Exception exception1 = exception2;
                if (Fx.IsFatal(exception1))
                {
                    throw;
                }
                MessagingClientEtwProvider.Provider.EventWriteExceptionAsWarning(exception1.ToStringSlim());
                if (exception == null)
                {
                    throw;
                }
            }
        }
Exemplo n.º 3
0
 public AsyncStep(Transaction transaction, IteratorAsyncResult <TIteratorAsyncResult> .BeginCall beginCall, IteratorAsyncResult <TIteratorAsyncResult> .EndCall endCall, IteratorAsyncResult <TIteratorAsyncResult> .Call call, IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy policy)
 {
     this.transaction = transaction;
     this.policy      = policy;
     this.beginCall   = beginCall;
     this.endCall     = endCall;
     this.call        = call;
 }
 protected override IEnumerator <IteratorAsyncResult <OpenCollectionIteratedAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     foreach (ICommunicationObject communicationObject in this.CommunicationObjects)
     {
         this.currentCommunicationObject = communicationObject;
         OpenCollectionIteratedAsyncResult openCollectionIteratedAsyncResult          = this;
         IteratorAsyncResult <OpenCollectionIteratedAsyncResult> .BeginCall beginCall = (OpenCollectionIteratedAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.currentCommunicationObject.BeginOpen(t, c, s);
         IteratorAsyncResult <OpenCollectionIteratedAsyncResult> .EndCall   endCall   = (OpenCollectionIteratedAsyncResult thisPtr, IAsyncResult r) => thisPtr.currentCommunicationObject.EndOpen(r);
         yield return(openCollectionIteratedAsyncResult.CallAsync(beginCall, endCall, (OpenCollectionIteratedAsyncResult thisPtr, TimeSpan t) => thisPtr.currentCommunicationObject.Open(t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
     }
 }
Exemplo n.º 5
0
            public static new void End(IAsyncResult result)
            {
                IteratorAsyncResult <TIteratorAsyncResult> .SleepAsyncResult sleepAsyncResult = AsyncResult <IteratorAsyncResult <TIteratorAsyncResult> .SleepAsyncResult> .End(result);

                try
                {
                    sleepAsyncResult.cancellationTokenRegistration.Dispose();
                }
                catch (ObjectDisposedException objectDisposedException)
                {
                }
            }
        protected override IEnumerator <IteratorAsyncResult <CloseCollectionIteratedAsyncResult> .AsyncStep> GetAsyncSteps()
        {
            foreach (ICommunicationObject communicationObject in this.CommunicationObjects)
            {
                if (communicationObject == null || communicationObject.State == CommunicationState.Closed)
                {
                    continue;
                }
                this.currentCommunicationObject = communicationObject;
                CloseCollectionIteratedAsyncResult closeCollectionIteratedAsyncResult         = this;
                IteratorAsyncResult <CloseCollectionIteratedAsyncResult> .BeginCall beginCall = (CloseCollectionIteratedAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.currentCommunicationObject.BeginClose(t, c, s);
                IteratorAsyncResult <CloseCollectionIteratedAsyncResult> .EndCall   endCall   = (CloseCollectionIteratedAsyncResult thisPtr, IAsyncResult r) => thisPtr.currentCommunicationObject.EndClose(r);
                yield return(closeCollectionIteratedAsyncResult.CallAsync(beginCall, endCall, (CloseCollectionIteratedAsyncResult thisPtr, TimeSpan t) => thisPtr.currentCommunicationObject.Close(t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                if (base.LastAsyncStepException == null)
                {
                    continue;
                }
                this.currentCommunicationObject.Abort();
            }
        }
Exemplo n.º 7
0
        private static bool StepCallback(IAsyncResult result)
        {
            IteratorAsyncResult <TIteratorAsyncResult> asyncState = (IteratorAsyncResult <TIteratorAsyncResult>)result.AsyncState;
            bool flag = asyncState.CheckSyncContinue(result);

            if (!flag)
            {
                asyncState.everCompletedAsynchronously = true;
                try
                {
                    asyncState.steps.Current.EndCall((TIteratorAsyncResult)asyncState, result);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception) || !asyncState.HandleException(exception))
                    {
                        throw;
                    }
                }
                asyncState.EnumerateSteps(IteratorAsyncResult <TIteratorAsyncResult> .CurrentThreadType.Callback);
            }
            return(flag);
        }
Exemplo n.º 8
0
 public ParallelAsyncResult(TIteratorAsyncResult iteratorAsyncResult, ICollection <TWorkItem> workItems, IteratorAsyncResult <TIteratorAsyncResult> .BeginCall <TWorkItem> beginCall, IteratorAsyncResult <TIteratorAsyncResult> .EndCall <TWorkItem> endCall, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.iteratorAsyncResult = iteratorAsyncResult;
     this.workItems           = workItems;
     this.endCall             = endCall;
     this.actions             = (long)(this.workItems.Count + 1);
     foreach (TWorkItem workItem in workItems)
     {
         try
         {
             beginCall(iteratorAsyncResult, workItem, timeout, IteratorAsyncResult <TIteratorAsyncResult> .ParallelAsyncResult <TWorkItem> .completed, new IteratorAsyncResult <TIteratorAsyncResult> .ParallelAsyncResult <TWorkItem> .CallbackState(this, workItem));
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             this.TryComplete(exception, true);
         }
     }
     this.TryComplete(null, true);
 }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.CloseAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                if (this.options.availabilityTimers.Count > 0)
                {
                    foreach (IOThreadTimer value in this.options.availabilityTimers.Values)
                    {
                        value.Cancel();
                    }
                }
                if (this.options.EnableSyphon)
                {
                    SendAvailabilityPairedNamespaceOptions.CloseAsyncResult closeAsyncResult = this;
                    IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.CloseAsyncResult> .BeginCall beginCall = (SendAvailabilityPairedNamespaceOptions.CloseAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.options.pump.BeginClose(t, c, s);
                    yield return(closeAsyncResult.CallAsync(beginCall, (SendAvailabilityPairedNamespaceOptions.CloseAsyncResult thisPtr, IAsyncResult r) => thisPtr.options.pump.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    SendAvailabilityPairedNamespaceOptions.CloseAsyncResult closeAsyncResult1 = this;
                    IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.CloseAsyncResult> .BeginCall beginCall1 = (SendAvailabilityPairedNamespaceOptions.CloseAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.options.SecondaryMessagingFactory.BeginClose(t, c, s);
                    yield return(closeAsyncResult1.CallAsync(beginCall1, (SendAvailabilityPairedNamespaceOptions.CloseAsyncResult thisPtr, IAsyncResult r) => thisPtr.options.SecondaryMessagingFactory.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null)
                    {
                        this.options.SecondaryMessagingFactory.Abort();
                    }
                }
            }
Exemplo n.º 10
0
 protected override IEnumerator <IteratorAsyncResult <EventHubClient.CloseOrAbortAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     if (!this.shouldAbort)
     {
         EventHubClient.CloseOrAbortAsyncResult closeOrAbortAsyncResult = this;
         IteratorAsyncResult <EventHubClient.CloseOrAbortAsyncResult> .BeginCall beginCall = (EventHubClient.CloseOrAbortAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.ClientEntityManager.BeginClose(t, c, s);
         yield return(closeOrAbortAsyncResult.CallAsync(beginCall, (EventHubClient.CloseOrAbortAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.ClientEntityManager.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
     }
     else
     {
         this.owner.ClientEntityManager.Abort();
     }
 }
Exemplo n.º 11
0
            protected override IEnumerator <IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;
                bool     flag;
                bool     flag1;
                int      num = 0;

                timeSpan = (this.session.RetryPolicy.IsServerBusy ? Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime : TimeSpan.Zero);
                TimeSpan zero = timeSpan;

                if (!this.session.RetryPolicy.IsServerBusy || !(Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime >= base.OriginalTimeout))
                {
                    do
                    {
                        flag1 = false;
                        if (zero != TimeSpan.Zero)
                        {
                            yield return(base.CallAsyncSleep(zero));
                        }
                        switch (this.operation)
                        {
                        case MessageSession.SessionOperation.GetState:
                        {
                            MessageSession.RetrySessionAsyncResult retrySessionAsyncResult = this;
                            Transaction ambientTransaction = base.AmbientTransaction;
                            IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginGetState(thisPtr.trackingContext, t, c, s);
                            yield return(retrySessionAsyncResult.CallTransactionalAsync(ambientTransaction, beginCall, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.SessionState = thisPtr.session.OnEndGetState(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                            break;
                        }

                        case MessageSession.SessionOperation.SetState:
                        {
                            if (this.stream != null && this.stream.CanSeek && this.stream.Position != (long)0)
                            {
                                this.stream.Position = (long)0;
                            }
                            MessageSession.RetrySessionAsyncResult retrySessionAsyncResult1 = this;
                            Transaction transaction = base.AmbientTransaction;
                            IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall1 = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginSetState(thisPtr.trackingContext, thisPtr.stream, t, c, s);
                            yield return(retrySessionAsyncResult1.CallTransactionalAsync(transaction, beginCall1, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.session.OnEndSetState(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                            break;
                        }

                        case MessageSession.SessionOperation.RenewSessionLock:
                        {
                            MessageSession.RetrySessionAsyncResult retrySessionAsyncResult2 = this;
                            IteratorAsyncResult <MessageSession.RetrySessionAsyncResult> .BeginCall beginCall2 = (MessageSession.RetrySessionAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.session.OnBeginRenewLock(thisPtr.trackingContext, t, c, s);
                            yield return(retrySessionAsyncResult2.CallAsync(beginCall2, (MessageSession.RetrySessionAsyncResult thisPtr, IAsyncResult r) => thisPtr.LockedUntilUtcTime = thisPtr.session.OnEndRenewLock(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                            break;
                        }
                        }
                        if (base.LastAsyncStepException == null)
                        {
                            this.session.RetryPolicy.ResetServerBusy();
                        }
                        else
                        {
                            base.LastAsyncStepException = this.session.ProcessException(base.LastAsyncStepException);
                            MessagingPerformanceCounters.IncrementExceptionPerSec(this.session.MessagingFactory.Address, 1, base.LastAsyncStepException);
                            flag  = (base.TransactionExists ? false : this.session.RetryPolicy.ShouldRetry(base.RemainingTime(), num, base.LastAsyncStepException, out zero));
                            flag1 = flag;
                            if (this.operation == MessageSession.SessionOperation.SetState && this.stream != null && !this.stream.CanSeek)
                            {
                                flag1 = false;
                                zero  = TimeSpan.Zero;
                                MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyStreamNotSeekable(this.trackingContext.Activity, this.trackingContext.TrackingId, this.session.RetryPolicy.GetType().Name, this.operation.ToString()));
                            }
                            if (!flag1)
                            {
                                continue;
                            }
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyIteration(this.trackingContext.Activity, this.trackingContext.TrackingId, this.session.RetryPolicy.GetType().Name, this.operation.ToString(), num, zero.ToString(), this.LastAsyncStepException.GetType().FullName, this.LastAsyncStepException.Message));
                            num++;
                        }
                    }while (flag1);
                    base.Complete(base.LastAsyncStepException);
                }
                else
                {
                    string str = this.session.RetryPolicy.ServerBusyExceptionMessage;
                    yield return(base.CallAsyncSleep(base.RemainingTime()));

                    base.Complete(new ServerBusyException(str, this.trackingContext));
                }
            }
Exemplo n.º 12
0
            protected override IEnumerator <IteratorAsyncResult <MessageReceivePump.StartAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;

                while (this.currentRetryCount <= 3)
                {
                    MessageReceivePump.StartAsyncResult startAsyncResult = this;
                    startAsyncResult.currentRetryCount = startAsyncResult.currentRetryCount + 1;
                    MessageReceivePump.StartAsyncResult startAsyncResult1 = this;
                    IteratorAsyncResult <MessageReceivePump.StartAsyncResult> .BeginCall beginCall = (MessageReceivePump.StartAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.receiver.BeginReceive(TimeSpan.Zero, c, s);
                    yield return(startAsyncResult1.CallAsync(beginCall, (MessageReceivePump.StartAsyncResult thisPtr, IAsyncResult r) => thisPtr.InitialMessage = thisPtr.owner.receiver.EndReceive(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException == null)
                    {
                        break;
                    }
                    if (this.ShouldRetry(base.LastAsyncStepException))
                    {
                        if (!MessageReceivePump.ShouldBackoff(base.LastAsyncStepException, out timeSpan))
                        {
                            continue;
                        }
                        yield return(base.CallAsyncSleep(timeSpan));
                    }
                    else
                    {
                        base.Complete(base.LastAsyncStepException);
                        goto Label0;
                    }
                }
                try
                {
                    (new MessageReceivePump.PumpAsyncResult(this.owner, this.InitialMessage, this.onPumpCompleted, this)).Start();
                }
                catch (Exception exception)
                {
                    Environment.FailFast(exception.ToString());
                }
Label0:
                yield break;
            }
 protected override IEnumerator <IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.OpenAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     SendAvailabilityPairedNamespaceMessageSender.OpenAsyncResult openAsyncResult = this;
     IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.OpenAsyncResult> .BeginCall beginCall = (SendAvailabilityPairedNamespaceMessageSender.OpenAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.sender.BeginOpen(t, c, s);
     yield return(openAsyncResult.CallAsync(beginCall, (SendAvailabilityPairedNamespaceMessageSender.OpenAsyncResult thisPtr, IAsyncResult r) => thisPtr.sender.EndOpen(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
 }
Exemplo n.º 14
0
            protected override IEnumerator <IteratorAsyncResult <EventProcessorLifecycleManager.EventDataPumpAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;

                while (this.lifeCycleManager.isStarted == 1 && this.receiver.IsOpened)
                {
                    this.messages = null;
                    EventProcessorLifecycleManager.EventDataPumpAsyncResult eventDataPumpAsyncResult = this;
                    yield return(eventDataPumpAsyncResult.CallTask((EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, TimeSpan t) => this.receiver.ReceiveAsync(this.lifeCycleManager.processorOptions.MaxBatchSize, this.lifeCycleManager.processorOptions.ReceiveTimeOut).Then <IEnumerable <EventData>, object>((IEnumerable <EventData> m) => {
                        if (m != null && m.Any <EventData>())
                        {
                            this.messages = m;
                        }
                        return TaskHelpers.GetCompletedTask <object>(null);
                    }), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null)
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpReceiveException(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                        this.lifeCycleManager.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "Receive");
                        if (base.LastAsyncStepException is ReceiverDisconnectedException)
                        {
                            if (Interlocked.CompareExchange(ref this.lifeCycleManager.isStarted, 0, 1) != 1)
                            {
                                continue;
                            }
                            EventProcessorLifecycleManager.EventDataPumpAsyncResult eventDataPumpAsyncResult1 = this;
                            IteratorAsyncResult <EventProcessorLifecycleManager.EventDataPumpAsyncResult> .BeginCall beginCall = (EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult.Begin(thisPtr.lifeCycleManager, thisPtr.receiver, thisPtr.lifeCycleManager.processor, thisPtr.context, CloseReason.LeaseLost, null, c, s);
                            yield return(eventDataPumpAsyncResult1.CallAsync(beginCall, (EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, IAsyncResult r) => AsyncResult <EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult> .End(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                            continue;
                        }
                        else if (EventProcessorLifecycleManager.EventDataPumpAsyncResult.ShouldBackoff(base.LastAsyncStepException, out timeSpan))
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpBackoff(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, (int)EventProcessorLifecycleManager.ServerBusyExceptionBackoffAmount.TotalMilliseconds, base.LastAsyncStepException.ToString()));
                            yield return(base.CallAsyncSleep(timeSpan));
                        }
                    }
                    if (this.messages == null || !this.messages.Any <EventData>())
                    {
                        continue;
                    }
                    EventProcessorLifecycleManager.EventDataPumpAsyncResult eventDataPumpAsyncResult2 = this;
                    yield return(eventDataPumpAsyncResult2.CallTask((EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, TimeSpan t) => {
                        if (this.messages == null || !this.messages.Any <EventData>())
                        {
                            return TaskHelpers.GetCompletedTask <object>(null);
                        }
                        EventData eventDatum = this.messages.Last <EventData>();
                        if (eventDatum != null)
                        {
                            this.context.Offset = eventDatum.Offset;
                            this.context.SequenceNumber = eventDatum.SequenceNumber;
                        }
                        return this.lifeCycleManager.processor.ProcessEventsAsync(this.context, this.messages);
                    }, IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException == null)
                    {
                        continue;
                    }
                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpUserCallbackException(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                    this.lifeCycleManager.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "ProcessMessages");
                    if (!(base.LastAsyncStepException is LeaseLostException))
                    {
                        continue;
                    }
                    bool flag = true;
                    try
                    {
                        AggregateException lastAsyncStepException = base.LastAsyncStepException as AggregateException;
                        if (lastAsyncStepException != null)
                        {
                            AggregateException aggregateException = lastAsyncStepException;
                            aggregateException.Handle((Exception e) => e is LeaseLostException);
                        }
                    }
                    catch
                    {
                        flag = false;
                    }
                    if (!flag || Interlocked.CompareExchange(ref this.lifeCycleManager.isStarted, 0, 1) != 1)
                    {
                        continue;
                    }
                    EventProcessorLifecycleManager.EventDataPumpAsyncResult eventDataPumpAsyncResult3 = this;
                    IteratorAsyncResult <EventProcessorLifecycleManager.EventDataPumpAsyncResult> .BeginCall beginCall1 = (EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult.Begin(thisPtr.lifeCycleManager, thisPtr.receiver, thisPtr.lifeCycleManager.processor, thisPtr.context, CloseReason.LeaseLost, null, c, s);
                    yield return(eventDataPumpAsyncResult3.CallAsync(beginCall1, (EventProcessorLifecycleManager.EventDataPumpAsyncResult thisPtr, IAsyncResult r) => AsyncResult <EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult> .End(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));
                }
            }
 protected override IEnumerator <IteratorAsyncResult <EventHubConsumerGroup.CloseOrAbortAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     foreach (EventProcessorLifecycleManager value in this.owner.handlers.Values)
     {
         EventHubConsumerGroup.CloseOrAbortAsyncResult closeOrAbortAsyncResult = this;
         yield return(closeOrAbortAsyncResult.CallTask((EventHubConsumerGroup.CloseOrAbortAsyncResult AsyncResult, TimeSpan timespan) => value.UnregisterProcessorAsync(CloseReason.Shutdown), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
     }
     this.owner.handlers.Clear();
     if (!this.shouldAbort)
     {
         EventHubConsumerGroup.CloseOrAbortAsyncResult closeOrAbortAsyncResult1 = this;
         IteratorAsyncResult <EventHubConsumerGroup.CloseOrAbortAsyncResult> .BeginCall beginCall = (EventHubConsumerGroup.CloseOrAbortAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.ClientEntityManager.BeginClose(t, c, s);
         yield return(closeOrAbortAsyncResult1.CallAsync(beginCall, (EventHubConsumerGroup.CloseOrAbortAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.ClientEntityManager.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
     }
     else
     {
         this.owner.ClientEntityManager.Abort();
     }
 }
Exemplo n.º 16
0
            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;
            }
            protected override IEnumerator <IteratorAsyncResult <MessageSessionPumpHost.CloseOrAbortAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                object obj  = null;
                bool   flag = false;

                try
                {
                    object thisLock = base.ThisLock;
                    object obj1     = thisLock;
                    obj = thisLock;
                    Monitor.Enter(obj1, ref flag);
                    this.owner.markedForClosed = true;
                    this.pumpToClose           = this.owner.pump;
                }
                finally
                {
                    if (flag)
                    {
                        Monitor.Exit(obj);
                    }
                }
                if (this.pumpToClose != null)
                {
                    if (!this.shouldAbort)
                    {
                        MessageSessionPumpHost.CloseOrAbortAsyncResult closeOrAbortAsyncResult = this;
                        IteratorAsyncResult <MessageSessionPumpHost.CloseOrAbortAsyncResult> .BeginCall beginCall = (MessageSessionPumpHost.CloseOrAbortAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.pumpToClose.BeginClose(t, c, s);
                        IteratorAsyncResult <MessageSessionPumpHost.CloseOrAbortAsyncResult> .EndCall   endCall   = (MessageSessionPumpHost.CloseOrAbortAsyncResult thisPtr, IAsyncResult r) => thisPtr.pumpToClose.EndClose(r);
                        yield return(closeOrAbortAsyncResult.CallAsync(beginCall, endCall, (MessageSessionPumpHost.CloseOrAbortAsyncResult thisPtr, TimeSpan t) => thisPtr.pumpToClose.Close(t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
                    }
                    else
                    {
                        this.pumpToClose.Abort();
                    }
                }
            }
Exemplo n.º 18
0
            protected override IEnumerator <IteratorAsyncResult <MessageBrowser.RetryBrowserAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;
                bool     flag;
                bool     flag1;
                int      num = 0;

                timeSpan = (this.browser.RetryPolicy.IsServerBusy ? Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime : TimeSpan.Zero);
                TimeSpan timeSpan1 = timeSpan;

                if (!this.browser.RetryPolicy.IsServerBusy || !(Microsoft.ServiceBus.RetryPolicy.ServerBusyBaseSleepTime >= base.OriginalTimeout))
                {
                    do
                    {
                        flag1 = false;
                        if (timeSpan1 != TimeSpan.Zero)
                        {
                            yield return(base.CallAsyncSleep(timeSpan1));
                        }
                        MessageBrowser.RetryBrowserAsyncResult retryBrowserAsyncResult = this;
                        IteratorAsyncResult <MessageBrowser.RetryBrowserAsyncResult> .BeginCall beginCall = (MessageBrowser.RetryBrowserAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.browser.OnBeginPeek(thisPtr.trackingContext, thisPtr.fromSequenceNumber, thisPtr.messageCount, t, c, s);
                        yield return(retryBrowserAsyncResult.CallAsync(beginCall, (MessageBrowser.RetryBrowserAsyncResult thisPtr, IAsyncResult r) => thisPtr.Messages = thisPtr.browser.OnEndPeek(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                        if (base.LastAsyncStepException == null)
                        {
                            this.browser.RetryPolicy.ResetServerBusy();
                        }
                        else
                        {
                            MessagingPerformanceCounters.IncrementExceptionPerSec(this.browser.MessagingFactory.Address, 1, base.LastAsyncStepException);
                            flag  = (base.TransactionExists ? false : this.browser.RetryPolicy.ShouldRetry(base.RemainingTime(), num, base.LastAsyncStepException, out timeSpan1));
                            flag1 = flag;
                            if (!flag1)
                            {
                                continue;
                            }
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRetryPolicyIteration(this.trackingContext.Activity, this.trackingContext.TrackingId, this.browser.RetryPolicy.GetType().Name, "Peek", num, timeSpan1.ToString(), this.LastAsyncStepException.GetType().FullName, this.LastAsyncStepException.Message));
                            num++;
                        }
                    }while (flag1);
                    base.Complete(base.LastAsyncStepException);
                }
                else
                {
                    string str = this.browser.RetryPolicy.ServerBusyExceptionMessage;
                    yield return(base.CallAsyncSleep(base.RemainingTime()));

                    base.Complete(new ServerBusyException(str, this.trackingContext));
                }
            }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityMessagePump.SendAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                using (BrokeredMessage brokeredMessage = SendAvailabilityPairedNamespaceMessageSender.ConvertMessageForPrimary(this.message, this.messageSender.Path))
                {
                    if (brokeredMessage == null || !this.pump.CanPump())
                    {
                    }
                    else
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceSendingMessage(this.sequenceNumber, this.messageSender.Path));
                        SendAvailabilityMessagePump.SendAsyncResult sendAsyncResult = this;
                        IteratorAsyncResult <SendAvailabilityMessagePump.SendAsyncResult> .BeginCall beginCall = (SendAvailabilityMessagePump.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.messageSender.BeginSend(brokeredMessage, t, c, s);
                        yield return(sendAsyncResult.CallAsync(beginCall, (SendAvailabilityMessagePump.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.messageSender.EndSend(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                        if (base.LastAsyncStepException != null)
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceDestinationSendException(this.pump.options.PrimaryMessagingFactory.Address.ToString(), this.messageSender.Path, base.LastAsyncStepException));
                            MessagingException lastAsyncStepException = base.LastAsyncStepException as MessagingException;
                            if (lastAsyncStepException != null)
                            {
                                if (!lastAsyncStepException.IsTransient && !(lastAsyncStepException is QuotaExceededException))
                                {
                                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceDeadletterException(this.messageSender.MessagingFactory.Address.ToString(), this.messageSender.Path, lastAsyncStepException));
                                    this.message.DeadLetter(SRClient.BacklogDeadletterReasonNotRetryable, SRClient.BacklogDeadletterDescriptionNotRetryable(this.messageSender.Path, lastAsyncStepException.GetType().Name, lastAsyncStepException.Message));
                                }
                                base.Complete(base.LastAsyncStepException);
                            }
                            else
                            {
                                base.Complete(base.LastAsyncStepException);
                            }
                        }
                        else
                        {
                            SendAvailabilityMessagePump.SendAsyncResult sendAsyncResult1 = this;
                            IteratorAsyncResult <SendAvailabilityMessagePump.SendAsyncResult> .BeginCall beginCall1 = (SendAvailabilityMessagePump.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.message.BeginComplete(t, c, s);
                            yield return(sendAsyncResult1.CallAsync(beginCall1, (SendAvailabilityMessagePump.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.message.EndComplete(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                            if (base.LastAsyncStepException == null)
                            {
                                goto Label0;
                            }
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceDestinationSendException(this.pump.options.PrimaryMessagingFactory.Address.ToString(), this.messageSender.Path, base.LastAsyncStepException));
                            base.Complete(base.LastAsyncStepException);
                        }
                    }
                }
Label0:
                yield break;
            }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityMessagePump.ProcessQueueAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                object obj;
                List <BrokeredMessage> brokeredMessages;
                MessageSender          retryPolicy;
                bool             flag = false;
                HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                do
                {
                    if (base.RemainingTime() < SendAvailabilityMessagePump.ProcessQueueAsyncResult.MinTimeToProcessLoop)
                    {
                        break;
                    }
                    base.LastAsyncStepException = null;
                    IEnumerable <BrokeredMessage> brokeredMessages1 = null;
                    bool flag1 = false;
                    if (!this.pump.CanPump())
                    {
                        break;
                    }
                    SendAvailabilityMessagePump.ProcessQueueAsyncResult processQueueAsyncResult = this;
                    yield return(processQueueAsyncResult.CallAsync((SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.messageReceiver.BeginTryReceive(100, SendAvailabilityMessagePump.ProcessQueueAsyncResult.DefaultReadTimeout, c, s), (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, IAsyncResult r) => flag1 = this.messageReceiver.EndTryReceive(r, out brokeredMessages1), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null)
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceMessagePumpReceiveFailed(this.messageReceiver.MessagingFactory.Address.ToString(), this.messageReceiver.Path, base.LastAsyncStepException));
                        if (!Fx.IsFatal(base.LastAsyncStepException) && !(base.LastAsyncStepException is UnauthorizedAccessException) && !(base.LastAsyncStepException is MessagingEntityNotFoundException))
                        {
                            break;
                        }
                        base.Complete(base.LastAsyncStepException);
                        break;
                    }
                    else if (!flag1 || brokeredMessages1 == null)
                    {
                        flag = true;
                    }
                    else
                    {
                        this.messagesToDispose.AddRange(brokeredMessages1);
                        Dictionary <string, List <BrokeredMessage> > strs1 = new Dictionary <string, List <BrokeredMessage> >();
                        foreach (BrokeredMessage brokeredMessage in brokeredMessages1)
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceReceiveMessageFromSecondary(brokeredMessage.SequenceNumber, this.messageReceiver.Path));
                            base.LastAsyncStepException = null;
                            if (!brokeredMessage.Properties.TryGetValue("x-ms-path", out obj) || !(obj is string))
                            {
                                BrokeredMessage brokeredMessage1 = brokeredMessage;
                                string          messageId        = brokeredMessage.MessageId;
                                MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceMessageNoPathInBacklog(this.messageReceiver.MessagingFactory.Address.ToString(), this.messageReceiver.Path, messageId));
                                yield return(base.CallAsync((SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => brokeredMessage1.BeginDeadLetter(SRClient.BacklogDeadletterReasonNoQueuePath, SRClient.BacklogDeadletterDescriptionNoQueuePath, c, s), (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, IAsyncResult r) => brokeredMessage1.EndDeadLetter(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));
                            }
                            else
                            {
                                string str = (string)obj;
                                if (!strs.Contains(str))
                                {
                                    if (!strs1.TryGetValue(str, out brokeredMessages))
                                    {
                                        brokeredMessages = new List <BrokeredMessage>();
                                        strs1.Add(str, brokeredMessages);
                                    }
                                    brokeredMessages.Add(brokeredMessage);
                                }
                            }
                        }
                        Dictionary <string, List <BrokeredMessage> > .KeyCollection.Enumerator enumerator = strs1.Keys.GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                string current = enumerator.Current;
                                base.LastAsyncStepException = null;
                                string str1 = current;
                                List <BrokeredMessage> item = strs1[current];
                                retryPolicy = null;
                                yield return(base.CallAsync((SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.pump.options.PrimaryMessagingFactory.BeginCreateMessageSender(null, str1, false, t, c, s), (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, IAsyncResult r) => retryPolicy = thisPtr.pump.options.PrimaryMessagingFactory.EndCreateMessageSender(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                                if (base.LastAsyncStepException == null)
                                {
                                    retryPolicy.ShouldLinkRetryPolicy = true;
                                    retryPolicy.RetryPolicy           = this.pump.options.PrimaryMessagingFactory.RetryPolicy;
                                    if (!this.pump.CanPump())
                                    {
                                        goto Label1;
                                    }
                                    SendAvailabilityMessagePump.ProcessQueueAsyncResult processQueueAsyncResult1 = this;
                                    List <BrokeredMessage> brokeredMessages2 = item;
                                    IteratorAsyncResult <SendAvailabilityMessagePump.ProcessQueueAsyncResult> .BeginCall <BrokeredMessage> sendAsyncResult = (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, BrokeredMessage i, TimeSpan t, AsyncCallback c, object s) => new SendAvailabilityMessagePump.SendAsyncResult(retryPolicy, i, this.pump, this.pump.options.PrimaryMessagingFactory.OperationTimeout, c, s);
                                    yield return(processQueueAsyncResult1.CallParallelAsync <BrokeredMessage>(brokeredMessages2, sendAsyncResult, (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, BrokeredMessage i, IAsyncResult r) => AsyncResult <SendAvailabilityMessagePump.SendAsyncResult> .End(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                                    if (base.LastAsyncStepException != null && !strs.Contains(current))
                                    {
                                        strs.Add(current);
                                    }
                                    if (!retryPolicy.IsOpened)
                                    {
                                        continue;
                                    }
                                    SendAvailabilityMessagePump.ProcessQueueAsyncResult processQueueAsyncResult2 = this;
                                    IteratorAsyncResult <SendAvailabilityMessagePump.ProcessQueueAsyncResult> .BeginCall beginCall = (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => retryPolicy.BeginClose(thisPtr.RemainingTime(), c, s);
                                    yield return(processQueueAsyncResult2.CallAsync(beginCall, (SendAvailabilityMessagePump.ProcessQueueAsyncResult thisPtr, IAsyncResult r) => retryPolicy.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                                    if (base.LastAsyncStepException == null)
                                    {
                                        continue;
                                    }
                                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceMessagePumpProcessCloseSenderFailed(base.LastAsyncStepException));
                                }
                                else
                                {
                                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceCouldNotCreateMessageSender(this.messageReceiver.MessagingFactory.Address.ToString(), this.messageReceiver.Path, base.LastAsyncStepException));
                                }
                            }
                            goto Label0;
Label1:
                            retryPolicy.Abort();
                            break;
                        }
                        finally
                        {
                            ((IDisposable)enumerator).Dispose();
                        }
                    }
Label0:
                }while (!flag);
            }
            protected override IEnumerator <IteratorAsyncResult <MessageSessionPumpHost.RegisterSessionHandlerFactoryAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                object obj  = null;
                bool   flag = false;

                try
                {
                    object thisLock = this.owner.ThisLock;
                    object obj1     = thisLock;
                    obj = thisLock;
                    Monitor.Enter(obj1, ref flag);
                    if (this.owner.markedForClosed)
                    {
                        throw new OperationCanceledException(SRClient.MessageEntityDisposed);
                    }
                    if (this.owner.pump != null)
                    {
                        throw new InvalidOperationException(SRClient.SessionHandlerAlreadyRegistered);
                    }
                    this.ownsRegistration = true;
                    this.owner.pump       = new MessageSessionPump(this.owner.entityName, this.owner.entity, this.factory, this.options);
                }
                finally
                {
                    if (flag)
                    {
                        Monitor.Exit(obj);
                    }
                }
                MessageSessionPumpHost.RegisterSessionHandlerFactoryAsyncResult registerSessionHandlerFactoryAsyncResult   = this;
                IteratorAsyncResult <MessageSessionPumpHost.RegisterSessionHandlerFactoryAsyncResult> .BeginCall beginCall = (MessageSessionPumpHost.RegisterSessionHandlerFactoryAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.pump.BeginOpen(c, s);
                yield return(registerSessionHandlerFactoryAsyncResult.CallAsync(beginCall, (MessageSessionPumpHost.RegisterSessionHandlerFactoryAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.pump.EndOpen(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
            }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.StartAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan                       timeSpan;
                MessagingException             lastAsyncStepException;
                IEnumerable <QueueDescription> queueDescriptions = null;
                Stopwatch                      stopwatch         = Stopwatch.StartNew();

                do
                {
                    if (stopwatch.Elapsed >= SendAvailabilityPairedNamespaceOptions.StartAsyncResult.GetQueuesTime)
                    {
                        break;
                    }
                    CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                    object[]    sbNamespace      = new object[] { this.options.SbNamespace };
                    string      str = string.Format(invariantCulture, "startswith(path, '{0}/x-servicebus-transfer/') eq true", sbNamespace);
                    SendAvailabilityPairedNamespaceOptions.StartAsyncResult startAsyncResult = this;
                    IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.StartAsyncResult> .BeginCall beginCall = (SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.options.SecondaryNamespaceManager.BeginGetQueues(str, c, s);
                    yield return(startAsyncResult.CallAsync(beginCall, (SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, IAsyncResult r) => queueDescriptions = thisPtr.options.SecondaryNamespaceManager.EndGetQueues(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException == null && queueDescriptions != null)
                    {
                        break;
                    }
                    lastAsyncStepException = base.LastAsyncStepException as MessagingException;
                }while (lastAsyncStepException == null || lastAsyncStepException.IsTransient);
                if (queueDescriptions != null || base.LastAsyncStepException == null)
                {
                    HashSet <string> strs = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                    foreach (QueueDescription queueDescription in queueDescriptions)
                    {
                        strs.Add(queueDescription.Path);
                    }
                    for (int num = 0; num < this.options.BacklogQueueCount; num++)
                    {
                        string str1 = this.options.CreateBacklogQueueName(num);
                        if (!strs.Contains(str1))
                        {
                            this.options.availableBacklogQueues.Add(string.Empty);
                        }
                        else
                        {
                            this.options.availableBacklogQueues.Add(str1);
                        }
                    }
                    for (int j1 = 0; j1 < this.options.BacklogQueueCount; j1++)
                    {
                        string str2 = this.options.CreateBacklogQueueName(j1);
                        if (string.IsNullOrWhiteSpace(this.options.availableBacklogQueues[j1]))
                        {
                            int num1 = 0;
                            while (num1 < 3)
                            {
                                if (base.LastAsyncStepException == null)
                                {
                                    QueueDescription queueDescription1 = new QueueDescription(str2)
                                    {
                                        MaxSizeInMegabytes       = (long)5120,
                                        MaxDeliveryCount         = 2147483647,
                                        DefaultMessageTimeToLive = TimeSpan.MaxValue,
                                        AutoDeleteOnIdle         = TimeSpan.MaxValue
                                    };
                                    QueueDescription queueDescription2 = queueDescription1;
                                    timeSpan = (Constants.MaximumLockDuration < SendAvailabilityPairedNamespaceOptions.StartAsyncResult.LocalMaxLockDuration ? Constants.MaximumLockDuration : SendAvailabilityPairedNamespaceOptions.StartAsyncResult.LocalMaxLockDuration);
                                    queueDescription2.LockDuration = timeSpan;
                                    queueDescription1.EnableDeadLetteringOnMessageExpiration = true;
                                    queueDescription1.EnableBatchedOperations = true;
                                    SendAvailabilityPairedNamespaceOptions.StartAsyncResult startAsyncResult1 = this;
                                    IteratorAsyncResult <SendAvailabilityPairedNamespaceOptions.StartAsyncResult> .BeginCall beginCall1 = (SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.options.SecondaryNamespaceManager.BeginCreateQueue(queueDescription1, c, s);
                                    yield return(startAsyncResult1.CallAsync(beginCall1, (SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, IAsyncResult r) => thisPtr.options.SecondaryNamespaceManager.EndCreateQueue(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));
                                }
                                if (base.LastAsyncStepException != null)
                                {
                                    if (base.LastAsyncStepException is MessagingEntityAlreadyExistsException)
                                    {
                                        QueueDescription queueDescription3 = null;
                                        SendAvailabilityPairedNamespaceOptions.StartAsyncResult startAsyncResult2 = this;
                                        yield return(startAsyncResult2.CallAsync((SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.options.SecondaryNamespaceManager.BeginGetQueue(str2, c, s), (SendAvailabilityPairedNamespaceOptions.StartAsyncResult thisPtr, IAsyncResult r) => queueDescription3 = thisPtr.options.SecondaryNamespaceManager.EndGetQueue(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                                        if (base.LastAsyncStepException == null && queueDescription3 != null && queueDescription3.Path == str2)
                                        {
                                            this.options.availableBacklogQueues[j1] = str2;
                                            break;
                                        }
                                    }
                                    if (!(base.LastAsyncStepException is UnauthorizedAccessException))
                                    {
                                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceTransferQueueCreateError(str2, this.options.SecondaryNamespaceManager.Address.ToString(), this.LastAsyncStepException.ToString()));
                                        yield return(base.CallAsyncSleep(SendAvailabilityPairedNamespaceOptions.StartAsyncResult.CreateQueuePauseTime));

                                        num1++;
                                    }
                                    else
                                    {
                                        base.Complete(base.LastAsyncStepException);
                                        goto Label0;
                                    }
                                }
                                else
                                {
                                    this.options.availableBacklogQueues[j1] = str2;
                                    break;
                                }
                            }
                        }
                    }
                    for (int k = this.options.availableBacklogQueues.Count - 1; k >= 0; k--)
                    {
                        if (string.IsNullOrWhiteSpace(this.options.availableBacklogQueues[k]))
                        {
                            this.options.availableBacklogQueues.RemoveAt(k);
                        }
                    }
                    this.options.UpdateBacklogQueueCount(this.options.availableBacklogQueues.Count);
                    if (this.options.BacklogQueueCount == 0)
                    {
                        throw Fx.Exception.AsError(new SendAvailabilityBacklogException(SRClient.SendAvailabilityNoTransferQueuesCreated), null);
                    }
                    if (this.options.EnableSyphon)
                    {
                        this.options.pump = new SendAvailabilityMessagePump(this.options);
                        this.options.pump.Start();
                    }
                }
                else
                {
                    base.Complete(base.LastAsyncStepException);
                }
Label0:
                yield break;
            }
Exemplo n.º 23
0
 protected override IEnumerator <IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     while (true)
     {
         Monitor.Enter(this.owner.ThisLock);
         this.shouldReleaseLock = true;
         try
         {
             if (!this.owner.instances.TryGetValue(this.key, out this.singletonContext))
             {
                 break;
             }
             if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded)
             {
                 this.singletonContext.State = SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading;
                 this.instance      = this.singletonContext.Instance;
                 this.ownsUnloading = true;
                 break;
             }
             else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading || this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading)
             {
                 SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult = this;
                 IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult 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(unloadInstanceAsyncResult.CallAsync(beginCall, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult 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.ownsUnloading)
     {
         if (!this.waitPendingOperationsCalled)
         {
             this.waitPendingOperationsCalled = true;
             SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult1 = this;
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall1 = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginWaitPendingOperations(thisPtr.instance, thisPtr.closeTimeout, c, s);
             yield return(unloadInstanceAsyncResult1.CallAsync(beginCall1, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndWaitPendingOperations(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
         }
         if (!this.shouldAbort)
         {
             SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult2 = this;
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall2 = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginCloseInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.instance, thisPtr.unloadingContext, thisPtr.closeTimeout, c, s);
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .EndCall   endCall    = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndCloseInstance(r);
             yield return(unloadInstanceAsyncResult2.CallAsync(beginCall2, endCall, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.owner.OnCloseInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.instance, thisPtr.unloadingContext, thisPtr.closeTimeout), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
         }
     }
 }
Exemplo n.º 24
0
            protected override IEnumerator <IteratorAsyncResult <MessageReceivePump.BatchCompleteAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                List <Guid> guids = null;

                yield return(base.CallAsyncSleep(MessageReceivePump.BatchCompleteAsyncResult.completionBufferWaitTime));

                bool flag = false;

                try
                {
                    List <Guid> guids1 = this.owner.completionList;
                    List <Guid> guids2 = guids1;
                    guids = guids1;
                    Monitor.Enter(guids2, ref flag);
                    this.lockTokens.AddRange(this.owner.completionList);
                    this.owner.completionList.Clear();
                }
                finally
                {
                    if (flag)
                    {
                        Monitor.Exit(guids);
                    }
                }
                if (this.lockTokens.Count != 0)
                {
                    MessageReceivePump.BatchCompleteAsyncResult batchCompleteAsyncResult = this;
                    List <Guid> guids3 = this.lockTokens;
                    IteratorAsyncResult <MessageReceivePump.BatchCompleteAsyncResult> .BeginCall <Guid> beginCall = (MessageReceivePump.BatchCompleteAsyncResult thisPtr, Guid i, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.receiver.BeginComplete(i, c, s);
                    yield return(batchCompleteAsyncResult.CallParallelAsync <Guid>(guids3, beginCall, (MessageReceivePump.BatchCompleteAsyncResult thisPtr, Guid i, IAsyncResult r) => thisPtr.owner.receiver.EndComplete(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null)
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpFailedToComplete(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                        this.owner.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "Complete");
                    }
                }
            }
            protected override IEnumerator <IteratorAsyncResult <EventHubConsumerGroup.CreateReceiverAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                if (!this.startingDateTime.HasValue)
                {
                    this.Receiver = new EventHubReceiver(this.owner.MessagingFactory, this.owner.EventHubPath, this.owner.GroupName, this.startingOffset, this.partitionId, this.owner.PrefetchCount, this.epoch, this.offsetInclusive);
                }
                else
                {
                    this.Receiver = new EventHubReceiver(this.owner.MessagingFactory, this.owner.EventHubPath, this.owner.GroupName, this.startingDateTime, this.partitionId, this.owner.PrefetchCount, this.epoch);
                }
                if (this.Receiver != null)
                {
                    EventHubConsumerGroup.CreateReceiverAsyncResult createReceiverAsyncResult = this;
                    IteratorAsyncResult <EventHubConsumerGroup.CreateReceiverAsyncResult> .BeginCall beginCall = (EventHubConsumerGroup.CreateReceiverAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.Receiver.BeginOpen(t, c, s);
                    yield return(createReceiverAsyncResult.CallAsync(beginCall, (EventHubConsumerGroup.CreateReceiverAsyncResult thisPtr, IAsyncResult r) => thisPtr.Receiver.EndOpen(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));

                    this.owner.RegisterMessageClientEntity(this.Receiver);
                }
            }
Exemplo n.º 26
0
            protected override IEnumerator <IteratorAsyncResult <MessageReceivePump.DispatchAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;

                if (this.ShouldRenewLock())
                {
                    this.owner.ScheduleRenewLockLoop(this.trackingContext, this.message, this.renewCancellationTokenSource.Token);
                    this.processingTimer.Set(this.owner.OnMessageOptions.AutoRenewTimeout);
                }
                MessageReceivePump.DispatchAsyncResult dispatchAsyncResult = this;
                IteratorAsyncResult <MessageReceivePump.DispatchAsyncResult> .BeginCall beginCall = (MessageReceivePump.DispatchAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.beginCallback(thisPtr.message, c, s);
                yield return(dispatchAsyncResult.CallAsync(beginCall, (MessageReceivePump.DispatchAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.endCallback(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                if (this.ShouldRenewLock())
                {
                    this.processingTimer.Cancel();
                    this.renewCancellationTokenSource.Cancel();
                    this.renewCancellationTokenSource.Dispose();
                }
                if (base.LastAsyncStepException != null)
                {
                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpUserCallbackException(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                    this.owner.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "UserCallback");
                }
                if (this.owner.receiver.Mode == ReceiveMode.PeekLock)
                {
                    if (base.LastAsyncStepException != null)
                    {
                        MessageReceivePump.DispatchAsyncResult dispatchAsyncResult1 = this;
                        IteratorAsyncResult <MessageReceivePump.DispatchAsyncResult> .BeginCall beginCall1 = (MessageReceivePump.DispatchAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.receiver.BeginAbandon(thisPtr.message.LockToken, c, s);
                        yield return(dispatchAsyncResult1.CallAsync(beginCall1, (MessageReceivePump.DispatchAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.receiver.EndAbandon(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                        if (base.LastAsyncStepException != null)
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpFailedToAbandon(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                            this.owner.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "Abandon");
                        }
                    }
                    else if (this.owner.OnMessageOptions.AutoComplete)
                    {
                        this.owner.ScheduleMessageCompletion(this.message, this.trackingContext);
                    }
                    bool lastAsyncStepException = base.LastAsyncStepException != null;
                    if (lastAsyncStepException && MessageReceivePump.ShouldBackoff(base.LastAsyncStepException, out timeSpan))
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpBackoff(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, (int)MessageReceivePump.ServerBusyExceptionBackoffAmount.TotalMilliseconds, base.LastAsyncStepException.ToString()));
                        yield return(base.CallAsyncSleep(timeSpan));
                    }
                }
            }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.CloseAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                SendAvailabilityPairedNamespaceMessageSender.CloseAsyncResult closeAsyncResult = this;
                ICollection <MessageSender> messageSenders = this.senders;

                IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.CloseAsyncResult> .BeginCall <MessageSender> beginCall = (SendAvailabilityPairedNamespaceMessageSender.CloseAsyncResult thisPtr, MessageSender i, TimeSpan t, AsyncCallback c, object s) => i.BeginClose(t, c, s);
                yield return(closeAsyncResult.CallParallelAsync <MessageSender>(messageSenders, beginCall, (SendAvailabilityPairedNamespaceMessageSender.CloseAsyncResult thisPtr, MessageSender i, IAsyncResult r) => i.EndClose(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
            }
Exemplo n.º 28
0
            protected override IEnumerator <IteratorAsyncResult <MessageReceivePump.PumpAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                TimeSpan timeSpan;

                while (this.owner.receiver.IsOpened)
                {
                    if (!this.owner.semaphore.TryEnter())
                    {
                        MessageReceivePump.PumpAsyncResult pumpAsyncResult = this;
                        IteratorAsyncResult <MessageReceivePump.PumpAsyncResult> .BeginCall beginCall = (MessageReceivePump.PumpAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.semaphore.BeginEnter(c, s);
                        yield return(pumpAsyncResult.CallAsync(beginCall, (MessageReceivePump.PumpAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.semaphore.EndEnter(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
                    }
                    this.message = null;
                    if (this.firstMessage != null)
                    {
                        this.message      = this.firstMessage;
                        this.firstMessage = null;
                    }
                    else
                    {
                        MessageReceivePump.PumpAsyncResult pumpAsyncResult1 = this;
                        IteratorAsyncResult <MessageReceivePump.PumpAsyncResult> .BeginCall beginCall1 = (MessageReceivePump.PumpAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.receiver.BeginReceive(thisPtr.owner.OnMessageOptions.ReceiveTimeOut, c, s);
                        yield return(pumpAsyncResult1.CallAsync(beginCall1, (MessageReceivePump.PumpAsyncResult thisPtr, IAsyncResult r) => thisPtr.message = thisPtr.owner.receiver.EndReceive(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));
                    }
                    if (base.LastAsyncStepException != null)
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpReceiveException(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, base.LastAsyncStepException.ToString()));
                        this.owner.RaiseExceptionReceivedEvent(base.LastAsyncStepException, "Receive");
                        if (MessageReceivePump.ShouldBackoff(base.LastAsyncStepException, out timeSpan))
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpBackoff(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker, (int)MessageReceivePump.ServerBusyExceptionBackoffAmount.TotalMilliseconds, base.LastAsyncStepException.ToString()));
                            yield return(base.CallAsyncSleep(timeSpan));
                        }
                    }
                    if (this.message != null)
                    {
                        try
                        {
                            (new MessageReceivePump.DispatchAsyncResult(this.owner, this.trackingContext, this.message, MessageReceivePump.PumpAsyncResult.onDispatchCompleted, this.owner)).Start();
                        }
                        catch (Exception exception)
                        {
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }
                            this.owner.semaphore.Exit();
                        }
                    }
                    else
                    {
                        this.owner.semaphore.Exit();
                    }
                }
                MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpStopped(this.trackingContext.Activity, this.trackingContext.TrackingId, this.trackingContext.SystemTracker));
            }
            protected override IEnumerator <IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                Exception exception = this.sender.Options.RetrieveNontransientException(this.sender.Primary.Path);

                if (exception != null)
                {
                    throw Fx.Exception.AsError(new SendAvailabilityMessagingException(exception), null);
                }
                if (this.sender.CanUsePrimary())
                {
                    SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult sendAsyncResult = this;
                    IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult> .BeginCall beginCall = (SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.sender.Primary.BeginSend(thisPtr.trackingContext, thisPtr.messages, t, c, s);
                    yield return(sendAsyncResult.CallAsync(beginCall, (SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.sender.Primary.EndSend(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null)
                    {
                        if (!this.sender.Options.ExceptionInspector.CausesFailover(base.LastAsyncStepException))
                        {
                            goto Label1;
                        }
                        this.sender.Options.NotifyPrimarySendResult(this.sender.Primary.Path, false);
                    }
                    else
                    {
                        this.sender.Options.MarkPathHealthy(this.sender.Path);
                        goto Label0;
                    }
                }
                if (!this.sender.CanUsePrimary())
                {
                    if (this.messageBuffer.Count > 0)
                    {
                        SendAvailabilityPairedNamespaceMessageSender.ConvertMessagesForBacklog(this.messageBuffer, this.sender.Primary.Path);
                        while (base.RemainingTime() > this.SafeBacklogAttempt || base.RemainingTime() > TimeSpan.FromTicks(base.OriginalTimeout.Ticks / (long)2))
                        {
                            List <BrokeredMessage> list             = null;
                            List <BrokeredMessage> brokeredMessages = this.messageBuffer;
                            list = (
                                from msg in brokeredMessages
                                select msg.Clone()).ToList <BrokeredMessage>();
                            try
                            {
                                SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult sendAsyncResult1 = this;
                                IteratorAsyncResult <SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult> .BeginCall beginCall1 = (SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.sender.Backlog.BeginSend(list, t, c, s);
                                yield return(sendAsyncResult1.CallAsync(beginCall1, (SendAvailabilityPairedNamespaceMessageSender.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.sender.Backlog.EndSend(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));
                            }
                            finally
                            {
                                if (list != null)
                                {
                                    list.ForEach((BrokeredMessage msg) => msg.Dispose());
                                    list.Clear();
                                }
                            }
                            if (base.LastAsyncStepException == null)
                            {
                                break;
                            }
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceSendToBacklogFailed(this.sender.MessagingFactory.Address.ToString(), this.sender.Backlog.Path, base.LastAsyncStepException));
                            if (!(base.RemainingTime() > TimeSpan.Zero) || this.sender.Options.BacklogQueueCount <= 1)
                            {
                                break;
                            }
                            this.sender.FindNewMessageSender(this.sender.Backlog.Path);
                        }
                    }
                    List <BrokeredMessage> brokeredMessages1 = this.messageBuffer;
                    brokeredMessages1.ForEach((BrokeredMessage msg) => msg.Dispose());
                    this.messageBuffer.Clear();
                    base.Complete(base.LastAsyncStepException);
                }
                else
                {
                    base.Complete(base.LastAsyncStepException);
                }
Label0:
                yield break;
Label1:
                base.Complete(base.LastAsyncStepException);
                goto Label0;
            }
Exemplo n.º 30
0
            protected override IEnumerator <IteratorAsyncResult <MessageReceivePump.RenewLockLoopAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                while (!this.pump.receiver.IsClosed && !this.cancellationToken.IsCancellationRequested)
                {
                    yield return(base.CallAsyncSleep(this.CalculateRenewAfterDuration(), this.cancellationToken));

                    if (this.cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                    MessageReceivePump.RenewLockLoopAsyncResult renewLockLoopAsyncResult = this;
                    IteratorAsyncResult <MessageReceivePump.RenewLockLoopAsyncResult> .BeginCall beginCall = (MessageReceivePump.RenewLockLoopAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.message.BeginRenewLock(c, s);
                    yield return(renewLockLoopAsyncResult.CallAsync(beginCall, (MessageReceivePump.RenewLockLoopAsyncResult thisPtr, IAsyncResult r) => thisPtr.message.EndRenewLock(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException == null)
                    {
                        continue;
                    }
                    Exception lastAsyncStepException = base.LastAsyncStepException;
                    if (!(lastAsyncStepException is NotSupportedException))
                    {
                        if (lastAsyncStepException is MessageLockLostException || lastAsyncStepException is ObjectDisposedException)
                        {
                            break;
                        }
                        if (!(lastAsyncStepException is InvalidOperationException))
                        {
                            if (lastAsyncStepException is OperationCanceledException)
                            {
                                break;
                            }
                            this.pump.RaiseExceptionReceivedEvent(lastAsyncStepException, "RenewLock");
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpRenewLockFailed(this.trackingContext.Activity, this.trackingContext.SystemTracker, this.trackingContext.TrackingId, this.message.MessageId, lastAsyncStepException.ToStringSlim()));
                        }
                        else
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpRenewLockInvalidOperation(this.trackingContext.Activity, this.trackingContext.SystemTracker, this.trackingContext.TrackingId, this.message.MessageId, lastAsyncStepException.ToStringSlim()));
                            break;
                        }
                    }
                    else
                    {
                        MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.MessageReceivePumpRenewLockNotSupported(this.trackingContext.Activity, this.trackingContext.SystemTracker, this.trackingContext.TrackingId, this.message.MessageId, lastAsyncStepException.ToStringSlim()));
                        this.pump.renewSupported = false;
                        break;
                    }
                }
            }