internal override void InternalProcessRecord() { base.InternalProcessRecord(); if (base.Task.MonitoringContext && !this.IsFirstActiveMdbLocallyMounted()) { base.AddInformationMonitoringEvent(2004, Strings.CrossPremiseServerNotSelected(base.SourceMailboxServer.Name)); return; } List <SmtpAddress> siteEgressTargets = this.GetSiteEgressTargets(); if (siteEgressTargets.Count <SmtpAddress>() == 0) { base.AddWarningMonitoringEvent(2003, Strings.CrossPremiseNoEgressTargets(base.SourceMailboxServer.Name)); base.Task.WriteWarning(Strings.CrossPremiseNoEgressTargets(base.SourceMailboxServer.Name)); return; } ADSystemMailbox adsystemMailbox = this.localSystemMailbox as ADSystemMailbox; using (MapiStore mapiStore = MapiStore.OpenMailbox(base.SourceMailboxServer.Fqdn, this.localSystemMailbox.LegacyExchangeDN, adsystemMailbox.ExchangeGuid, adsystemMailbox.Database.ObjectGuid, this.localSystemMailbox.Name, null, null, ConnectFlag.UseAdminPrivilege | ConnectFlag.UseSeparateConnection, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=Management;Action=CrossPremiseTestMailFlow", null)) { using (MapiFolder rootFolder = mapiStore.GetRootFolder()) { using (MapiFolder inboxFolder = mapiStore.GetInboxFolder()) { using (MapiFolder mapiFolder = rootFolder.CreateFolder("Cross Premise", "The folder for cross premise mailflow monitoring.", true)) { if (base.Task.MonitoringContext) { this.MatchCrossPremiseMessages(inboxFolder, mapiFolder, this.localSystemMailbox.WindowsEmailAddress, siteEgressTargets); using (List <SmtpAddress> .Enumerator enumerator = siteEgressTargets.GetEnumerator()) { while (enumerator.MoveNext()) { SmtpAddress smtpAddress = enumerator.Current; string subject = string.Format("{0}{{{1}}}", "CrossPremiseMailFlowMonitoring-", Guid.NewGuid()); TestMailFlowHelper.CreateAndSubmitMessage(mapiFolder, this.localSystemMailbox.Name, smtpAddress.ToString(), subject, false); } goto IL_238; } } Dictionary <string, string> dictionary = new Dictionary <string, string>(); ExDateTime utcNow = ExDateTime.UtcNow; foreach (SmtpAddress smtpAddress2 in siteEgressTargets) { string text = string.Format("{0}{{{1}}}", "CrossPremiseMailFlowMonitoring-", Guid.NewGuid()); TestMailFlowHelper.CreateAndSubmitMessage(mapiFolder, this.localSystemMailbox.Name, smtpAddress2.ToString(), text, true); dictionary[text] = smtpAddress2.ToString(); } this.WaitAndProcessProbeResponses(inboxFolder, this.localSystemMailbox.Name, dictionary, utcNow); IL_238 :; } } } } }
public StoreId CreateFolder(string folderName, string folderDescription, StoreId parentFolderId, CreateMode mode, out Guid contentMailboxGuid) { StoreId result; 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))) { using (MapiFolder mapiFolder2 = mapiFolder.CreateFolder(folderName, folderDescription, mode == CreateMode.OpenIfExists)) { contentMailboxGuid = RPCPrimaryHierarchyProvider.GetMailboxGuidFromPersonalizedLegacyDN(mapiFolder2.GetReplicaServers()[0]); result = StoreObjectId.FromProviderSpecificId(mapiFolder2.GetProp(PropTag.EntryId).GetBytes(), StoreObjectType.Folder); } } } } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex, storeSession, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(folderName), ex2, storeSession, thisObject, "{0}. MapiException = {1}.", new object[] { string.Format("RPCPrimaryHierarchyProvider.CreateFolder : folderName = {0}", folderName), ex2 }); } finally { try { if (storeSession != null) { storeSession.EndMapiCall(); if (flag) { storeSession.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } } return(result); }
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(); } } }