protected void RemoveSystemMailbox() { TDataObject dataObject = base.DataObject; ADObjectId adobjectId = ((ADObjectId)dataObject.Identity).DomainId; adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects"); adobjectId = adobjectId.GetChildId("SystemMailbox" + dataObject.Guid.ToString("B")); try { string identity = adobjectId.ToDNString(); GeneralMailboxIdParameter generalMailboxIdParameter = GeneralMailboxIdParameter.Parse(identity); base.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(generalMailboxIdParameter, this.RecipientSessionForSystemMailbox, typeof(ADRecipient), null)); IEnumerable <ADSystemMailbox> objects = generalMailboxIdParameter.GetObjects <ADSystemMailbox>(null, this.RecipientSessionForSystemMailbox); using (IEnumerator <ADSystemMailbox> enumerator = objects.GetEnumerator()) { if (enumerator.MoveNext()) { ADSystemMailbox adsystemMailbox = enumerator.Current; base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.RecipientSessionForSystemMailbox)); base.WriteVerbose(Strings.VerboseDeleteSystemAttendantObject(adsystemMailbox.Identity.ToString())); this.RecipientSessionForSystemMailbox.Delete(adsystemMailbox); } } } catch (DataSourceTransientException ex) { TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[] { dataObject.Identity.ToString(), ex.Message }); this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex.Message)); } catch (DataSourceOperationException ex2) { TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[] { dataObject.Identity.ToString(), ex2.Message }); this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex2.Message)); } catch (DataValidationException ex3) { TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' raises exception: {1}.", new object[] { dataObject.Identity.ToString(), ex3.Message }); this.WriteWarning(Strings.ErrorFailedToRemoveSystemMailbox(dataObject.Identity.ToString(), ex3.Message)); } finally { base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(this.RecipientSessionForSystemMailbox)); } TaskLogger.Trace("The action of Removing system mailbox object of database '{0}' succeeded.", new object[] { dataObject.Identity.ToString() }); }
protected ADSystemMailbox GetSystemMailboxFromMdb(MailboxDatabase mdb) { ADSystemMailbox adsystemMailbox = null; GeneralMailboxIdParameter id = GeneralMailboxIdParameter.Parse(string.Format(CultureInfo.InvariantCulture, "SystemMailbox{{{0}}}", new object[] { mdb.Guid.ToString() })); IEnumerable <ADSystemMailbox> adDataObjects = this.Task.GetAdDataObjects <ADSystemMailbox>(id, this.Task.TenantGlobalCatalogSession); using (IEnumerator <ADSystemMailbox> enumerator = adDataObjects.GetEnumerator()) { adsystemMailbox = (enumerator.MoveNext() ? enumerator.Current : null); } if (adsystemMailbox == null) { this.WriteErrorAndMonitoringEvent(new RecipientTaskException(Strings.TestMailflowNoSystemMailbox), ErrorCategory.InvalidOperation, 1005); } return(adsystemMailbox); }
protected override void InternalValidate() { bool flag = false; try { ADRecipient adrecipient = null; List <MailboxDatabase> list = new List <MailboxDatabase>(); bool flag2 = false; ActiveManager activeManagerInstance = ActiveManager.GetActiveManagerInstance(); base.TenantGlobalCatalogSession.ServerTimeout = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout)); this.ConfigurationSession.ServerTimeout = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout)); this.transactionTargets = new List <MapiTransaction>(); if (this.Identity != null) { if (this.EnableSoftDeletedRecipientLogon) { IDirectorySession directorySession = base.DataSession as IDirectorySession; directorySession.SessionSettings.IncludeSoftDeletedObjects = true; } ADUser aduser = (ADUser)RecipientTaskHelper.ResolveDataObject <ADUser>(base.DataSession, base.TenantGlobalCatalogSession, base.ServerSettings, this.Identity, null, base.OptionalIdentityData, base.DomainController, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADUser>), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError)); if (this.Archive) { if (aduser.ArchiveDatabase == null) { base.WriteError(new MdbAdminTaskException(Strings.ErrorArchiveNotEnabled(aduser.ToString())), ErrorCategory.InvalidArgument, this.Identity); } else { this.Database = new DatabaseIdParameter(aduser.ArchiveDatabase); } } else { this.Database = new DatabaseIdParameter(aduser.Database); } flag = true; adrecipient = aduser; } if (this.Database != null) { MailboxDatabase mailboxDatabase = null; MailboxDatabase mailboxDatabase2 = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(this.Database, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString()))); if (mailboxDatabase2.Recovery) { string name = mailboxDatabase2.Name; RecoveryMailboxDatabaseNotMonitoredException exception = new RecoveryMailboxDatabaseNotMonitoredException(name); this.WriteErrorAndMonitoringEvent(exception, ErrorCategory.InvalidOperation, null, 1006, "MSExchange Monitoring MAPIConnectivity"); return; } mailboxDatabase = mailboxDatabase2; if (!flag) { try { MapiTaskHelper.VerifyDatabaseAndItsOwningServerInScope(base.SessionSettings, mailboxDatabase, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError)); flag = true; } catch (InvalidOperationException exception2) { this.WriteErrorAndMonitoringEvent(exception2, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity"); return; } } list.Add(mailboxDatabase); if (this.CopyOnServer != null) { this.Server = this.CopyOnServer; } else { DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase.Guid); if (serverForDatabase != null) { this.Server = ServerIdParameter.Parse(serverForDatabase.ServerFqdn); } else { this.Server = ServerIdParameter.Parse(mailboxDatabase.Server.DistinguishedName); } } } if (this.Server == null) { string machineName = Environment.MachineName; this.Server = ServerIdParameter.Parse(machineName); } this.targetServer = (Server)base.GetDataObject <Server>(this.Server, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorServerNotFound(this.Server.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(this.Server.ToString()))); LocalizedException ex = null; if (!this.targetServer.IsExchange2007OrLater) { ex = new OperationOnOldServerException(this.targetServer.Name); } else if (!this.targetServer.IsMailboxServer) { ex = new OperationOnlyOnMailboxServerException(this.targetServer.Name); } if (ex != null) { this.WriteErrorAndMonitoringEvent(ex, ErrorCategory.InvalidArgument, null, 1005, "MSExchange Monitoring MAPIConnectivity"); } else { if (!flag) { try { MapiTaskHelper.VerifyIsWithinConfigWriteScope(base.SessionSettings, this.targetServer, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError)); } catch (InvalidOperationException exception3) { this.WriteErrorAndMonitoringEvent(exception3, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity"); return; } } if (list.Count == 0) { MailboxDatabase[] mailboxDatabases = this.targetServer.GetMailboxDatabases(); if (mailboxDatabases.Length > 0) { flag2 = true; } foreach (MailboxDatabase mailboxDatabase3 in mailboxDatabases) { if (!mailboxDatabase3.AutoDagExcludeFromMonitoring) { if (this.IncludePassive) { list.Add(mailboxDatabase3); } else { DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase3.Guid); if ((serverForDatabase != null && serverForDatabase.ServerGuid == this.targetServer.Guid) || (serverForDatabase == null && mailboxDatabase3.Server.ObjectGuid == this.targetServer.Guid)) { list.Add(mailboxDatabase3); } } } } } if (adrecipient != null) { this.wasTargetMailboxSpecified = true; this.transactionTargets.Add(new MapiTransaction(this.targetServer, list[0], adrecipient, this.Archive, list[0].Server.ObjectGuid == this.targetServer.Guid)); } else { foreach (MailboxDatabase mailboxDatabase4 in list) { if (!mailboxDatabase4.Recovery) { GeneralMailboxIdParameter id = GeneralMailboxIdParameter.Parse(string.Format(CultureInfo.InvariantCulture, "SystemMailbox{{{0}}}", new object[] { mailboxDatabase4.Guid.ToString() })); IEnumerable <ADSystemMailbox> dataObjects = base.GetDataObjects <ADSystemMailbox>(id, base.RootOrgGlobalCatalogSession, null); using (IEnumerator <ADSystemMailbox> enumerator2 = dataObjects.GetEnumerator()) { adrecipient = (enumerator2.MoveNext() ? enumerator2.Current : null); this.transactionTargets.Add(new MapiTransaction(this.targetServer, mailboxDatabase4, adrecipient, false, mailboxDatabase4.Server.ObjectGuid == this.targetServer.Guid)); } } } } this.transactionTargets.Sort(); if (this.transactionTargets.Count < 1) { if (flag2) { this.WriteWarning(Strings.MapiTransactionServerWithoutMdbs(this.targetServer.Name)); this.onlyPassives = true; } else { this.WriteErrorAndMonitoringEvent(new NoMdbForOperationException(this.targetServer.Name), ErrorCategory.ReadError, null, 1010, "MSExchange Monitoring MAPIConnectivity"); } } } } finally { if (base.HasErrors && this.MonitoringContext) { base.WriteObject(this.monitoringData); } TaskLogger.LogExit(); } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(new object[] { this.DataObject }); try { try { MailboxDatabase mailboxDatabase = this.ConfigurationSession.Read <MailboxDatabase>((ADObjectId)this.DataObject.Identity); Server server = null; ADComputer adcomputer = null; bool useConfigNC = this.ConfigurationSession.UseConfigNC; bool useGlobalCatalog = this.ConfigurationSession.UseGlobalCatalog; if (mailboxDatabase != null) { server = mailboxDatabase.GetServer(); try { this.ConfigurationSession.UseConfigNC = false; this.ConfigurationSession.UseGlobalCatalog = true; adcomputer = ((ITopologyConfigurationSession)this.ConfigurationSession).FindComputerByHostName(server.Name); } finally { this.ConfigurationSession.UseConfigNC = useConfigNC; this.ConfigurationSession.UseGlobalCatalog = useGlobalCatalog; } if (adcomputer == null) { base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorDBOwningServerNotFound(mailboxDatabase.Identity.ToString())), ErrorCategory.ObjectNotFound, server.Identity); } ADObjectId adobjectId = adcomputer.Id.DomainId; adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects"); adobjectId = adobjectId.GetChildId("SystemMailbox" + mailboxDatabase.Guid.ToString("B")); string identity = adobjectId.ToDNString(); GeneralMailboxIdParameter generalMailboxIdParameter = GeneralMailboxIdParameter.Parse(identity); base.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(generalMailboxIdParameter, this.RecipientSession, typeof(ADRecipient), null)); IEnumerable <ADSystemMailbox> objects = generalMailboxIdParameter.GetObjects <ADSystemMailbox>(adobjectId, this.RecipientSession); using (IEnumerator <ADSystemMailbox> enumerator = objects.GetEnumerator()) { if (enumerator.MoveNext()) { ADSystemMailbox adsystemMailbox = enumerator.Current; } else { NewMailboxDatabase.SaveSystemMailbox(mailboxDatabase, mailboxDatabase.GetServer(), base.RootOrgContainerId, (ITopologyConfigurationSession)this.ConfigurationSession, this.RecipientSession, null, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)); } } } base.WriteVerbose(Strings.VerboseMountDatabase(this.Identity.ToString())); this.RequestMount(MountFlags.None); if (!this.DataObject.DatabaseCreated) { this.DataObject.DatabaseCreated = true; base.InternalProcessRecord(); } } catch (AmServerException ex) { Exception ex2; if (ex.TryGetInnerExceptionOfType(out ex2)) { TaskLogger.Trace("Database already mounted (database={0}, exception={1})", new object[] { this.DataObject.Name, ex2.Message }); } else if (ex.TryGetInnerExceptionOfType(out ex2) || ex.TryGetInnerExceptionOfType(out ex2)) { this.AttemptForcedMountIfNecessary(this.Force, Strings.ContinueMountWhenDBFilesNotExist, Strings.VerboseMountDatabaseForcely(this.Identity.ToString()), Strings.ErrorFailedToMountReplicatedDbWithMissingEdbFile(this.Identity.ToString()), ex, MountFlags.ForceDatabaseCreation); } else if (ex.TryGetInnerExceptionOfType(out ex2)) { this.PromptForMountIfNecessary(this.AcceptDataLoss, Strings.ContinueMountWithDataLoss, Strings.VerboseMountDatabaseDataLoss(this.Identity.ToString()), MountFlags.AcceptDataLoss); } else { TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[] { ex.Message }); base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex.Message), ex), ErrorCategory.InvalidOperation, this.DataObject.Identity); } } } catch (AmServerException ex3) { TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[] { ex3.Message }); base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex3.Message), ex3), ErrorCategory.InvalidOperation, this.DataObject.Identity); } catch (AmServerTransientException ex4) { TaskLogger.Trace("MountDatabase.InternalProcessRecord raises exception while mounting database: {0}", new object[] { ex4.Message }); base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMountDatabase(this.Identity.ToString(), ex4.Message), ex4), ErrorCategory.InvalidOperation, this.DataObject.Identity); } finally { TaskLogger.LogExit(); } }