Exemple #1
0
            public bool Create()
            {
                NamespaceManager NM = NamespaceManager.CreateFromConnectionString(_ConStr);

                Microsoft.ServiceBus.Messaging.QueueDescription Queue = null;

                if (!NM.QueueExists(_ReceivingQueue))
                {
                    Queue = NM.CreateQueue(_ReceivingQueue);
                }

                return(Queue != null);
            }
Exemple #2
0
            public long Count()
            {
                NamespaceManager NM = NamespaceManager.CreateFromConnectionString(_ConStr);


                try
                {
                    Microsoft.ServiceBus.Messaging.QueueDescription Queue = NM.GetQueue(_ReceivingQueue);

                    return(Queue.MessageCount);
                }
                catch (Exception ex)
                {
                    Debugger.Log(1, "Niffler.Data.SQLServer", ex.ToString());
                    return(-1);
                }
            }
        internal override void UpdateForVersion(ApiVersion version, EntityDescription existingDescription = null)
        {
            string internalForwardDeadLetteredMessagesTo;
            bool?  internalEnableExpress;
            bool?  internalEnablePartitioning;
            bool?  internalIsExpress;
            EntityAvailabilityStatus?internalAvailabilityStatus;
            TimeSpan?          internalAutoDeleteOnIdle;
            AuthorizationRules authorization;
            AuthorizationRules internalAuthorization;
            bool?        internalIsAnonymousAccessible;
            EntityStatus?internalStatus;
            string       internalForwardTo;
            DateTime?    internalCreatedAt;
            DateTime?    internalUpdatedAt;
            DateTime?    internalAccessedAt;
            string       internalUserMetadata;
            bool?        internalSupportOrdering;

            Microsoft.ServiceBus.Messaging.MessageCountDetails internalMessageCountDetails;
            QueueDescription queueDescription = existingDescription as QueueDescription;

            base.UpdateForVersion(version, existingDescription);
            bool flag = false;

            if (version < ApiVersion.Two)
            {
                if (queueDescription == null)
                {
                    internalAuthorization = null;
                }
                else
                {
                    internalAuthorization = queueDescription.InternalAuthorization;
                }
                this.InternalAuthorization = internalAuthorization;
                flag = true;
                if (queueDescription == null)
                {
                    internalIsAnonymousAccessible = null;
                }
                else
                {
                    internalIsAnonymousAccessible = queueDescription.InternalIsAnonymousAccessible;
                }
                this.InternalIsAnonymousAccessible = internalIsAnonymousAccessible;
                if (queueDescription == null)
                {
                    internalStatus = null;
                }
                else
                {
                    internalStatus = queueDescription.InternalStatus;
                }
                this.InternalStatus = internalStatus;
                if (queueDescription == null)
                {
                    internalForwardTo = null;
                }
                else
                {
                    internalForwardTo = queueDescription.InternalForwardTo;
                }
                this.InternalForwardTo = internalForwardTo;
                if (queueDescription == null)
                {
                    internalCreatedAt = null;
                }
                else
                {
                    internalCreatedAt = queueDescription.InternalCreatedAt;
                }
                this.InternalCreatedAt = internalCreatedAt;
                if (queueDescription == null)
                {
                    internalUpdatedAt = null;
                }
                else
                {
                    internalUpdatedAt = queueDescription.InternalUpdatedAt;
                }
                this.InternalUpdatedAt = internalUpdatedAt;
                if (queueDescription == null)
                {
                    internalAccessedAt = null;
                }
                else
                {
                    internalAccessedAt = queueDescription.InternalAccessedAt;
                }
                this.InternalAccessedAt = internalAccessedAt;
                if (queueDescription == null)
                {
                    internalUserMetadata = null;
                }
                else
                {
                    internalUserMetadata = queueDescription.InternalUserMetadata;
                }
                this.InternalUserMetadata = internalUserMetadata;
                if (queueDescription == null)
                {
                    internalSupportOrdering = null;
                }
                else
                {
                    internalSupportOrdering = queueDescription.InternalSupportOrdering;
                }
                this.InternalSupportOrdering = internalSupportOrdering;
                if (queueDescription == null)
                {
                    internalMessageCountDetails = null;
                }
                else
                {
                    internalMessageCountDetails = queueDescription.InternalMessageCountDetails;
                }
                this.InternalMessageCountDetails = internalMessageCountDetails;
            }
            if (version < ApiVersion.Three)
            {
                if (this.InternalAuthorization != null && !flag)
                {
                    AuthorizationRules authorizationRules = this.InternalAuthorization;
                    ApiVersion         apiVersion         = version;
                    if (queueDescription == null)
                    {
                        authorization = null;
                    }
                    else
                    {
                        authorization = queueDescription.Authorization;
                    }
                    authorizationRules.UpdateForVersion(apiVersion, authorization);
                }
                if (this.Status == EntityStatus.ReceiveDisabled || this.Status == EntityStatus.SendDisabled)
                {
                    this.Status = EntityStatus.Active;
                }
                if (queueDescription == null)
                {
                    internalAutoDeleteOnIdle = null;
                }
                else
                {
                    internalAutoDeleteOnIdle = queueDescription.InternalAutoDeleteOnIdle;
                }
                this.InternalAutoDeleteOnIdle = internalAutoDeleteOnIdle;
            }
            if (version < ApiVersion.Four)
            {
                if (queueDescription == null)
                {
                    internalAvailabilityStatus = null;
                }
                else
                {
                    internalAvailabilityStatus = queueDescription.InternalAvailabilityStatus;
                }
                this.InternalAvailabilityStatus = internalAvailabilityStatus;
            }
            if (version < ApiVersion.Six)
            {
                if (queueDescription == null)
                {
                    internalEnablePartitioning = null;
                }
                else
                {
                    internalEnablePartitioning = queueDescription.InternalEnablePartitioning;
                }
                this.InternalEnablePartitioning = internalEnablePartitioning;
                if (queueDescription == null)
                {
                    internalIsExpress = null;
                }
                else
                {
                    internalIsExpress = queueDescription.InternalIsExpress;
                }
                this.InternalIsExpress = internalIsExpress;
            }
            if (version < ApiVersion.Eight)
            {
                if (queueDescription == null)
                {
                    internalForwardDeadLetteredMessagesTo = null;
                }
                else
                {
                    internalForwardDeadLetteredMessagesTo = queueDescription.InternalForwardDeadLetteredMessagesTo;
                }
                this.InternalForwardDeadLetteredMessagesTo = internalForwardDeadLetteredMessagesTo;
                if (queueDescription == null)
                {
                    internalEnableExpress = null;
                }
                else
                {
                    internalEnableExpress = queueDescription.InternalEnableExpress;
                }
                this.InternalEnableExpress = internalEnableExpress;
            }
        }
            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;
            }