private static bool IsReminderSearchFolderForO12(DefaultFolderContext context, SearchFolderCriteria currentCriteria, out bool isUpToDate) { isUpToDate = false; ExTraceGlobals.DefaultFoldersTracer.TraceDebug <SearchFolderCriteria>(-1L, "RemindersSearchFolderValidation::IsReminderSearchFolderForO12. We are checking currentCriteria on the folder we found. currentCriteria = {0}.", currentCriteria); QueryFilter[] o12RemindersSearchFolderExclusionList = RemindersSearchFolderValidation.GetO12RemindersSearchFolderExclusionList(currentCriteria); if (o12RemindersSearchFolderExclusionList == null) { return(false); } foreach (QueryFilter queryFilter in o12RemindersSearchFolderExclusionList) { ComparisonFilter comparisonFilter = queryFilter as ComparisonFilter; if (comparisonFilter == null || comparisonFilter.ComparisonOperator != ComparisonOperator.NotEqual || !comparisonFilter.Property.Equals(InternalSchema.ParentItemId) || !(comparisonFilter.PropertyValue is StoreId)) { return(false); } } AndFilter andFilter = currentCriteria.SearchQuery as AndFilter; SearchFolderCriteria searchFolderCriteria = RemindersSearchFolderValidation.CreateRemindersQueryForO12(context, o12RemindersSearchFolderExclusionList); AndFilter andFilter2 = (AndFilter)searchFolderCriteria.SearchQuery; if (andFilter == null || andFilter.FilterCount != 2 || andFilter.FilterCount != andFilter2.FilterCount || currentCriteria.FolderScope.Length != searchFolderCriteria.FolderScope.Length) { return(false); } for (int j = 0; j < currentCriteria.FolderScope.Length; j++) { if (!currentCriteria.FolderScope[j].Equals(searchFolderCriteria.FolderScope[j])) { return(false); } } if (!andFilter.Filters[1].Equals(andFilter2.Filters[1])) { return(false); } AndFilter andFilter3 = (AndFilter)andFilter2.Filters[0]; isUpToDate = (o12RemindersSearchFolderExclusionList.Length == andFilter3.FilterCount); return(true); }
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); }