internal static StoreObjectId FindWorkingSetPartitionFolder(MailboxSession mailboxSession, string partitionName) { StoreObjectId result; using (Folder folder = WorkingSetUtils.SafeBindToWorkingSetFolder(mailboxSession)) { using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[] { FolderSchema.Id })) { queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.WorkingSetSourcePartitionInternal, partitionName)); object[][] rows = queryResult.GetRows(1); result = ((rows.Length > 0) ? ((VersionedId)rows[0][0]).ObjectId : null); } } return(result); }
public static void DeleteWorkingSetPartition(MailboxSession mailboxSession, string workingSetSourcePartitionInternal) { StoreObjectId storeObjectId = WorkingSetUtils.FindWorkingSetPartitionFolder(mailboxSession, workingSetSourcePartitionInternal); if (storeObjectId != null) { using (Folder folder = WorkingSetUtils.SafeBindToWorkingSetFolder(mailboxSession)) { AggregateOperationResult aggregateOperationResult = folder.DeleteObjects(DeleteItemFlags.HardDelete, new StoreId[] { storeObjectId }); if (aggregateOperationResult.OperationResult != OperationResult.Succeeded) { throw new ObjectNotFoundException(new LocalizedString(string.Format("Delete partition failed, partition {0} is not found", workingSetSourcePartitionInternal))); } WorkingSet.PartitionsDeleted.Increment(); return; } } throw new ObjectNotFoundException(new LocalizedString(string.Format("Delete partition failed, partition {0} is not found", workingSetSourcePartitionInternal))); }
internal static StoreObjectId GetWorkingSetPartitionFolderId(MailboxSession mailboxSession, string workingSetSourcePartition, string workingSetSourcePartitionInternal) { StoreObjectId result; using (Folder folder = WorkingSetUtils.SafeBindToWorkingSetFolder(mailboxSession)) { StoreObjectId storeObjectId = WorkingSetUtils.FindWorkingSetPartitionFolder(mailboxSession, workingSetSourcePartitionInternal); if (storeObjectId == null) { using (Folder folder2 = Folder.Create(mailboxSession, folder.StoreObjectId, StoreObjectType.Folder, workingSetSourcePartition, CreateMode.CreateNew)) { folder2[FolderSchema.WorkingSetSourcePartitionInternal] = workingSetSourcePartitionInternal; folder2.Save(); folder2.Load(); storeObjectId = folder2.StoreObjectId; WorkingSet.PartitionsCreated.Increment(); } } result = storeObjectId; } return(result); }