protected override void InternalProcessRecord() { TaskLogger.LogEnter(new object[] { this.DataObject }); if (this.PublicFolder) { MailboxTaskHelper.RemoveOrDisablePublicFolderMailbox(this.DataObject, this.exchangeGuid, this.TenantLocalConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), true, false); } base.InternalProcessRecord(); if ("Archive" == base.ParameterSetName || "RemoteArchive" == base.ParameterSetName) { TaskLogger.Trace("DisableMailbox -Archive or -RemoteArchive skipping InternalProcessRecord", new object[0]); TaskLogger.LogExit(); return; } try { MailboxDatabase mailboxDatabase = null; if (this.mdbId != null) { mailboxDatabase = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(new DatabaseIdParameter(this.mdbId) { AllowLegacy = true }, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.mdbId.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.mdbId.ToString()))); } if (mailboxDatabase != null && this.exchangeGuid != Guid.Empty) { Server server = mailboxDatabase.GetServer(); if (server == null) { this.WriteWarning(Strings.ErrorDBOwningServerNotFound(mailboxDatabase.Identity.ToString())); } else if (string.IsNullOrEmpty(server.ExchangeLegacyDN)) { this.WriteWarning(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, server.Identity.ToString(), ServerSchema.ExchangeLegacyDN.Name)); } else if (string.IsNullOrEmpty(server.Fqdn)) { this.WriteWarning(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, server.Identity.ToString(), ServerSchema.Fqdn.Name)); } else { base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(server.Fqdn)); using (MapiAdministrationSession mapiAdministrationSession = new MapiAdministrationSession(server.ExchangeLegacyDN, Fqdn.Parse(server.Fqdn))) { base.WriteVerbose(Strings.VerboseSyncMailboxWithDS(this.Identity.ToString(), this.mdbId.ToString(), server.Fqdn)); mapiAdministrationSession.SyncMailboxWithDS(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(this.mdbId), this.exchangeGuid)); } } } } catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException ex) { TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[] { ex }); base.WriteVerbose(ex.LocalizedString); } catch (DataSourceTransientException ex2) { TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[] { ex2 }); this.WriteWarning(ex2.LocalizedString); } catch (DataSourceOperationException ex3) { TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[] { ex3 }); this.WriteWarning(ex3.LocalizedString); } 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(); } }