Esempio n. 1
0
 public static SubscriptionCache GetCache(UserContext userContext, bool useInMemCache)
 {
     if (userContext == null)
     {
         throw new ArgumentNullException("userContext");
     }
     lock (SubscriptionCache.syncRoot)
     {
         if (!userContext.CanActAsOwner)
         {
             userContext.SubscriptionCache = new SubscriptionCache();
         }
         else if (userContext.SubscriptionCache == null || !useInMemCache)
         {
             List <PimAggregationSubscription> allSendAsSubscriptions = SubscriptionManager.GetAllSendAsSubscriptions(userContext.MailboxSession);
             userContext.SubscriptionCache = new SubscriptionCache();
             short num = 1;
             foreach (PimAggregationSubscription pimAggregationSubscription in allSendAsSubscriptions)
             {
                 string address = Utilities.DecodeIDNDomain(pimAggregationSubscription.UserEmailAddress);
                 if (128 <= num)
                 {
                     break;
                 }
                 SubscriptionCacheEntry item = new SubscriptionCacheEntry(pimAggregationSubscription.SubscriptionGuid, address, pimAggregationSubscription.UserDisplayName, pimAggregationSubscription.InstanceKey, userContext.MailboxSession.PreferedCulture);
                 userContext.SubscriptionCache.cacheEntries.Add(item);
                 num += 1;
             }
             userContext.SubscriptionCache.cacheEntries.Sort();
         }
     }
     return(userContext.SubscriptionCache);
 }
Esempio n. 2
0
 public int Add(SubscriptionCacheEntry entry)
 {
     if (128 == this.cacheEntries.Count)
     {
         return(-1);
     }
     lock (SubscriptionCache.syncRoot)
     {
         for (int i = 0; i < this.cacheEntries.Count; i++)
         {
             int num = this.cacheEntries[i].CompareTo(entry);
             if (num == 0)
             {
                 this.cacheEntries[i] = entry;
                 return(i);
             }
             if (0 < num)
             {
                 this.cacheEntries.Insert(i, entry);
                 return(i);
             }
         }
         this.cacheEntries.Add(entry);
     }
     return(this.cacheEntries.Count - 1);
 }
Esempio n. 3
0
 private int ForFirstEntryByIdThenAddress(SubscriptionCacheEntry entry, SubscriptionCache.CacheEntryProcessor processor)
 {
     lock (SubscriptionCache.syncRoot)
     {
         for (int i = 0; i < this.cacheEntries.Count; i++)
         {
             if (this.cacheEntries[i].Id.Equals(entry.Id))
             {
                 processor(i);
                 return(i);
             }
         }
         for (int j = 0; j < this.cacheEntries.Count; j++)
         {
             int num = this.cacheEntries[j].CompareTo(entry);
             if (num == 0)
             {
                 processor(j);
                 return(j);
             }
             if (0 < num)
             {
                 break;
             }
         }
     }
     return(-1);
 }
Esempio n. 4
0
        public bool TryGetSendAsDefaultEntry(SendAddressDefaultSetting sendAddressDefaultSetting, out SubscriptionCacheEntry subscriptionCacheEntry)
        {
            subscriptionCacheEntry = new SubscriptionCacheEntry(Guid.Empty, string.Empty, string.Empty, null, CultureInfo.InvariantCulture);
            Guid subscriptionId;

            return(sendAddressDefaultSetting.TryGetSubscriptionSendAddressId(out subscriptionId) && this.TryGetEntry(subscriptionId, out subscriptionCacheEntry));
        }
Esempio n. 5
0
        public int Modify(SubscriptionCacheEntry entry, SendAsState sendAsState, AggregationStatus status)
        {
            int index = -1;

            this.ForFirstEntryByIdThenAddress(entry, delegate(int i)
            {
                if (!SubscriptionManager.IsValidForSendAs(sendAsState, status))
                {
                    this.cacheEntries.RemoveAt(i);
                    index = i;
                    return;
                }
                if (this.cacheEntries[i].Id.Equals(entry.Id))
                {
                    int num = this.cacheEntries[i].CompareTo(entry);
                    if (num == 0 && entry.DisplayNameMatch(this.cacheEntries[i]))
                    {
                        index = -2;
                        return;
                    }
                    if (0 < num)
                    {
                        while (0 < i)
                        {
                            if (0 >= this.cacheEntries[i - 1].CompareTo(entry))
                            {
                                break;
                            }
                            this.cacheEntries[i] = this.cacheEntries[--i];
                        }
                    }
                    else if (0 > num)
                    {
                        while (this.cacheEntries.Count - 1 > i && 0 > this.cacheEntries[i + 1].CompareTo(entry))
                        {
                            this.cacheEntries[i] = this.cacheEntries[++i];
                        }
                    }
                }
                this.cacheEntries[i] = entry;
                index = i;
            });
            if (-1 == index && SubscriptionManager.IsValidForSendAs(sendAsState, status))
            {
                index = this.Add(entry);
            }
            return(index);
        }
