Example #1
0
 internal SearchFolderCriteria(QueryFilter searchQuery, StoreId[] folderScope, SearchState searchState)
 {
     SearchFolderCriteria.CheckFolderScope(folderScope);
     this.FolderScope = folderScope;
     this.SearchQuery = searchQuery;
     this.searchState = searchState;
 }
Example #2
0
        protected override void SetPropertiesInternal(DefaultFolderContext context, Folder folder)
        {
            base.SetPropertiesInternal(context, folder);
            SearchFolderCriteria searchFolderCriteria = null;
            SearchFolder         searchFolder         = (SearchFolder)folder;

            searchFolder[InternalSchema.ContainerClass] = "IPF.Task";
            int num = 786432;

            searchFolder[InternalSchema.ExtendedFolderToDoVersion] = num;
            searchFolder.Save();
            searchFolder.Load(null);
            try
            {
                searchFolderCriteria = searchFolder.GetSearchCriteria();
            }
            catch (ObjectNotInitializedException arg)
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <string, ObjectNotInitializedException>((long)this.GetHashCode(), "ToDoSearchValidation::SetPropertiesInternal. Failed to get search criteria on the folder with name {0} due to {1}. It can be normal though for a search folder without search criteria applied yet.", searchFolder.DisplayName, arg);
            }
            if (searchFolderCriteria == null || !ToDoSearchValidation.MatchedToDoSearchCriteriaApproxly(searchFolderCriteria))
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <string, SearchFolderCriteria, SearchFolderCriteria>((long)this.GetHashCode(), "ToDoSearchValidation::SetPropertiesInternal. Apply ToDo search criteria on the folder. DisplayName = {0}, currentCriteria = {1}, newCriteria = {2}.", searchFolder.DisplayName, searchFolderCriteria, ToDoSearchValidation.GetToDoSearchCriteria(context));
                searchFolder.ApplyContinuousSearch(ToDoSearchValidation.GetToDoSearchCriteria(context));
            }
        }
        protected override void SetPropertiesInternal(DefaultFolderContext context, Folder folder)
        {
            base.SetPropertiesInternal(context, folder);
            folder.Save();
            SearchFolder searchFolder = (SearchFolder)folder;

            StoreObjectId[] folderScope;
            if (MailboxSession.DefaultFoldersToForceInit != null && MailboxSession.DefaultFoldersToForceInit.Contains(DefaultFolderType.MyContacts))
            {
                folderScope = this.contactsSearchFolderCriteria.GetExistingDefaultFolderScope(context);
            }
            else
            {
                folderScope = this.contactsSearchFolderCriteria.GetDefaultFolderScope(context.Session, true);
            }
            SearchFolderCriteria searchFolderCriteria = ContactsSearchFolderCriteria.CreateSearchCriteria(folderScope);

            ContactsSearchFolderCriteria.ApplyContinuousSearchFolderCriteria(XSOFactory.Default, context.Session, searchFolder, searchFolderCriteria);
            bool flag = context.Session.MailboxOwner.RecipientTypeDetails != RecipientTypeDetails.GroupMailbox || !context.Session.ClientInfoString.Contains("Client=WebServices;Action=ConfigureGroupMailbox");

            MyContactsFolderValidation.Tracer.TraceDebug <string, RecipientTypeDetails, bool>((long)context.Session.GetHashCode(), "SearchFolder criteria applied. ClientInfoString={0}, RecipientTypeDetails={1}, ShouldWaitForNotification={2}", context.Session.ClientInfoString, context.Session.MailboxOwner.RecipientTypeDetails, flag);
            if (flag)
            {
                ContactsSearchFolderCriteria.WaitForSearchFolderPopulation(XSOFactory.Default, context.Session, searchFolder);
            }
            folder.Load(null);
        }
