Example #1
0
        private static bool ApplyOwaContinuousSearch(SearchFolder searchFolder, SearchFolderCriteria searchCriteria, MailboxSession mailboxSession, OwaSearchContext searchContext)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::ApplyOwaContinuousSearch] Start for search folder: {0}", searchContext.ClientSearchFolderIdentity);
            StoreObjectId storeObjectId = searchFolder.StoreObjectId;
            bool          flag          = false;

            try
            {
                IAsyncResult asyncResult = searchFolder.BeginApplyContinuousSearch(searchCriteria, null, null);
                flag = asyncResult.AsyncWaitHandle.WaitOne(searchContext.SearchTimeoutInMilliseconds);
                if (flag)
                {
                    searchFolder.EndApplyContinuousSearch(asyncResult);
                    searchContext.ViewFilterActions |= ViewFilterActions.SearchCriteriaApplied;
                    ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::ApplyOwaContinuousSearch] Search completed for search folder: {0}", searchContext.ClientSearchFolderIdentity);
                }
                else
                {
                    flag = true;
                    searchContext.ViewFilterActions |= ViewFilterActions.PopulateSearchFolderTimedOut;
                    ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::ApplyOwaContinuousSearch] Search timed out for search folder: {0}", searchContext.ClientSearchFolderIdentity);
                }
            }
            catch (QueryInProgressException ex)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.QueryInProgressException;
                string message = string.Format("[OwaFilterState::ApplyOwaContinuousSearch] Population of dynamic search folder: {0} failed due to QueryInProgressException: {1}. ViewFilterActions: {2}", searchContext.ClientSearchFolderIdentity, ex.ToString(), (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, message);
                flag = OwaFilterState.EnsureSearchIsCompleted(searchFolder, mailboxSession, searchContext);
            }
            catch (CorruptDataException ex2)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.CorruptDataException;
                string text = string.Format("[OwaFilterState::ApplyOwaContinuousSearch] Population of dynamic search folder: {0} failed due to CorruptDataException: {1}. ViewFilterActions = {2}.", searchContext.ClientSearchFolderIdentity, ex2.ToString(), (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, text);
                OwaFilterState.SendWatsonWithoutDump(ex2, text);
            }
            catch (ObjectNotFoundException ex3)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.ObjectNotFoundException;
                string message2 = string.Format("[OwaFilterState::ApplyOwaContinuousSearch] Population of dynamic search folder: {0} failed due to ObjectNotFoundException: {1}. ViewFilterActions = {2}.", searchContext.ClientSearchFolderIdentity, ex3.ToString(), (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, message2);
            }
            catch (Exception ex4)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.Exception;
                string text2 = string.Format("[OwaFilterState::ApplyOwaContinuousSearch] Population of dynamic search folder: {0} failed due to Exception: {1}. ViewFilterActions = {2}.", searchContext.ClientSearchFolderIdentity, ex4.ToString(), (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, text2);
                OwaFilterState.SendWatsonWithoutDump(ex4, text2);
            }
            return(flag);
        }
Example #2
0
 private static bool VerifyAndFixRemindersSearchFolder(DefaultFolderContext context, SearchFolder reminders)
 {
     RemindersSearchFolderValidation.RemindersSearchFolderState remindersSearchFolderState = RemindersSearchFolderValidation.GetRemindersSearchFolderState(context, reminders);
     if (!remindersSearchFolderState.IsUpToDate)
     {
         ExTraceGlobals.DefaultFoldersTracer.TraceDebug <RemindersSearchFolderValidation.RemindersSearchFolderState>(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. We are updating reminder's state: {0}", remindersSearchFolderState);
         if (context.Session.LogonType != LogonType.Owner)
         {
             return(false);
         }
         QueryFilter[] array = (remindersSearchFolderState.Version == RemindersSearchFolderValidation.RemindersSearchFolderVersion.O12) ? RemindersSearchFolderValidation.GetO12RemindersSearchFolderExclusionList(reminders.GetSearchCriteria()) : null;
         if (array != null && array.Length > 30)
         {
             string message = "A maximum allowed number of exclusion entries for a Reminders search folder is reached.Either default folders got re-created numerous times or the folder completeness criteria produced false negatives.";
             ExTraceGlobals.DefaultFoldersTracer.TraceError(-1L, message);
             return(true);
         }
         SearchFolderCriteria searchFolderCriteria = RemindersSearchFolderValidation.CreateRemindersQueryForO12(context, array);
         if (array != null)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <int, int>(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. Current Reminders search criteria is incomplete: {0} exclusions versus {1} expected", array.Length, RemindersSearchFolderValidation.GetO12RemindersSearchFolderExclusionList(searchFolderCriteria).Length);
         }
         if (remindersSearchFolderState.Version != RemindersSearchFolderValidation.RemindersSearchFolderVersion.O11)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <RemindersSearchFolderValidation.RemindersSearchFolderState>(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. Reminder starts to apply new criteria on the folder. folderState = {0}.", remindersSearchFolderState);
             reminders.ApplyContinuousSearch(searchFolderCriteria);
         }
         else
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <RemindersSearchFolderValidation.RemindersSearchFolderState>(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. Outlook12. folderState = {0}.", remindersSearchFolderState);
             IAsyncResult asyncResult = reminders.BeginApplyContinuousSearch(searchFolderCriteria, null, null);
             if (RemindersSearchFolderValidation.InternalWaitForRemindersIndexing(asyncResult))
             {
                 reminders.EndApplyContinuousSearch(asyncResult);
             }
             else
             {
                 ExTraceGlobals.DefaultFoldersTracer.TraceDebug(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. Timeout expired waiting for a Reminders search folder to finish population.");
             }
             RemindersSearchFolderValidation.UnsetStaleReminders(context, reminders);
             UserConfiguration userConfiguration = null;
             try
             {
                 try
                 {
                     userConfiguration = context.Session.UserConfigurationManager.GetFolderConfiguration("Calendar", UserConfigurationTypes.Dictionary, context.Session.GetDefaultFolderId(DefaultFolderType.Calendar));
                 }
                 catch (ObjectNotFoundException)
                 {
                     ExTraceGlobals.DefaultFoldersTracer.TraceDebug(-1L, "RemindersSearchFolderValidation::VerifyAndFixRemindersSearchFolder. No existing Calendar configuration was found. We are creating new one.");
                     userConfiguration = context.Session.UserConfigurationManager.CreateFolderConfiguration("Calendar", UserConfigurationTypes.Dictionary, context.Session.GetDefaultFolderId(DefaultFolderType.Calendar));
                 }
                 IDictionary dictionary = userConfiguration.GetDictionary();
                 dictionary["piReminderUpgradeTime"] = Util.ConvertDateTimeToRTime(ExDateTime.GetNow(context.Session.ExTimeZone));
                 userConfiguration.Save();
             }
             finally
             {
                 if (userConfiguration != null)
                 {
                     userConfiguration.Dispose();
                 }
             }
         }
     }
     return(true);
 }