public static bool LinkViewFolder(MailboxSession session, StoreId folderId, SearchFolder viewFolder, OwaViewFilter filter) { bool flag = false; Exception ex = null; if (OwaFilterState.FilterToLinkPropertyDefinitionsMap.ContainsKey(filter)) { try { using (Folder folder = Folder.Bind(session, folderId)) { bool flag2 = true; StoreId linkedFolderIdForFilteredView = OwaFilterState.GetLinkedFolderIdForFilteredView(session, folderId, filter); if (linkedFolderIdForFilteredView != null && viewFolder.StoreObjectId.Equals(linkedFolderIdForFilteredView)) { flag2 = false; flag = true; } if (flag2) { folder.SafeSetProperty(OwaFilterState.FilterToLinkPropertyDefinitionsMap[filter], viewFolder.Id.ObjectId.ProviderLevelItemId); FolderSaveResult folderSaveResult = folder.Save(); if (folderSaveResult.OperationResult == OperationResult.Succeeded) { ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::LinkViewFolder] Search Folder Name = {0} linked to physical folder", viewFolder.DisplayName); flag = true; } else { ex = folderSaveResult.Exception; } } } } catch (ObjectNotFoundException ex2) { ex = ex2; } if (!flag) { string arg = (ex != null) ? ex.ToString() : "[OwaFilterState::LinkViewFolder] FolderSaveResult.OperationResult != OperationResult.Succeeded"; string message = string.Format("Linking the view folder ({0}) failed. Details= {1}", viewFolder.DisplayName, arg); ExTraceGlobals.StorageTracer.TraceError(0L, message); } } else { ExTraceGlobals.StorageTracer.TraceDebug <OwaViewFilter>(0L, "[OwaFilterState::LinkViewFolder] The specified OwaViewFilter {0} is not supported for linking to the source folder.", filter); } return(flag); }
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); }