Example #4
0
        public void MakeVisibleToOutlook(bool replaceAssociatedMessageIfPresent, SearchFolderCriteria criteria)
        {
            if (this.IsDirty)
            {
                throw new InvalidOperationException(ServerStrings.ExMustSaveFolderToMakeVisibleToOutlook);
            }
            VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId((MailboxSession)base.Session, (Guid)this[InternalSchema.OutlookSearchFolderClsId]);

            if (versionedId != null && !replaceAssociatedMessageIfPresent)
            {
                throw new ObjectExistedException(ServerStrings.ExSearchFolderIsAlreadyVisibleToOutlook);
            }
            if (criteria == null)
            {
                try
                {
                    criteria = base.GetSearchCriteria();
                    goto IL_70;
                }
                catch (ObjectNotInitializedException innerException)
                {
                    throw new InvalidOperationException(ServerStrings.ExMustSetSearchCriteriaToMakeVisibleToOutlook, innerException);
                }
            }
            base.ApplyContinuousSearch(criteria);
IL_70:
            this.CreateOrHijackAssociatedMessage(versionedId, criteria);
        }
 protected static bool MatchSearchFolderCriteria(SearchFolderCriteria currentCriteria, SearchFolderCriteria expectedCriteria)
 {
     if (currentCriteria.FolderScope.Length != expectedCriteria.FolderScope.Length)
     {
         return(false);
     }
     for (int i = 0; i < expectedCriteria.FolderScope.Length; i++)
     {
         bool flag = false;
         for (int j = 0; j < currentCriteria.FolderScope.Length; j++)
         {
             if (currentCriteria.FolderScope[j].Equals(expectedCriteria.FolderScope[i]))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceError <int, string>(-1L, "SearchFolderValidation::MatchSearchFolderCriteria. We failed to find the folder scope from the current search criteria. Index = {0}, Id = {1}.", i, expectedCriteria.FolderScope[i].ToBase64String());
             return(false);
         }
     }
     return(currentCriteria.SearchQuery.Equals(expectedCriteria.SearchQuery));
 }
Example #6
0
        public static void UpdateFolderScope(IXSOFactory xsoFactory, IMailboxSession mailboxSession, ISearchFolder searchFolder, StoreObjectId[] folderScope)
        {
            ArgumentValidator.ThrowIfNull("xsoFactory", xsoFactory);
            ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
            ArgumentValidator.ThrowIfNull("searchFolder", searchFolder);
            ArgumentValidator.ThrowIfNull("folderScope", folderScope);
            SearchFolderCriteria searchFolderCriteria;

            try
            {
                searchFolderCriteria = searchFolder.GetSearchCriteria();
            }
            catch (ObjectNotInitializedException)
            {
                searchFolderCriteria = null;
            }
            if (searchFolderCriteria != null && ContactsSearchFolderCriteria.MatchFolderScope(searchFolderCriteria.FolderScope, folderScope))
            {
                return;
            }
            SearchFolderCriteria searchFolderCriteria2 = ContactsSearchFolderCriteria.CreateSearchCriteria(folderScope);

            ContactsSearchFolderCriteria.Tracer.TraceDebug <SearchFolderCriteria, SearchFolderCriteria>((long)searchFolder.GetHashCode(), "Updating MyContactsFolder Search Criteria since it is different from the current one. Current:{0}, New:{1}.", searchFolderCriteria, searchFolderCriteria2);
            ContactsSearchFolderCriteria.ApplyContinuousSearchFolderCriteria(xsoFactory, mailboxSession, searchFolder, searchFolderCriteria2);
            ContactsSearchFolderCriteria.WaitForSearchFolderPopulation(xsoFactory, mailboxSession, searchFolder);
        }
Example #7
0
        internal override bool EnsureIsValid(DefaultFolderContext context, Folder folder)
        {
            FromFavoriteSendersFolderValidation.Tracer.TraceFunction((long)this.GetHashCode(), "Entering FromFavoriteSendersFolderValidation.EnsureIsValid");
            if (!base.EnsureIsValid(context, folder))
            {
                FromFavoriteSendersFolderValidation.Tracer.TraceFunction((long)this.GetHashCode(), "Exiting FromFavoriteSendersFolderValidation.EnsureIsValid:  folder failed base class validation.");
                return(false);
            }
            SearchFolder searchFolder = folder as SearchFolder;

            if (searchFolder == null)
            {
                FromFavoriteSendersFolderValidation.Tracer.TraceFunction((long)this.GetHashCode(), "Exiting FromFavoriteSendersFolderValidation.Validate:  not a SearchFolder instance.");
                return(false);
            }
            SearchFolderCriteria searchFolderCriteria = SearchFolderValidation.TryGetSearchCriteria(searchFolder);
            SearchFolderCriteria searchCriteria       = FromFavoriteSendersFolderValidation.GetSearchCriteria(context);

            if (searchFolderCriteria == null || !SearchFolderValidation.MatchSearchFolderCriteria(searchFolderCriteria, searchCriteria) || searchFolderCriteria.DeepTraversal != searchCriteria.DeepTraversal)
            {
                FromFavoriteSendersFolderValidation.Tracer.TraceDebug((long)this.GetHashCode(), "Current criteria are NOT initialized or don't match desired criteria.  Updating.");
                searchFolder.ApplyContinuousSearch(searchCriteria);
            }
            FromFavoriteSendersFolderValidation.Tracer.TraceFunction((long)this.GetHashCode(), "Exiting FromFavoriteSendersFolderValidation.EnsureIsValid.  Validation is done.");
            return(true);
        }
