Example #1
0
        private static void SmartReplyOrForward(MessageItem originalItem, MessageItem newItem, UserContext userContext)
        {
            if (!RecipientCache.RunGetCacheOperationUnderDefaultExceptionHandler(delegate
            {
                SubscriptionCache.GetCache(userContext);
            }, userContext.GetHashCode()))
            {
                return;
            }
            SendAddressDefaultSetting sendAddressDefaultSetting = new SendAddressDefaultSetting(userContext);

            if (sendAddressDefaultSetting.IsUserEmailAddress)
            {
                return;
            }
            SubscriptionCacheEntry subscriptionCacheEntry;

            if (userContext.SubscriptionCache.TryGetSendAsDefaultEntry(sendAddressDefaultSetting, out subscriptionCacheEntry))
            {
                newItem.From = new Participant(subscriptionCacheEntry.DisplayName, subscriptionCacheEntry.Address, "SMTP");
                return;
            }
            try
            {
                object obj = originalItem.TryGetProperty(MessageItemSchema.SharingInstanceGuid);
                SubscriptionCacheEntry subscriptionCacheEntry2;
                if (obj is Guid && userContext.SubscriptionCache.TryGetEntry((Guid)obj, out subscriptionCacheEntry2))
                {
                    newItem.From = new Participant(subscriptionCacheEntry2.DisplayName, subscriptionCacheEntry2.Address, "SMTP");
                }
            }
            catch (NotInBagPropertyErrorException)
            {
            }
        }
Example #2
0
 protected void FinishSession(RecipientCache backEndCache, UserConfiguration configuration)
 {
     this.Merge(backEndCache);
     foreach (RecipientInfoCacheEntry recipientInfoCacheEntry in this.cacheEntries)
     {
         recipientInfoCacheEntry.Decay();
     }
     this.Commit(configuration);
 }
 public override void AddEntry(RecipientInfoCacheEntry newEntry)
 {
     base.AddEntry(newEntry);
     if (0 < (newEntry.RecipientFlags & 2))
     {
         RecipientCache recipientCache = RoomsCache.TryGetCache(base.UserContext);
         if (recipientCache != null)
         {
             recipientCache.AddEntry(newEntry);
         }
     }
 }
Example #4
0
 public override void Commit(bool mergeBeforeCommit)
 {
     if (base.IsDirty)
     {
         using (RecipientCacheTransaction recipientCacheTransaction = new RecipientCacheTransaction("OWA.SendFromCache", base.UserContext))
         {
             RecipientCache backEndRecipientCache = null;
             if (mergeBeforeCommit)
             {
                 backEndRecipientCache = new SendFromCache(base.UserContext, recipientCacheTransaction.Configuration);
             }
             this.Commit(backEndRecipientCache, recipientCacheTransaction.Configuration);
         }
     }
 }
Example #5
0
 internal virtual void Commit(RecipientCache backEndRecipientCache, UserConfiguration configuration)
 {
     this.Merge(backEndRecipientCache);
     this.Commit(configuration);
 }
