Example #1
0
        private void Subscribe(object state)
        {
            AuditingNotificationSubscriber.log.Debug((object)"Subscribing auditing indications..");
            try
            {
                AuditingNotificationSubscriber.DeleteOldSubscriptions();
            }
            catch (Exception ex)
            {
                AuditingNotificationSubscriber.log.Warn((object)"Exception deleting old subscriptions:", ex);
            }
            HashSet <string> stringSet = new HashSet <string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);

            using (IEnumerator <IAuditing2> enumerator = this.auditingPlugins.AuditingInstances.GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    IAuditing2 current = enumerator.Current;
                    if (current is IAuditingMultiSubscription multiSubscription)
                    {
                        foreach (string subscriptionQuery in multiSubscription.GetSubscriptionQueries())
                        {
                            stringSet.Add(subscriptionQuery);
                        }
                    }
                    else
                    {
                        stringSet.Add(current.GetSubscriptionQuery());
                    }
                }
            }
            foreach (string query in stringSet)
            {
                try
                {
                    SubscriptionId subscriptionId;
                    ((SubscriptionId) ref subscriptionId).\u002Ector("Core", typeof(AuditingNotificationSubscriber).FullName + "." + this.GetHashFromQuery(query), (Scope)0);
                    SubscriberConfiguration subscriberConfiguration1 = new SubscriberConfiguration();
                    subscriberConfiguration1.set_SubscriptionQuery(query);
                    SubscriberConfiguration subscriberConfiguration2 = subscriberConfiguration1;
                    AuditingNotificationSubscriber.log.DebugFormat("Subscribing '{0}'", (object)query);
                    SubscriptionId id     = this.subscriptionManager.Subscribe(subscriptionId, (ISubscriber)this, subscriberConfiguration2).get_Id();
                    string         query1 = query;
                    this.subscriptionIdToAuditingInstances.TryAdd(id.ToString(), ((IEnumerable <IAuditing2>) this.auditingPlugins.AuditingInstances).Where <IAuditing2>((Func <IAuditing2, bool>)(instance =>
                    {
                        try
                        {
                            return(string.Compare(query1, instance.GetSubscriptionQuery(), StringComparison.OrdinalIgnoreCase) == 0);
                        }
                        catch (NotImplementedException ex)
                        {
                            return(instance is IAuditingMultiSubscription multiSubscription && ((IEnumerable <string>)multiSubscription.GetSubscriptionQueries()).Contains <string>(query1));
                        }
                    })));
                    AuditingNotificationSubscriber.log.DebugFormat("Subscribed '{0}' with {1} number of auditing instances.", (object)query, (object)this.subscriptionIdToAuditingInstances[id.ToString()].Count <IAuditing2>());
                }
                catch (Exception ex)
                {
                    AuditingNotificationSubscriber.log.ErrorFormat("Unable to subscribe auditing instance with query '{0}'. {1}", (object)query, (object)ex);
                }
            }
            AuditingNotificationSubscriber.log.InfoFormat("Auditing pub/sub subscription succeeded.", Array.Empty <object>());
            Scheduler.get_Instance().Remove("AuditingIndications");
        }
        // Token: 0x0600002C RID: 44 RVA: 0x00002D00 File Offset: 0x00000F00
        private void Subscribe(object state)
        {
            AuditingNotificationSubscriber.log.Debug("Subscribing auditing indications..");
            try
            {
                AuditingNotificationSubscriber.DeleteOldSubscriptions();
            }
            catch (Exception ex)
            {
                AuditingNotificationSubscriber.log.Warn("Exception deleting old subscriptions:", ex);
            }
            HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (IAuditing2 auditing in this.auditingPlugins.AuditingInstances)
            {
                IAuditingMultiSubscription auditingMultiSubscription = auditing as IAuditingMultiSubscription;
                if (auditingMultiSubscription != null)
                {
                    foreach (string item in auditingMultiSubscription.GetSubscriptionQueries())
                    {
                        hashSet.Add(item);
                    }
                }
                else
                {
                    hashSet.Add(auditing.GetSubscriptionQuery());
                }
            }
            foreach (string text in hashSet)
            {
                try
                {
                    AuditingNotificationSubscriber.log.DebugFormat("Subscribing '{0}'", text);
                    string key = InformationServiceSubscriptionProviderShared.Instance().Subscribe(text, this, new SubscriptionOptions
                    {
                        Description = "AuditingIndications"
                    });
                    string query1 = text;
                    this.subscriptionIdToAuditingInstances.TryAdd(key, this.auditingPlugins.AuditingInstances.Where(delegate(IAuditing2 instance)
                    {
                        bool result;
                        try
                        {
                            result = (string.Compare(query1, instance.GetSubscriptionQuery(), StringComparison.OrdinalIgnoreCase) == 0);
                        }
                        catch (NotImplementedException)
                        {
                            IAuditingMultiSubscription auditingMultiSubscription2 = instance as IAuditingMultiSubscription;
                            result = (auditingMultiSubscription2 != null && auditingMultiSubscription2.GetSubscriptionQueries().Contains(query1));
                        }
                        return(result);
                    }));
                    AuditingNotificationSubscriber.log.DebugFormat("Subscribed '{0}' with {1} number of auditing instances.", text, this.subscriptionIdToAuditingInstances[key].Count <IAuditing2>());
                }
                catch (Exception ex2)
                {
                    AuditingNotificationSubscriber.log.ErrorFormat("Unable to subscribe auditing instance with query '{0}'. {1}", text, ex2);
                }
            }
            AuditingNotificationSubscriber.log.InfoFormat("Auditing pub/sub subscription succeeded.", Array.Empty <object>());
            Scheduler.Instance.Remove("AuditingIndications");
        }