Example #8
0
        public bool IsPopulated()
        {
            this.CheckDisposed("IsPopulated");
            ExTraceGlobals.StorageTracer.Information((long)this.GetHashCode(), "SearchFolder::IsPopulated.");
            SearchFolderCriteria searchCriteria = this.GetSearchCriteria();

            return((searchCriteria.SearchState & SearchState.Rebuild) != SearchState.Rebuild);
        }
Example #9
0
        public void ApplyOneTimeSearch(SearchFolderCriteria searchFolderCriteria)
        {
            this.CheckDisposed("ApplyOneTimeSearch");
            ExTraceGlobals.StorageTracer.Information <SearchFolderCriteria>((long)this.GetHashCode(), "SearchFolder::ApplyOneTimeSearch. SearchCriteria = {0}", searchFolderCriteria);
            SetSearchCriteriaFlags setSearchCriteriaFlags;

            this.PreprocessSearch(searchFolderCriteria, SearchFolder.SearchType.RunOnce, out setSearchCriteriaFlags);
            base.CoreFolder.SetSearchCriteria(searchFolderCriteria, setSearchCriteriaFlags);
        }
Example #10
0
        private bool ValidateUMFaxFilter(DefaultFolderContext context, OutlookSearchFolder folder)
        {
            SearchFolderCriteria searchFolderCriteria = SearchFolderValidation.TryGetSearchCriteria(folder);

            if (searchFolderCriteria == null || !UMFaxValidation.GetUMFaxQueryFilter(context).Equals(searchFolderCriteria.SearchQuery))
            {
                folder.ApplyContinuousSearch(UMFaxValidation.CreateUMFaxSearchCriteria(context));
            }
            return(true);
        }
Example #11
0
        private bool ValidateUMVoiceMailFilter(DefaultFolderContext context, OutlookSearchFolder folder)
        {
            SearchFolderCriteria searchFolderCriteria = SearchFolderValidation.TryGetSearchCriteria(folder);

            if (searchFolderCriteria == null || !UMVoiceMailValidation.GetUMVoicemailQueryFilter(context).Equals(searchFolderCriteria.SearchQuery))
            {
                folder.ApplyContinuousSearch(UMVoiceMailValidation.CreateUMVoiceMailSearchCriteria(context));
                folder.MakeVisibleToOutlook(true);
            }
            return(true);
        }
Example #12
0
        private static bool VerifyAndFixSearchFolder(DefaultFolderContext context, SearchFolder folder)
        {
            SearchFolderCriteria searchFolderCriteria  = SearchFolderValidation.TryGetSearchCriteria(folder);
            SearchFolderCriteria searchFolderCriteria2 = AllItemsFolderValidation.CreateSearchCriteria(context);

            if (searchFolderCriteria == null || !SearchFolderValidation.MatchSearchFolderCriteria(searchFolderCriteria, searchFolderCriteria2))
            {
                AllItemsFolderValidation.TryApplyContinuousSearch(folder, searchFolderCriteria2);
            }
            return(true);
        }
Example #13
0
        public IAsyncResult BeginApplyOneTimeSearch(SearchFolderCriteria searchFolderCriteria, AsyncCallback asyncCallback, object state)
        {
            this.CheckDisposed("BeginApplyOneTimeSearch");
            ExTraceGlobals.StorageTracer.Information <SearchFolderCriteria>((long)this.GetHashCode(), "SearchFolder::BeginApplyOneTimeSearch. SearchCriteria = {0}", searchFolderCriteria);
            SetSearchCriteriaFlags setSearchCriteriaFlags;

            this.PreprocessSearch(searchFolderCriteria, SearchFolder.SearchType.RunOnce, out setSearchCriteriaFlags);
            this.asyncSearch = new SearchFolderAsyncSearch(base.Session, base.Id.ObjectId, asyncCallback, state);
            base.CoreFolder.SetSearchCriteria(searchFolderCriteria, setSearchCriteriaFlags);
            return(this.asyncSearch.AsyncResult);
        }
Example #14
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 #15
0
        private static QueryFilter[] GetO12RemindersSearchFolderExclusionList(SearchFolderCriteria currentCriteria)
        {
            AndFilter andFilter  = currentCriteria.SearchQuery as AndFilter;
            AndFilter andFilter2 = (andFilter != null && andFilter.FilterCount > 0) ? (andFilter.Filters[0] as AndFilter) : null;

            if (andFilter2 != null)
            {
                QueryFilter[] array = new QueryFilter[andFilter2.FilterCount];
                andFilter2.Filters.CopyTo(array, 0);
                return(array);
            }
            return(null);
        }
