Пример #1
0
        public bool AddSubscription(SubscriptionInfo subscriptionInfo, SubscriptionIdentifier subscriptionIdentifier, bool isUserOperation = true)
        {
            Subscriptions subscription;
            bool          created = true;

            lock (_mutex)
            {
                if (_subscriptions.TryGetValue(subscriptionIdentifier, out subscription))
                {
                    if (subscription.SubscriptionPolicyType == SubscriptionPolicyType.NonDurableExclusiveSubscription && isUserOperation)
                    {
                        created = false;
                    }
                    else
                    {
                        if (subscriptionInfo.SubPolicyType != SubscriptionPolicyType.NonDurableExclusiveSubscription)
                        {
                            created = subscription.AddSubscriber(subscriptionInfo.ClientId);
                        }
                    }
                }
                else
                {
                    switch (subscriptionInfo.SubPolicyType)
                    {
                    case SubscriptionPolicyType.NonDurableExclusiveSubscription:
                        FeatureUsageCollector.Instance.GetFeature(FeatureEnum.data_sharing).UpdateUsageTime();
                        FeatureUsageCollector.Instance.GetFeature(FeatureEnum.pubsub, FeatureEnum.data_sharing).UpdateUsageTime();
                        FeatureUsageCollector.Instance.GetFeature(FeatureEnum.non_durable_subscription, FeatureEnum.pubsub).UpdateUsageTime();

                        if (subscriptionInfo.Type != SubscriptionType.Publisher)
                        {
                            subscription = new ExclusiveSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context);
                        }
                        else
                        {
                            subscription = new ExclusiveSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context, subscriptionInfo.Type);

                            FeatureUsageCollector.Instance.GetFeature(FeatureEnum.data_sharing).UpdateUsageTime();
                            FeatureUsageCollector.Instance.GetFeature(FeatureEnum.pubsub, FeatureEnum.data_sharing).UpdateUsageTime();
                            FeatureUsageCollector.Instance.GetFeature(FeatureEnum.delivery_failure_notificatiion, FeatureEnum.pubsub).UpdateUsageTime();
                        }

                        break;

                    case SubscriptionPolicyType.EventSubscription:
                        subscription = new EventSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context, subscriptionInfo.Type);
                        break;
                    }
                    _subscriptions.Add(subscriptionIdentifier, subscription);
                }
                return(created);
            }
        }
Пример #2
0
        public bool AddSubscription(SubscriptionInfo subscriptionInfo, SubscriptionIdentifier subscriptionIdentifier, bool isUserOperation = true)
        {
            Subscriptions subscription;
            bool          created = true;

            lock (_mutex)
            {
                if (_subscriptions.TryGetValue(subscriptionIdentifier, out subscription))
                {
                    if (subscription.SubscriptionPolicyType == SubscriptionPolicyType.NonDurableExclusiveSubscription && isUserOperation)
                    {
                        created = false;
                    }
                    else
                    {
                        if (subscriptionInfo.SubPolicyType != SubscriptionPolicyType.NonDurableExclusiveSubscription)
                        {
                            created = subscription.AddSubscriber(subscriptionInfo.ClientId);
                        }
                    }
                }
                else
                {
                    switch (subscriptionInfo.SubPolicyType)
                    {
                    case SubscriptionPolicyType.NonDurableExclusiveSubscription:
                        if (subscriptionInfo.Type != SubscriptionType.Publisher)
                        {
                            subscription = new ExclusiveSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context);
                        }
                        else
                        {
                            subscription = new ExclusiveSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context, subscriptionInfo.Type);
                        }
                        break;

                    case SubscriptionPolicyType.EventSubscription:
                        subscription = new EventSubscriptions(subscriptionInfo.ClientId, subscriptionInfo.SubscriptionId, subscriptionInfo.SubPolicyType, subscriptionInfo.Expiration, _context, subscriptionInfo.Type);
                        break;
                    }
                    _subscriptions.Add(subscriptionIdentifier, subscription);
                }
                return(created);
            }
        }