Esempio n. 6
0
 public bool TryGetEntry(Guid subscriptionId, out SubscriptionCacheEntry subscriptionCacheEntry)
 {
     lock (SubscriptionCache.syncRoot)
     {
         foreach (SubscriptionCacheEntry subscriptionCacheEntry2 in this.cacheEntries)
         {
             if (subscriptionId.Equals(subscriptionCacheEntry2.Id))
             {
                 subscriptionCacheEntry = subscriptionCacheEntry2;
                 return(true);
             }
         }
     }
     subscriptionCacheEntry = new SubscriptionCacheEntry(Guid.Empty, string.Empty, string.Empty, null, CultureInfo.InvariantCulture);
     return(false);
 }
Esempio n. 7
0
        public bool TryGetEntry(Participant fromParticipant, out SubscriptionCacheEntry subscriptionCacheEntry)
        {
            SubscriptionCacheEntry subscriptionCacheEntry2 = new SubscriptionCacheEntry(Guid.Empty, fromParticipant.EmailAddress, fromParticipant.DisplayName, null, CultureInfo.InvariantCulture);

            lock (SubscriptionCache.syncRoot)
            {
                foreach (SubscriptionCacheEntry subscriptionCacheEntry3 in this.cacheEntries)
                {
                    if (subscriptionCacheEntry3.CompareTo(subscriptionCacheEntry2) == 0)
                    {
                        subscriptionCacheEntry = subscriptionCacheEntry3;
                        return(true);
                    }
                }
            }
            subscriptionCacheEntry = subscriptionCacheEntry2;
            return(false);
        }
Esempio n. 8
0
        private void UpdateSubscriptionCache(QueryNotification notification, TextWriter writer)
        {
            bool flag = null == this.userContext.SubscriptionCache;

            if (!RecipientCache.RunGetCacheOperationUnderExceptionHandler(delegate
            {
                SubscriptionCache.GetCache(this.userContext);
            }, new RecipientCache.ExceptionHandler(this.HandleSubscriptionLoadException), this.GetHashCode()))
            {
                return;
            }
            SubscriptionCache subscriptionCache = this.userContext.SubscriptionCache;

            if (flag)
            {
                SubscriptionNotificationHandler.RefreshClientCache(writer, subscriptionCache);
                return;
            }
            int num;

            if (QueryNotificationType.RowDeleted == notification.EventType)
            {
                num = subscriptionCache.Delete(notification.Index);
            }
            else
            {
                object obj = notification.Row[0];
                if (!(obj is Guid))
                {
                    return;
                }
                Guid   id   = (Guid)obj;
                string text = notification.Row[1] as string;
                if (text == null)
                {
                    return;
                }
                string text2 = notification.Row[2] as string;
                if (text2 == null)
                {
                    return;
                }
                obj = notification.Row[3];
                if (!(obj is int))
                {
                    return;
                }
                SendAsState sendAsState = (SendAsState)obj;
                obj = notification.Row[4];
                if (!(obj is int))
                {
                    return;
                }
                AggregationStatus      status  = (AggregationStatus)obj;
                string                 address = Utilities.DecodeIDNDomain(text);
                SubscriptionCacheEntry entry   = new SubscriptionCacheEntry(id, address, text2, notification.Index, this.mailboxSession.PreferedCulture);
                switch (notification.EventType)
                {
                case QueryNotificationType.RowAdded:
                    if (!SubscriptionManager.IsValidForSendAs(sendAsState, status))
                    {
                        return;
                    }
                    num = subscriptionCache.Add(entry);
                    goto IL_14B;

                case QueryNotificationType.RowModified:
                    num = subscriptionCache.Modify(entry, sendAsState, status);
                    goto IL_14B;
                }
                num = -1;
            }
IL_14B:
            if (-1 < num)
            {
                SubscriptionNotificationHandler.RefreshClientCache(writer, subscriptionCache);
            }
        }