Example #16
0
 private static void TryApplyContinuousSearch(SearchFolder folder, SearchFolderCriteria criteria)
 {
     try
     {
         folder.ApplyContinuousSearch(criteria);
     }
     catch (QueryInProgressException)
     {
         SearchFolderCriteria searchFolderCriteria = SearchFolderValidation.TryGetSearchCriteria(folder);
         if (searchFolderCriteria == null || !SearchFolderValidation.MatchSearchFolderCriteria(criteria, searchFolderCriteria))
         {
             throw;
         }
     }
 }
        internal static SearchFolderCriteria TryGetSearchCriteria(SearchFolder folder)
        {
            SearchFolderCriteria result = null;

            try
            {
                result = folder.GetSearchCriteria();
            }
            catch (ObjectNotInitializedException)
            {
            }
            catch (CorruptDataException)
            {
            }
            return(result);
        }
Example #18
0
        internal override bool EnsureIsValid(DefaultFolderContext context, Folder folder)
        {
            if (!base.EnsureIsValid(context, folder) || !(folder is SearchFolder))
            {
                return(false);
            }
            SearchFolder         searchFolder         = (SearchFolder)folder;
            SearchFolderCriteria searchFolderCriteria = CalendarVersionStoreValidation.CreateCalendarVersionSearchCriteria(context);
            SearchFolderCriteria searchCriteria       = searchFolder.GetSearchCriteria();

            if (!SearchFolderValidation.MatchSearchFolderCriteria(searchCriteria, searchFolderCriteria))
            {
                searchFolder.ApplyContinuousSearch(searchFolderCriteria);
            }
            return(true);
        }
Example #19
0
        private StoreObjectId[] GetFolderIdsFromSearchFolder(DefaultFolderType searchFolderId)
        {
            SearchFolderCriteria searchFolderCriteria = null;

            try
            {
                using (ISearchFolder searchFolder = this.xsoFactory.BindToSearchFolder(this.mailboxSession, searchFolderId))
                {
                    searchFolderCriteria = searchFolder.GetSearchCriteria();
                }
            }
            catch (ObjectNotInitializedException arg)
            {
                MyContactFolders.Tracer.TraceError <DefaultFolderType, ObjectNotInitializedException>((long)this.GetHashCode(), "Unable to load folder ids from the search folder {0} due ObjectNotInitializedException: {1}", searchFolderId, arg);
                return(null);
            }
            catch (ObjectNotFoundException arg2)
            {
                MyContactFolders.Tracer.TraceError <DefaultFolderType, ObjectNotFoundException>((long)this.GetHashCode(), "Unable to load folder ids from the search folder {0} due ObjectNotFoundException: {1}", searchFolderId, arg2);
                return(null);
            }
            if (searchFolderCriteria == null)
            {
                MyContactFolders.Tracer.TraceError <DefaultFolderType>((long)this.GetHashCode(), "There is no search folder criteria in the search folder {0}", searchFolderId);
                return(null);
            }
            if (searchFolderCriteria.FolderScope == null)
            {
                MyContactFolders.Tracer.TraceError <DefaultFolderType>((long)this.GetHashCode(), "There is no folder scope in the search folder {0}", searchFolderId);
                return(null);
            }
            if (searchFolderCriteria.FolderScope.Length == 0)
            {
                MyContactFolders.Tracer.TraceError <DefaultFolderType>((long)this.GetHashCode(), "The folder scope in the search folder {0} is empty", searchFolderId);
                return(null);
            }
            StoreObjectId[] array = new StoreObjectId[searchFolderCriteria.FolderScope.Length];
            for (int i = 0; i < searchFolderCriteria.FolderScope.Length; i++)
            {
                array[i] = (StoreObjectId)searchFolderCriteria.FolderScope[i];
            }
            MyContactFolders.Tracer.TraceDebug <DefaultFolderType, ArrayTracer <StoreObjectId> >((long)this.GetHashCode(), "Loaded folder ids from the scope of search folder {0}: {1}", searchFolderId, new ArrayTracer <StoreObjectId>(array));
            return(array);
        }
Example #20
0
        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);
        }
