internal override void Delete() { if (ObjectState.Deleted == base.ObjectState) { throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString())); } if (base.ObjectState == ObjectState.New) { base.MarkAsDeleted(); return; } Folder.CheckRequirementsToContinue(this.Identity, base.MapiSession); ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Delete Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); base.EnableDisposeTracking(); using (MapiStore messageStore = this.GetMessageStore()) { using (MapiFolder mapiFolder = this.GetMapiFolder(messageStore)) { try { this.DetectDisallowedModification(messageStore); bool flag = false; this.TryTestHasSubFolders(mapiFolder, out flag); try { using (MapiFolder parentFolder = this.GetParentFolder(messageStore)) { parentFolder.DeleteFolder((byte[])this.Identity.MapiEntryId); } } catch (MapiExceptionPartialCompletion innerException) { if (flag) { throw new MapiPartialCompletionException(Strings.ErrorRemovalPartialCompleted(this.Identity.ToString()), innerException); } throw; } } finally { base.Dispose(); } } } base.ResetChangeTracking(); base.MarkAsDeleted(); }
public void DeleteFolder(StoreId parentFolderId, StoreId folderId, DeleteFolderFlags deleteFlags) { using (PublicFolderConnectionLimitsTracker.Instance.GetToken(this.PrimaryHierarchyMailboxPrincipal.MailboxInfo.Location.ServerFqdn)) { StoreSession storeSession = null; object thisObject = null; bool flag = false; try { if (storeSession != null) { storeSession.BeginMapiCall(); storeSession.BeginServerHealthCall(); flag = true; } if (StorageGlobals.MapiTestHookBeforeCall != null) { StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod()); } using (MapiStore hierarchyStore = this.GetHierarchyStore()) { using (MapiFolder mapiFolder = (MapiFolder)hierarchyStore.OpenEntry(this.GetDestinationSpecificEntryId(hierarchyStore, parentFolderId))) { mapiFolder.DeleteFolder(this.GetDestinationSpecificEntryId(hierarchyStore, folderId), deleteFlags); } } } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyMessagesFailed, ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("RPCPrimaryHierarchyProvider.DeleteFolder : folderId = {0}", folderId), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCopyMessagesFailed, ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("RPCPrimaryHierarchyProvider.DeleteFolder : folderId = {0}", folderId), ex2 }); } finally { try { if (storeSession != null) { storeSession.EndMapiCall(); if (flag) { storeSession.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } } }
internal override void Save(bool keepUnmanagedResources) { if (ObjectState.Unchanged == base.ObjectState) { return; } if (ObjectState.Deleted == base.ObjectState) { throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString())); } base.EnableDisposeTracking(); using (MapiStore messageStore = this.GetMessageStore()) { MapiFolder mapiFolder = null; MapiFolder parentFolder = null; bool isFolderRetrieved = false; try { MapiSession mapiSession = base.MapiSession; Folder.CheckRequirementsOnSessionToContinue(base.MapiSession); bool creating = false; if (base.ObjectState == ObjectState.New) { creating = true; string text = null; if (this.newFolderIdentity == null) { if (null == this.Identity) { throw new MapiInvalidOperationException(Strings.ExceptionIdentityNull); } if (null == this.Identity.MapiFolderPath) { throw new MapiInvalidOperationException(Strings.ExceptionIdentityInvalid); } MapiFolder mapiFolder2 = null; try { parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder2); } finally { if (mapiFolder2 != null) { mapiFolder2.Dispose(); } } if (parentFolder != null && !parentFolder.AllowWarnings) { parentFolder.AllowWarnings = true; } text = this.Identity.MapiFolderPath.Name; } else { this.Identity = this.ConstructIdentity(null, MapiFolderPath.GenerateFolderPath(this.newFolderIdentity.ParentIdentity.MapiFolderPath, this.newFolderIdentity.FolderName, false), null); parentFolder = Folder.RetrieveMapiFolder(messageStore, this.newFolderIdentity.ParentIdentity); if (parentFolder != null && !parentFolder.AllowWarnings) { parentFolder.AllowWarnings = true; } text = this.newFolderIdentity.FolderName; } ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Create Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); try { mapiFolder = parentFolder.CreateFolder(text, string.Empty, false); if (mapiFolder != null && !mapiFolder.AllowWarnings) { mapiFolder.AllowWarnings = true; } isFolderRetrieved = true; } catch (MapiExceptionCollision innerException) { this.DetectFolderExistence(messageStore, parentFolder, text, innerException); throw; } this.UpdateIdentity(this.UpdateIdentityFlagsForCreating); } if (creating || ObjectState.Changed == base.ObjectState) { Folder.CheckRequirementsOnIdentityToContinue(this.Identity); this.DetectDisallowedModification(messageStore); if (ObjectState.Changed == base.ObjectState && base.IsChanged(MapiPropertyDefinitions.Name)) { string name = (string)this[MapiPropertyDefinitions.Name]; if (parentFolder == null) { MapiFolder mapiFolder3 = null; try { parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder3); } finally { if (mapiFolder3 != null) { mapiFolder3.Dispose(); } } } this.DetectFolderExistence(messageStore, parentFolder, name, null); } PropProblem[] array = null; PropProblem[] array2 = null; FolderId folderId = null; if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } mapiFolder = Folder.RetrieveMapiFolder(messageStore, this.Identity, ref parentFolder, new Folder.IdentityConstructor(this.ConstructIdentity), out folderId); ParameterlessReturnlessDelegate parameterlessReturnlessDelegate = delegate() { if (creating && isFolderRetrieved) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Remove Folder '{0}' for rolling back creating on server '{1}'.", this.Identity, this.MapiSession.ServerName); try { parentFolder.DeleteFolder((byte[])this.Identity.MapiEntryId); } catch (MapiRetryableException ex) { ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex.Message); } catch (MapiPermanentException ex2) { ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex2.Message); } } }; try { PropValue[] propertyValuesToUpdate = base.GetPropertyValuesToUpdate(); if (0 < propertyValuesToUpdate.Length) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Set PropValues against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); array = mapiFolder.SetProps(propertyValuesToUpdate); } PropTag[] propertyTagsToDelete = base.GetPropertyTagsToDelete(); if (0 < propertyTagsToDelete.Length) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Delete PropTags against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); array2 = mapiFolder.DeleteProps(propertyTagsToDelete); } } catch (DataValidationException) { parameterlessReturnlessDelegate(); throw; } catch (MapiRetryableException) { parameterlessReturnlessDelegate(); throw; } catch (MapiPermanentException) { parameterlessReturnlessDelegate(); throw; } base.ResetChangeTrackingAndObjectState(); StringBuilder stringBuilder = new StringBuilder(); if (array != null && 0 < array.Length) { stringBuilder.AppendLine(Strings.ErrorSetPropsProblem(this.Identity.ToString(), array.Length.ToString())); foreach (PropProblem propProblem in array) { stringBuilder.Append('\t'); stringBuilder.AppendLine(Strings.ErrorPropProblem(propProblem.PropTag.ToString(), propProblem.PropType.ToString(), propProblem.Scode.ToString())); } stringBuilder.AppendLine(); } if (array2 != null && 0 < array2.Length) { stringBuilder.AppendLine(Strings.ErrorDeletePropsProblem(this.Identity.ToString(), array2.Length.ToString())); foreach (PropProblem propProblem2 in array2) { stringBuilder.Append('\t'); stringBuilder.Append(Strings.ErrorPropProblem(propProblem2.PropTag.ToString(), propProblem2.PropType.ToString(), propProblem2.Scode.ToString())); stringBuilder.AppendLine(); } stringBuilder.AppendLine(); } if (0 < stringBuilder.Length) { string text2 = stringBuilder.ToString(); ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string, string>((long)this.GetHashCode(), "Setting Folder '{0}' on server '{1}' returns error '{2}'.", this.Identity, base.MapiSession.ServerName, text2); parameterlessReturnlessDelegate(); throw new MapiInvalidOperationException(new LocalizedString(text2)); } } } finally { if (mapiFolder != null) { mapiFolder.Dispose(); } if (parentFolder != null) { parentFolder.Dispose(); } base.Dispose(); } } }