Example #6
0
        protected void Merge(RecipientCache externalRecipientCache)
        {
            if (externalRecipientCache == null)
            {
                return;
            }
            if (!(externalRecipientCache.syncTime > this.syncTime))
            {
                return;
            }
            int cacheLength = externalRecipientCache.CacheLength;
            int count       = this.cacheEntries.Count;

            if (cacheLength <= 0)
            {
                return;
            }
            int num = cacheLength + count;
            List <RecipientInfoCacheEntry>      list     = new List <RecipientInfoCacheEntry>((num > (int)this.cacheSize) ? num : ((int)this.cacheSize));
            IComparer <RecipientInfoCacheEntry> comparer = new RecipientCache.PrimaryKeySort();

            this.cacheEntries.Sort(comparer);
            externalRecipientCache.cacheEntries.Sort(comparer);
            int num2 = 0;
            int num3 = 0;

            while (num2 < count || num3 < cacheLength)
            {
                RecipientInfoCacheEntry recipientInfoCacheEntry;
                if (num2 < count)
                {
                    recipientInfoCacheEntry = this.CacheEntries[num2];
                }
                else
                {
                    recipientInfoCacheEntry = null;
                }
                RecipientInfoCacheEntry recipientInfoCacheEntry2;
                if (num3 < cacheLength)
                {
                    recipientInfoCacheEntry2 = externalRecipientCache.CacheEntries[num3];
                }
                else
                {
                    recipientInfoCacheEntry2 = null;
                }
                int num4 = comparer.Compare(recipientInfoCacheEntry, recipientInfoCacheEntry2);
                int num5 = 0;
                if (recipientInfoCacheEntry != null && recipientInfoCacheEntry2 != null)
                {
                    num5 = (int)(Convert.ToByte(Utilities.IsMapiPDL(recipientInfoCacheEntry.RoutingType)) | Convert.ToByte(Utilities.IsMapiPDL(recipientInfoCacheEntry2.RoutingType)));
                }
                if (num4 < 0 || num5 == 1)
                {
                    if (recipientInfoCacheEntry.IsSessionFlagSet())
                    {
                        list.Add(recipientInfoCacheEntry);
                    }
                    num2++;
                }
                else if (num4 == 0)
                {
                    short sessionCount = Math.Max(recipientInfoCacheEntry.SessionCount, recipientInfoCacheEntry2.SessionCount);
                    if (recipientInfoCacheEntry2.DateTimeTicks > recipientInfoCacheEntry.DateTimeTicks)
                    {
                        this.UpdateEntry(recipientInfoCacheEntry2, num2);
                        list.Add(this.cacheEntries[num2]);
                    }
                    else
                    {
                        list.Add(recipientInfoCacheEntry);
                    }
                    list[list.Count - 1].SessionCount = sessionCount;
                    num2++;
                    num3++;
                }
                else
                {
                    list.Add(recipientInfoCacheEntry2);
                    num3++;
                }
            }
            list.Sort(new RecipientCache.UsageSort());
            if (num > (int)this.cacheSize && list.Count > (int)this.cacheSize)
            {
                this.cacheEntries = list.GetRange(0, (int)this.cacheSize);
                return;
            }
            this.cacheEntries = list;
        }
Example #7
0
 public static bool RunGetCacheOperationUnderDefaultExceptionHandler(RecipientCache.GetCacheOperation operation, int hashCode)
 {
     return(RecipientCache.RunGetCacheOperationUnderExceptionHandler(operation, new RecipientCache.ExceptionHandler(RecipientCache.HandleGetCacheException), hashCode));
 }
Example #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);
            }
        }
Example #9
0
        internal override void HandlePendingGetTimerCallback()
        {
            lock (this.syncRoot)
            {
                if (this.isDisposed)
                {
                    return;
                }
            }
            bool flag2 = false;
            bool flag3 = false;

            try
            {
                this.userContext.Lock();
                flag2 = true;
                Utilities.ReconnectStoreSession(this.mailboxSession, this.userContext);
                lock (this.syncRoot)
                {
                    if (this.needReinitSubscriptions)
                    {
                        this.InitSubscription();
                        this.needReinitSubscriptions = false;
                        this.missedNotifications     = true;
                    }
                    if (this.missedNotifications)
                    {
                        if (!RecipientCache.RunGetCacheOperationUnderExceptionHandler(delegate
                        {
                            SubscriptionCache.GetCache(this.userContext, false);
                        }, new RecipientCache.ExceptionHandler(this.HandleSubscriptionLoadException), this.GetHashCode()))
                        {
                            return;
                        }
                    }
                }
            }
            catch (OwaLockTimeoutException ex)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>((long)this.GetHashCode(), "User context lock timed out in the pending GET timer callback. Exception: {0}", ex.Message);
                this.missedNotifications = true;
                flag3 = true;
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>((long)this.GetHashCode(), "Unexpected exception in pending GET timer callback thread. Exception: {0}", ex2.Message);
                this.missedNotifications = true;
                flag3 = true;
            }
            finally
            {
                if (this.userContext.LockedByCurrentThread() && flag2)
                {
                    Utilities.DisconnectStoreSessionSafe(this.mailboxSession);
                    this.userContext.Unlock();
                }
            }
            try
            {
                if (this.missedNotifications && !flag3)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    using (StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.InvariantCulture))
                    {
                        SubscriptionNotificationHandler.RefreshClientCache(stringWriter, this.userContext.SubscriptionCache);
                    }
                    if (0 < stringBuilder.Length)
                    {
                        this.payload.AddPayload(stringBuilder);
                        this.payload.PickupData();
                    }
                    this.missedNotifications = false;
                }
            }
            catch (Exception ex3)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>((long)this.GetHashCode(), "Unexpected exception in pending GET timer callback thread. Exception: {0}", ex3.Message);
                this.missedNotifications = true;
            }
        }