Example #21
0
        private void PreprocessSearch(SearchFolderCriteria searchFolderCriteria, SearchFolder.SearchType searchType, out SetSearchCriteriaFlags searchCriteriaFlags)
        {
            if (searchFolderCriteria == null)
            {
                throw new ArgumentNullException("searchFolderCriteria");
            }
            if (this.IsDirty)
            {
                throw new InvalidOperationException(ServerStrings.ExMustSaveFolderToApplySearch);
            }
            this.DisposeCurrentSearch();
            SetSearchCriteriaFlags setSearchCriteriaFlags = SetSearchCriteriaFlags.None;

            if (searchFolderCriteria.StatisticsOnly)
            {
                setSearchCriteriaFlags |= SetSearchCriteriaFlags.StatisticsOnly;
            }
            if (searchFolderCriteria.EstimateCountOnly)
            {
                setSearchCriteriaFlags |= SetSearchCriteriaFlags.EstimateCountOnly;
            }
            searchCriteriaFlags = SearchFolder.CalculateSearchCriteriaFlags(searchFolderCriteria.DeepTraversal, searchFolderCriteria.UseCiForComplexQueries, setSearchCriteriaFlags, searchFolderCriteria.FailNonContentIndexedSearch, searchType);
        }
Example #22
0
        private static RemindersSearchFolderValidation.RemindersSearchFolderState GetRemindersSearchFolderState(DefaultFolderContext context, SearchFolder reminders)
        {
            SearchFolderCriteria searchFolderCriteria = SearchFolderValidation.TryGetSearchCriteria(reminders);

            if (searchFolderCriteria == null)
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug(-1L, "RemindersSearchFolderValidation::GetRemindersSearchFolderState. currentCriteria is null.");
                return(new RemindersSearchFolderValidation.RemindersSearchFolderState(RemindersSearchFolderValidation.RemindersSearchFolderVersion.NotSet, false));
            }
            if (RemindersSearchFolderValidation.IsReminderSearchFolderForO11(context, searchFolderCriteria))
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <SearchFolderCriteria>(-1L, "RemindersSearchFolderValidation::GetRemindersSearchFolderState. currentCriteria is O11. current = {0}.", searchFolderCriteria);
                return(new RemindersSearchFolderValidation.RemindersSearchFolderState(RemindersSearchFolderValidation.RemindersSearchFolderVersion.O11, false));
            }
            bool isUpToDate;

            if (RemindersSearchFolderValidation.IsReminderSearchFolderForO12(context, searchFolderCriteria, out isUpToDate))
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <SearchFolderCriteria>(-1L, "DefaultFolderManager::GetRemindersSearchFolderState. currentCriteria is O12. current = {0}.", searchFolderCriteria);
                return(new RemindersSearchFolderValidation.RemindersSearchFolderState(RemindersSearchFolderValidation.RemindersSearchFolderVersion.O12, isUpToDate));
            }
            ExTraceGlobals.DefaultFoldersTracer.Information <string>(-1L, "Reminders search folder has an unknown criteria; probably from a newer client: {0}", searchFolderCriteria.SearchQuery.ToString());
            return(new RemindersSearchFolderValidation.RemindersSearchFolderState(RemindersSearchFolderValidation.RemindersSearchFolderVersion.Unknown, true));
        }
Example #23
0
        public static StoreObjectId Recreate(MailboxSession session, Guid searchFolderClsId)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (searchFolderClsId == Guid.Empty)
            {
                throw new ArgumentException("Guid is empty", "searchFolderClsId");
            }
            using (Folder folder = Folder.Bind(session, DefaultFolderType.SearchFolders))
            {
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[]
                {
                    InternalSchema.OutlookSearchFolderClsId
                }))
                {
                    for (;;)
                    {
                        object[][] rows = queryResult.GetRows(10000);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (rows[i][0] is Guid && ((Guid)rows[i][0]).Equals(searchFolderClsId))
                            {
                                goto Block_9;
                            }
                        }
                        if (rows.Length <= 0)
                        {
                            goto Block_11;
                        }
                    }
Block_9:
                    throw new ObjectExistedException(ServerStrings.ExSearchFolderAlreadyExists(searchFolderClsId));
                    Block_11 :;
                }
            }
            VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(session, searchFolderClsId);

            if (versionedId == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ExSearchFolderNoAssociatedItem(searchFolderClsId));
            }
            StoreObjectId objectId;

            using (MessageItem messageItem = MessageItem.Bind(session, versionedId))
            {
                bool                 deepTraversal;
                StoreId[]            folderScope;
                Restriction          restriction          = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out deepTraversal, out folderScope);
                QueryFilter          searchQuery          = FilterRestrictionConverter.CreateFilter(session, session.Mailbox.MapiStore, restriction, true);
                SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(searchQuery, folderScope);
                searchFolderCriteria.DeepTraversal = deepTraversal;
                string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.DisplayName, string.Empty);
                using (OutlookSearchFolder outlookSearchFolder = OutlookSearchFolder.Create(session, valueOrDefault))
                {
                    outlookSearchFolder[InternalSchema.OutlookSearchFolderClsId] = searchFolderClsId;
                    FolderSaveResult folderSaveResult = outlookSearchFolder.Save();
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));
                    }
                    outlookSearchFolder.Load(null);
                    outlookSearchFolder.ApplyContinuousSearch(searchFolderCriteria);
                    objectId = outlookSearchFolder.Id.ObjectId;
                }
            }
            return(objectId);
        }
Example #24
0
        private static bool IsSearchFolderPopulated(ISearchFolder folder)
        {
            SearchFolderCriteria searchCriteria = folder.GetSearchCriteria();

            return((searchCriteria.SearchState & SearchState.Rebuild) != SearchState.Rebuild);
        }
Example #25
0
 private static void ApplySearchFolderCriteria(IXSOFactory xsoFactory, IMailboxSession mailboxSession, ISearchFolder searchFolder, SearchFolderCriteria searchFolderCriteria, Action <SearchFolderCriteria> applySearchCriteriaAction)
 {
     ArgumentValidator.ThrowIfNull("xsoFactory", xsoFactory);
     ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession);
     ArgumentValidator.ThrowIfNull("searchFolder", searchFolder);
     ArgumentValidator.ThrowIfNull("searchFolderCriteria", searchFolderCriteria);
     ContactsSearchFolderCriteria.Tracer.TraceDebug <SearchFolderCriteria>((long)mailboxSession.GetHashCode(), "Applying search folder criteria: {0}", searchFolderCriteria);
     try
     {
         applySearchCriteriaAction(searchFolderCriteria);
     }
     catch (ObjectNotFoundException)
     {
         List <StoreObjectId> list = new List <StoreObjectId>(searchFolderCriteria.FolderScope.Length);
         foreach (StoreId storeId in searchFolderCriteria.FolderScope)
         {
             list.Add((StoreObjectId)storeId);
         }
         searchFolderCriteria.FolderScope = ContactsSearchFolderCriteria.RemoveDeletedFoldersFromCollection(xsoFactory, mailboxSession, list);
         applySearchCriteriaAction(searchFolderCriteria);
     }
 }
Example #26
0
        private void WriteOutlookSearchFolderDefinitionBlob(MessageItem message, SearchFolderCriteria criteria)
        {
            Restriction restriction = FilterRestrictionConverter.CreateRestriction(base.Session, base.PropertyBag.ExTimeZone, base.MapiProp, criteria.SearchQuery);

            OutlookSearchFolder.WriteOutlookSearchFolderDefinitionBlob(message, restriction, criteria.DeepTraversal, criteria.FolderScope);
        }
Example #27
0
        private void CreateOrHijackAssociatedMessage(VersionedId associatedMessageId, SearchFolderCriteria criteria)
        {
            MailboxSession mailboxSession = (MailboxSession)base.Session;
            MessageItem    messageItem    = null;

            try
            {
                if (associatedMessageId == null)
                {
                    messageItem = MessageItem.CreateAssociated(base.Session, mailboxSession.SafeGetDefaultFolderId(DefaultFolderType.CommonViews));
                }
                else
                {
                    messageItem = MessageItem.Bind(base.Session, associatedMessageId);
                }
                messageItem[InternalSchema.ItemClass] = "IPM.Microsoft.WunderBar.SFInfo";
                messageItem[InternalSchema.AssociatedSearchFolderId] = ((Guid)this[InternalSchema.OutlookSearchFolderClsId]).ToByteArray();
                messageItem[InternalSchema.DisplayName] = this[FolderSchema.DisplayName];
                messageItem[ItemSchema.Subject]         = this[FolderSchema.DisplayName];
                ExtendedFolderFlags?valueAsNullable = base.GetValueAsNullable <ExtendedFolderFlags>(FolderSchema.ExtendedFolderFlags);
                if (valueAsNullable != null)
                {
                    messageItem[InternalSchema.AssociatedSearchFolderFlags] = valueAsNullable.Value;
                }
                int num = OutlookSearchFolder.ConvertUtcDateTimeToRTime(ExDateTime.UtcNow);
                messageItem[InternalSchema.AssociatedSearchFolderLastUsedTime] = num;
                messageItem[InternalSchema.AssociatedSearchFolderExpiration]   = num;
                messageItem[InternalSchema.AssociatedSearchFolderTemplateId]   = 1;
                messageItem[InternalSchema.AssociatedSearchFolderTag]          = 0;
                this.WriteOutlookSearchFolderDefinitionBlob(messageItem, criteria);
                messageItem[InternalSchema.AssociatedSearchFolderStorageType] = 72;
                messageItem.Save(SaveMode.FailOnAnyConflict);
            }
            finally
            {
                if (messageItem != null)
                {
                    messageItem.Dispose();
                    messageItem = null;
                }
            }
        }
Example #28
0
        private static bool EnsureSearchIsCompleted(SearchFolder searchFolder, MailboxSession mailboxSession, OwaSearchContext searchContext)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::EnsureSearchIsCompleted] Start. search folder: {0}", searchContext.ClientSearchFolderIdentity);
            Subscription subscription    = null;
            bool         searchCompleted = false;
            SearchState  searchState     = SearchState.Error;
            bool         result;

            try
            {
                SearchFolderCriteria searchCriteria = searchFolder.GetSearchCriteria();
                if (searchCriteria != null)
                {
                    searchState = searchCriteria.SearchState;
                }
                if ((searchState & SearchState.Rebuild) == SearchState.Rebuild)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::EnsureSearchIsCompleted] SearchState.Rebuild == true. search folder: {0}", searchContext.ClientSearchFolderIdentity);
                    ManualResetEvent completedEvent = new ManualResetEvent(false);
                    subscription = Subscription.Create(mailboxSession, delegate(Notification notification)
                    {
                        if ((notification.Type & NotificationType.SearchComplete) == NotificationType.SearchComplete)
                        {
                            searchCompleted = true;
                            completedEvent.Set();
                        }
                    }, NotificationType.SearchComplete, searchFolder.StoreObjectId);
                    completedEvent.WaitOne(searchContext.SearchTimeoutInMilliseconds);
                    if (!searchCompleted)
                    {
                        searchCompleted = true;
                        searchContext.ViewFilterActions |= ViewFilterActions.PopulateSearchFolderTimedOut;
                        ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::EnsureSearchIsCompleted] Search timed out for search folder: {0}", searchContext.ClientSearchFolderIdentity);
                    }
                }
                else
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <SearchState, string, string>(0L, "[OwaFilterState::EnsureSearchIsCompleted] SearchFolder not rebuilding. searchState: {0}. searchCriteria: {1} for search folder: {2}", searchState, searchCriteria.ToString(), searchContext.ClientSearchFolderIdentity);
                    searchCompleted = ((searchState & SearchState.Error) != SearchState.Error);
                }
                ExTraceGlobals.StorageTracer.TraceDebug <bool, string>(0L, "[OwaFilterState::EnsureSearchIsCompleted] Is searchCompleted is: {0} for search folder: {1}", searchCompleted, searchContext.ClientSearchFolderIdentity);
                searchContext.ViewFilterActions |= ViewFilterActions.SearchCompleted;
                result = searchCompleted;
            }
            catch (ObjectNotInitializedException)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.ObjectNotInitializedException;
                string message = string.Format("[OwaFilterState::EnsureSearchIsCompleted] ObjectNotInitializedException thrown, searchCompleted is false for search folder: {0}. ViewFilterActions: {1}", searchContext.ClientSearchFolderIdentity, (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, message);
                result = false;
            }
            catch (CorruptDataException ex)
            {
                searchContext.ViewFilterActions |= ViewFilterActions.CorruptDataException;
                string text = string.Format("[OwaFilterState::EnsureSearchIsCompleted] CorruptDataException thrown, searchCompleted is false for search folder: {0}. Exception: {1}. ViewFilterActions: {2}", searchContext.ClientSearchFolderIdentity, ex.ToString(), (int)searchContext.ViewFilterActions);
                ExTraceGlobals.StorageTracer.TraceError(0L, text);
                OwaFilterState.SendWatsonWithoutDump(ex, text);
                result = false;
            }
            finally
            {
                if (subscription != null)
                {
                    subscription.Dispose();
                    subscription = null;
                }
            }
            return(result);
        }
Example #29
0
        public static SearchFolder CreateOrOpenOwaFilteredViewSearchFolder(MailboxSession mailboxSession, OwaSearchContext searchContext, StoreId searchFoldersRootId, SearchFolderCriteria searchFolderCriteria, bool flushStaleFolders = true)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <OwaViewFilter>(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] Create or open the specified filtered view: {0}", searchContext.ViewFilter);
            SearchFolder searchFolder = null;
            bool         flag         = true;

            searchContext.ViewFilterActions = ViewFilterActions.None;
            try
            {
                searchContext.ClientSearchFolderIdentity = OwaFilterState.GetOwaFilteredViewSearchFolderName(mailboxSession, searchContext);
                if (searchContext.SearchFolderId == null && OwaFilterState.FilterToLinkPropertyDefinitionsMap.ContainsKey(searchContext.ViewFilter))
                {
                    StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox);
                    if (defaultFolderId.Equals(searchContext.FolderIdToSearch))
                    {
                        searchContext.SearchFolderId = OwaFilterState.GetLinkedFolderIdForFilteredView(mailboxSession, searchContext.FolderIdToSearch, searchContext.ViewFilter);
                    }
                }
                if (searchContext.SearchFolderId != null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.BindToExisting;
                    searchFolder = OwaFilterState.BindAndUpdateExistingFilteredViewSearchFolder(mailboxSession, searchContext);
                }
                if (searchFolder == null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.FindExisting;
                    searchFolder = OwaFilterState.GetFilteredView(mailboxSession, searchContext, searchFoldersRootId, flushStaleFolders);
                }
                if (searchContext.IsSearchFailed && searchFolder != null)
                {
                    ExTraceGlobals.StorageTracer.TraceError <string, StoreId>(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] deleting search folder: {0} using searchContext.SearchFolderId: {1}", searchContext.ClientSearchFolderIdentity, searchContext.SearchFolderId);
                    searchContext.ViewFilterActions |= ViewFilterActions.DeleteInvalidSearchFolder;
                    mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                    {
                        searchContext.SearchFolderId
                    });
                    searchContext.SearchFolderId = null;
                    searchContext.IsSearchFailed = false;
                    searchFolder.Dispose();
                    searchFolder = null;
                }
                if (searchFolder == null)
                {
                    searchContext.ViewFilterActions |= ViewFilterActions.CreateFilter;
                    searchFolder = OwaFilterState.CreateAndUpdateFilteredViewSearchFolder(mailboxSession, searchContext, searchFoldersRootId, searchFolderCriteria);
                }
                ExTraceGlobals.StorageTracer.TraceDebug(0L, string.Format("{0}_{1}", searchContext.ClientSearchFolderIdentity, (int)searchContext.ViewFilterActions));
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "[OwaFilterState::CreateOrOpenOwaFilteredViewSearchFolder] Creating/Opening of dynamic search folder failed. Setting search folder to null and disposing it");
                    if (searchFolder != null)
                    {
                        searchFolder.Dispose();
                        searchFolder = null;
                    }
                }
            }
            return(searchFolder);
        }
Example #30
0
        private static SearchFolder CreateAndUpdateFilteredViewSearchFolder(MailboxSession mailboxSession, OwaSearchContext searchContext, StoreId searchFoldersRootId, SearchFolderCriteria searchFolderCriteria)
        {
            ExTraceGlobals.StorageTracer.TraceDebug <string, string>(0L, "[OwaFilterState::CreateAndUpdateFilteredViewSearchFolder] Create filtered view search folder for view filter: {0} search folder identity: {1} ", searchContext.ViewFilter.ToString(), searchContext.ClientSearchFolderIdentity);
            SearchFolder searchFolder = SearchFolder.Create(mailboxSession, searchFoldersRootId, searchContext.ClientSearchFolderIdentity, CreateMode.OpenIfExists);

            OwaFilterState.UpdateFilteredViewSearchFolder(mailboxSession, searchFolder, searchContext);
            searchContext.SearchFolderId = searchFolder.StoreObjectId;
            searchContext.IsSearchFailed = !OwaFilterState.ApplyOwaContinuousSearch(searchFolder, searchFolderCriteria, mailboxSession, searchContext);
            if (searchContext.IsSearchFailed)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "[OwaFilterState::CreateAndUpdateFilteredViewSearchFolder] deleting searchContext.SearchFolderId: " + searchContext.SearchFolderId);
                searchContext.ViewFilterActions |= ViewFilterActions.DeleteInvalidSearchFolder;
                mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                {
                    searchContext.SearchFolderId
                });
                searchFolder.Dispose();
                searchFolder = null;
            }
            else if (OwaFilterState.LinkViewFolder(mailboxSession, searchContext.FolderIdToSearch, searchFolder, searchContext.ViewFilter))
            {
                searchContext.ViewFilterActions |= ViewFilterActions.LinkToSourceFolderSucceeded;
            }
            return(searchFolder);
        }