Exemple #1
0
        public static ADSystemMailbox GetADSystemMailbox(Guid mdbGuid, string dcName, NetworkCredential cred)
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(dcName, true, ConsistencyMode.PartiallyConsistent, cred, ADSessionSettings.FromRootOrgScopeSet(), 1080, "GetADSystemMailbox", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Common\\MapiUtils.cs");

            tenantOrRootOrgRecipientSession.UseGlobalCatalog    = true;
            tenantOrRootOrgRecipientSession.EnforceDefaultScope = false;
            string text = string.Format(CultureInfo.InvariantCulture, "SystemMailbox{{{0}}}", new object[]
            {
                mdbGuid.ToString()
            });
            QueryFilter filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, text);

            ADRecipient[] array = tenantOrRootOrgRecipientSession.Find(null, QueryScope.SubTree, filter, null, 2);
            if (array.Length != 1)
            {
                MrsTracer.Common.Error("Found {0} mailboxes named '{1}' in the AD", new object[]
                {
                    array.Length,
                    text
                });
                throw new SystemMailboxNotFoundPermanentException(mdbGuid.ToString());
            }
            ADSystemMailbox adsystemMailbox = array[0] as ADSystemMailbox;

            if (adsystemMailbox == null)
            {
                throw new SystemMailboxNotFoundPermanentException(text);
            }
            return(adsystemMailbox);
        }
 private IGenericADUser TranslateADRecipient(ADRecipient recipient, bool checkForSystemMailbox = false)
 {
     if (recipient != null)
     {
         if (checkForSystemMailbox && recipient.RecipientType == RecipientType.SystemMailbox)
         {
             ADSystemMailbox adsystemMailbox = recipient as ADSystemMailbox;
             if (adsystemMailbox != null)
             {
                 return(new ADSystemMailboxGenericWrapper(adsystemMailbox));
             }
         }
         else
         {
             ADUser aduser = recipient as ADUser;
             if (aduser != null)
             {
                 return(new ADUserGenericWrapper(aduser));
             }
             ADGroup adgroup = recipient as ADGroup;
             if (adgroup != null && adgroup.RecipientType == RecipientType.MailUniversalDistributionGroup && adgroup.RecipientTypeDetails == RecipientTypeDetails.GroupMailbox)
             {
                 return(new ADGroupGenericWrapper(adgroup));
             }
         }
     }
     return(null);
 }
Exemple #3
0
        public static Guid GetSystemMailboxGuid(Guid mdbGuid, string dcName, NetworkCredential cred, FindServerFlags flags)
        {
            Guid guid = Guid.Empty;

            if ((flags & FindServerFlags.ForceRediscovery) == FindServerFlags.None)
            {
                lock (MapiUtils.syncRoot)
                {
                    if (MapiUtils.mdbToSystemMailboxMap.TryGetValue(mdbGuid, out guid))
                    {
                        return(guid);
                    }
                }
            }
            try
            {
                ADSystemMailbox adsystemMailbox = MapiUtils.GetADSystemMailbox(mdbGuid, dcName, cred);
                guid = adsystemMailbox.ExchangeGuid;
            }
            catch (SystemMailboxNotFoundPermanentException)
            {
                if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None)
                {
                    throw;
                }
                return(Guid.Empty);
            }
            lock (MapiUtils.syncRoot)
            {
                MapiUtils.mdbToSystemMailboxMap[mdbGuid] = guid;
            }
            return(guid);
        }
Exemple #4
0
        private ExchangePrincipal GetExchangePrincipal(IConfigurable dataObject)
        {
            ADUser aduser = dataObject as ADUser;

            if (aduser != null)
            {
                if (!this.ShouldProcessArchive)
                {
                    if (aduser.RecipientType == RecipientType.MailUser)
                    {
                        base.WriteError(new InvalidOperationException(Strings.RecipientTypeNotValid(this.Identity.ToString())), ErrorCategory.InvalidOperation, null);
                    }
                    return(XsoStoreDataProviderBase.GetExchangePrincipalWithAdSessionSettingsForOrg(base.SessionSettings.CurrentOrganizationId, aduser));
                }
                if (aduser.ArchiveState != ArchiveState.None)
                {
                    return(ExchangePrincipal.FromMailboxGuid(base.SessionSettings, aduser.ArchiveGuid, RemotingOptions.AllowCrossSite | RemotingOptions.AllowCrossPremise, null));
                }
                base.WriteError(new InvalidOperationException(Strings.VerboseArchiveNotExistInStore(aduser.DisplayName)), ErrorCategory.InvalidOperation, null);
            }
            ADSystemMailbox adsystemMailbox = dataObject as ADSystemMailbox;

            if (adsystemMailbox != null)
            {
                return(ExchangePrincipal.FromADSystemMailbox(base.SessionSettings, adsystemMailbox, ((ITopologyConfigurationSession)this.ConfigurationSession).FindServerByLegacyDN(adsystemMailbox.ServerLegacyDN)));
            }
            return(null);
        }
        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()
            });
        }
        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 ExchangePrincipal FromADSystemMailbox(ADSessionSettings adSettings, ADSystemMailbox adSystemMailbox, Server server)
 {
     Util.ThrowOnNullArgument(adSettings, "adSettings");
     Util.ThrowOnNullArgument(adSystemMailbox, "adSystemMailbox");
     Util.ThrowOnNullArgument(server, "server");
     if (!server.IsMailboxServer)
     {
         throw new ArgumentException("Needs to be a Mailbox server", "server");
     }
     return(this.FromADSystemMailbox(adSettings.CreateRecipientSession(null), new ADSystemMailboxGenericWrapper(adSystemMailbox), server.Fqdn, server.ExchangeLegacyDN));
 }
Exemple #8
0
        private MailboxSession OpenSystemMailbox()
        {
            MrsTracer.Provider.Function("StorageMailbox.OpenSystemMailbox", new object[0]);
            base.CheckDisposed();
            Server          server          = LocalServer.GetServer();
            ADSystemMailbox adsystemMailbox = MapiUtils.GetADSystemMailbox(base.MdbGuid, null, null);
            MailboxSession  result;

            using (base.RHTracker.Start())
            {
                ExchangePrincipal mailboxOwner = ExchangePrincipal.FromADSystemMailbox(ADSessionSettings.FromRootOrgScopeSet(), adsystemMailbox, server);
                result = MailboxSession.OpenAsSystemService(mailboxOwner, CultureInfo.InvariantCulture, "Client=MSExchangeMigration");
            }
            return(result);
        }
Exemple #9
0
        protected ADSystemMailbox GetServerSystemMailbox(Server server)
        {
            ADSystemMailbox result = null;

            try
            {
                this.SourceSystemMailboxMdb = this.GetServerMdb(this.SourceMailboxServer);
                result = this.GetSystemMailboxFromMdb(this.SourceSystemMailboxMdb);
            }
            catch (MailboxServerNotHostingMdbException)
            {
                this.AddErrorMonitoringEvent(1005, Strings.TestMailflowServerWithoutMdbs(server.Name));
            }
            this.SourceSystemMailbox = result;
            return(result);
        }
Exemple #10
0
        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);
        }
 private void SetTargetParameters()
 {
     if (base.Task.AutoDiscoverTargetMailboxServer.IsPresent)
     {
         base.Task.TargetMailboxServer = this.AutoDiscoverTargetServer();
     }
     if (base.Task.TargetMailboxServer != null)
     {
         this.targetMailboxServer = this.GetServerFromId(base.Task.TargetMailboxServer);
         ADSystemMailbox adsystemMailbox = null;
         try
         {
             this.targetSystemMailboxMdb = base.GetServerMdb(this.targetMailboxServer);
             adsystemMailbox             = base.GetSystemMailboxFromMdb(this.targetSystemMailboxMdb);
             this.targetServerHasMdb     = true;
         }
         catch (MailboxServerNotHostingMdbException)
         {
             this.targetServerHasMdb = false;
         }
         if (this.targetServerHasMdb)
         {
             this.targetMailboxAddress  = adsystemMailbox.PrimarySmtpAddress.ToString();
             this.friendlyTargetAddress = base.Task.TargetMailboxServer.ToString() + "\\" + this.targetMailboxAddress;
             return;
         }
     }
     else if (base.Task.TargetDatabase != null)
     {
         MailboxDatabase      mailboxDatabase       = (MailboxDatabase)base.Task.GetAdDataObject <MailboxDatabase>(base.Task.TargetDatabase, base.Task.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(base.Task.TargetDatabase.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(base.Task.TargetDatabase.ToString())));
         ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
         DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(mailboxDatabase.Guid);
         if (serverForDatabase != null && !string.IsNullOrEmpty(serverForDatabase.ServerFqdn))
         {
             base.Task.TargetMailboxServer = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
             this.targetMailboxServer      = this.GetServerFromId(base.Task.TargetMailboxServer);
             ADSystemMailbox systemMailboxFromMdb = base.GetSystemMailboxFromMdb(mailboxDatabase);
             this.targetSystemMailboxMdb = mailboxDatabase;
             this.targetMailboxAddress   = systemMailboxFromMdb.PrimarySmtpAddress.ToString();
             this.friendlyTargetAddress  = base.Task.TargetMailboxServer.ToString() + "\\" + this.targetMailboxAddress;
             return;
         }
         base.WriteErrorAndMonitoringEvent(new MdbServerNotFoundException(mailboxDatabase.ToString()), ErrorCategory.InvalidData, 1011);
         return;
     }
     else if (base.Task.TargetEmailAddress != null)
     {
         this.targetMailboxAddress = base.Task.TargetEmailAddress;
         if (string.IsNullOrEmpty(base.Task.TargetEmailAddressDisplayName))
         {
             this.friendlyTargetAddress = base.Task.TargetEmailAddress;
         }
         else
         {
             this.friendlyTargetAddress = base.Task.TargetEmailAddressDisplayName + "(" + base.Task.TargetEmailAddress + ")";
         }
         RoutingAddress routingAddress = new RoutingAddress(base.Task.TargetEmailAddress);
         if (!routingAddress.IsValid)
         {
             base.WriteErrorAndMonitoringEvent(new RecipientTaskException(Strings.TestMailflowInvalidTargetEmailAddress(base.Task.TargetEmailAddress)), ErrorCategory.InvalidData, 1008);
         }
     }
 }
 public static ExchangePrincipal FromADSystemMailbox(ADSessionSettings adSettings, ADSystemMailbox adSystemMailbox, Server server)
 {
     return(ExchangePrincipal.ExchangePrincipalFactory.FromADSystemMailbox(adSettings, adSystemMailbox, server));
 }
        internal static ADSystemMailbox SaveSystemMailbox(MailboxDatabase mdb, Server owningServer, ADObjectId rootOrgContainerId, ITopologyConfigurationSession configSession, IRecipientSession recipientSession, ADObjectId[] forcedReplicationSites, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            TaskLogger.LogEnter();
            bool               useConfigNC        = configSession.UseConfigNC;
            bool               useGlobalCatalog   = configSession.UseGlobalCatalog;
            string             text               = "SystemMailbox" + mdb.Guid.ToString("B");
            SecurityIdentifier securityIdentifier = new SecurityIdentifier("SY");
            ADSystemMailbox    adsystemMailbox    = new ADSystemMailbox();

            adsystemMailbox.StampPersistableDefaultValues();
            adsystemMailbox.Name        = text;
            adsystemMailbox.DisplayName = text;
            adsystemMailbox.Alias       = text;
            adsystemMailbox.HiddenFromAddressListsEnabled = true;
            adsystemMailbox.Database = mdb.Id;
            if (owningServer == null)
            {
                throw new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.ServerLegacyDN = owningServer.ExchangeLegacyDN;
            adsystemMailbox.ExchangeGuid   = Guid.NewGuid();
            AcceptedDomain defaultAcceptedDomain = configSession.GetDefaultAcceptedDomain();

            if (defaultAcceptedDomain == null || defaultAcceptedDomain.DomainName == null || defaultAcceptedDomain.DomainName.Domain == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorNoDefaultAcceptedDomainFound(mdb.Identity.ToString()));
            }
            adsystemMailbox.EmailAddresses.Add(ProxyAddress.Parse("SMTP:" + adsystemMailbox.Alias + "@" + defaultAcceptedDomain.DomainName.Domain.ToString()));
            adsystemMailbox.WindowsEmailAddress         = adsystemMailbox.PrimarySmtpAddress;
            adsystemMailbox.SendModerationNotifications = TransportModerationNotificationFlags.Never;
            Organization organization = configSession.Read <Organization>(rootOrgContainerId);

            if (organization == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorOrganizationNotFound(rootOrgContainerId.Name));
            }
            string parentLegacyDN = string.Format(CultureInfo.InvariantCulture, "{0}/ou={1}/cn=Recipients", new object[]
            {
                organization.LegacyExchangeDN,
                configSession.GetAdministrativeGroupId().Name
            });

            adsystemMailbox.LegacyExchangeDN = LegacyDN.GenerateLegacyDN(parentLegacyDN, adsystemMailbox);
            ADComputer adcomputer;

            try
            {
                configSession.UseConfigNC      = false;
                configSession.UseGlobalCatalog = true;
                adcomputer = configSession.FindComputerByHostName(owningServer.Name);
            }
            finally
            {
                configSession.UseConfigNC      = useConfigNC;
                configSession.UseGlobalCatalog = useGlobalCatalog;
            }
            if (adcomputer == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorDBOwningServerNotFound(mdb.Identity.ToString()));
            }
            ADObjectId adobjectId = adcomputer.Id.DomainId;

            adobjectId = adobjectId.GetChildId("Microsoft Exchange System Objects");
            adsystemMailbox.SetId(adobjectId.GetChildId(text));
            GenericAce[] aces = new GenericAce[]
            {
                new CommonAce(AceFlags.None, AceQualifier.AccessAllowed, 131075, securityIdentifier, false, null)
            };
            DirectoryCommon.SetAclOnAlternateProperty(adsystemMailbox, aces, ADSystemAttendantMailboxSchema.ExchangeSecurityDescriptor, securityIdentifier, securityIdentifier);
            recipientSession.LinkResolutionServer = mdb.OriginatingServer;
            bool enforceDefaultScope = recipientSession.EnforceDefaultScope;

            try
            {
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.EnforceDefaultScope = false;
                recipientSession.Save(adsystemMailbox);
            }
            catch (ADConstraintViolationException ex)
            {
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ex.Server, false, ConsistencyMode.PartiallyConsistent, configSession.SessionSettings, 705, "SaveSystemMailbox", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\database\\NewMailboxDatabase.cs");
                if (!tenantOrTopologyConfigurationSession.ReplicateSingleObjectToTargetDC(mdb, ex.Server))
                {
                    throw;
                }
                writeVerbose(TaskVerboseStringHelper.GetSaveObjectVerboseString(adsystemMailbox, recipientSession, typeof(ADSystemMailbox)));
                recipientSession.Save(adsystemMailbox);
            }
            finally
            {
                writeVerbose(TaskVerboseStringHelper.GetSourceVerboseString(recipientSession));
                recipientSession.EnforceDefaultScope = enforceDefaultScope;
            }
            if (forcedReplicationSites != null)
            {
                DagTaskHelper.ForceReplication(recipientSession, adsystemMailbox, forcedReplicationSites, mdb.Name, writeWarning, writeVerbose);
            }
            TaskLogger.LogExit();
            return(adsystemMailbox);
        }
Exemple #14
0
 public SystemMailboxPresentationObject(ADSystemMailbox dataObject) : base(dataObject)
 {
 }
Exemple #15
0
        private bool AcquireADObjectsForPrivateMdb()
        {
            if (MdbSystemMailboxPinger.OnTestPing != null)
            {
                return(true);
            }
            bool flag = false;

            try
            {
                if (this.principal != null)
                {
                    if (!this.VerifyLocalBoxCall(this.principal.MailboxInfo.Location.ServerFqdn))
                    {
                        return(false);
                    }
                    flag = true;
                    return(true);
                }
                else
                {
                    if ((this.pingerState == MdbSystemMailboxPinger.PingerState.NeedReinitialization || this.pingerState == MdbSystemMailboxPinger.PingerState.NotInitialized) && TimeProvider.UtcNow - this.lastSessionAttemptUtc < MdbSystemMailboxPinger.OpenSessionAttemptInterval)
                    {
                        ExTraceGlobals.DatabasePingerTracer.TraceDebug((long)this.GetHashCode(), "Need to acquire principal, but not enough time has passed between attempts.");
                        return(false);
                    }
                    this.lastSessionAttemptUtc = TimeProvider.UtcNow;
                    ActiveManager        noncachingActiveManagerInstance = ActiveManager.GetNoncachingActiveManagerInstance();
                    DatabaseLocationInfo serverForDatabase = noncachingActiveManagerInstance.GetServerForDatabase(this.databaseGuid, true);
                    if (!this.VerifyLocalBoxCall(serverForDatabase.ServerFqdn))
                    {
                        return(false);
                    }
                    ADSessionSettings adsessionSettings = ADSessionSettings.FromRootOrgScopeSet();
                    ADSystemMailbox   adSystemMailbox   = this.FindSystemMailbox(adsessionSettings);
                    Server            server            = this.FindMdbServer(adsessionSettings, serverForDatabase.ServerFqdn);
                    if (server == null)
                    {
                        ExTraceGlobals.DatabasePingerTracer.TraceError <string>((long)this.GetHashCode(), "[MdbSystemMailboxPinger.AcquireADObjectsForPrivateMdb] Failed to find server with FQDN: '{0}'", serverForDatabase.ServerFqdn);
                        return(false);
                    }
                    this.principal  = ExchangePrincipal.FromADSystemMailbox(adsessionSettings, adSystemMailbox, server);
                    this.accessInfo = new MailboxAccessInfo(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                    flag            = true;
                }
            }
            catch (StoragePermanentException arg)
            {
                ExTraceGlobals.DatabasePingerTracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "Encountered StoragePermanentException obtaining ExchangePrincipal.  Exception: {0}", arg);
            }
            catch (StorageTransientException arg2)
            {
                ExTraceGlobals.DatabasePingerTracer.TraceError <StorageTransientException>((long)this.GetHashCode(), "Encountered StorageTransientException obtaining ExchangePrincipal.  Exception: {0}", arg2);
            }
            catch (DataSourceOperationException arg3)
            {
                ExTraceGlobals.DatabasePingerTracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "EncounteredDataSourceOperationException obtaining ExchangePrincipal.  Exception :{0}", arg3);
            }
            catch (DataSourceTransientException arg4)
            {
                ExTraceGlobals.DatabasePingerTracer.TraceError <DataSourceTransientException>((long)this.GetHashCode(), "Encountered DataSourceTransientException obtaining ExchangePrincipal.  Exception :{0}", arg4);
            }
            finally
            {
                if (!flag)
                {
                    this.principal = null;
                    this.DisposeAccessInfo();
                }
            }
            return(flag);
        }
        protected void ResolveDatabaseAndServer()
        {
            DatabaseIdParameter databaseIdParameter   = this.Database;
            ServerIdParameter   serverIdParameter     = this.Server ?? new ServerIdParameter();
            ActiveManager       activeManagerInstance = ActiveManager.GetActiveManagerInstance();

            if (this.Identity != null)
            {
                bool flag = false;
                if (this.isRunningLogonStatisticsTask)
                {
                    TIdentity tidentity            = this.Identity;
                    IEnumerable <Database> objects = tidentity.GetObjects <Database>(null, base.GlobalConfigSession);
                    foreach (Database item in objects)
                    {
                        this.databases.Add(item);
                    }
                    if (this.databases.Count > 0)
                    {
                        if (this.databases[0].Server == null)
                        {
                            string    name       = typeof(Database).Name;
                            TIdentity tidentity2 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name, tidentity2.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        DatabaseLocationInfo serverForDatabase = activeManagerInstance.GetServerForDatabase(this.databases[0].Guid);
                        serverIdParameter = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                        if (string.IsNullOrEmpty(this.databases[0].ExchangeLegacyDN))
                        {
                            string    name2      = typeof(Database).Name;
                            TIdentity tidentity3 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name2, tidentity3.ToString(), DatabaseSchema.ExchangeLegacyDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        this.identity = new MailboxId(this.databases[0].ExchangeLegacyDN);
                        flag          = true;
                    }
                }
                if (!flag)
                {
                    IIdentityParameter  id            = this.Identity;
                    IConfigDataProvider session       = this.readOnlyRecipientSession;
                    ObjectId            rootID        = null;
                    TIdentity           tidentity4    = this.Identity;
                    LocalizedString?    notFoundError = new LocalizedString?(Strings.ErrorMailboxNotFound(tidentity4.ToString()));
                    TIdentity           tidentity5    = this.Identity;
                    ADRecipient         adrecipient   = (ADRecipient)base.GetDataObject <ADRecipient>(id, session, rootID, notFoundError, new LocalizedString?(Strings.ErrorMailboxNotUnique(tidentity5.ToString())));
                    Guid       guid = Guid.Empty;
                    string     mailboxExchangeLegacyDn = null;
                    ADObjectId adobjectId = null;
                    if (string.IsNullOrEmpty(adrecipient.LegacyExchangeDN))
                    {
                        string    name3      = typeof(ADRecipient).Name;
                        TIdentity tidentity6 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name3, tidentity6.ToString(), ADRecipientSchema.LegacyExchangeDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
                    }
                    ADUser                   aduser                   = adrecipient as ADUser;
                    ADSystemMailbox          adsystemMailbox          = adrecipient as ADSystemMailbox;
                    ADSystemAttendantMailbox adsystemAttendantMailbox = adrecipient as ADSystemAttendantMailbox;
                    ADPublicDatabase         adpublicDatabase         = adrecipient as ADPublicDatabase;
                    if (aduser != null)
                    {
                        if (this.isRunningMailboxStatisticsTask && aduser.RecipientTypeDetails == RecipientTypeDetails.AuditLogMailbox && !this.GetAuditLogMailboxStatistics())
                        {
                            TIdentity tidentity7 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.RecipientNotFoundException(tidentity7.ToString())), ErrorCategory.InvalidArgument, null);
                        }
                        bool archiveMailboxStatistics = this.GetArchiveMailboxStatistics();
                        if (aduser.RecipientType == RecipientType.MailUser && !archiveMailboxStatistics)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.RecipientTypeNotValid(aduser.ToString())), (ErrorCategory)1003, this.Identity);
                        }
                        RecipientIdParameter recipientIdParameter = this.Identity as RecipientIdParameter;
                        if (this.isRunningMailboxStatisticsTask && recipientIdParameter != null && recipientIdParameter.RawMailboxGuidInvolvedInSearch != Guid.Empty && aduser.MailboxLocations != null)
                        {
                            IMailboxLocationInfo mailboxLocation = aduser.MailboxLocations.GetMailboxLocation(recipientIdParameter.RawMailboxGuidInvolvedInSearch);
                            if (mailboxLocation != null)
                            {
                                guid       = mailboxLocation.MailboxGuid;
                                adobjectId = mailboxLocation.DatabaseLocation;
                            }
                        }
                        if (guid == Guid.Empty || adobjectId == null)
                        {
                            if (archiveMailboxStatistics)
                            {
                                if (aduser.ArchiveGuid != Guid.Empty)
                                {
                                    if (aduser.ArchiveDomain != null)
                                    {
                                        base.WriteError(new MdbAdminTaskException(Strings.ErrorRemoteArchiveNoStats(aduser.ToString())), (ErrorCategory)1003, this.Identity);
                                    }
                                    else
                                    {
                                        guid       = aduser.ArchiveGuid;
                                        adobjectId = (aduser.ArchiveDatabase ?? aduser.Database);
                                    }
                                }
                                else
                                {
                                    base.WriteError(new MdbAdminTaskException(Strings.ErrorArchiveNotEnabled(aduser.ToString())), ErrorCategory.InvalidArgument, this.Identity);
                                }
                            }
                            else
                            {
                                guid       = aduser.ExchangeGuid;
                                adobjectId = aduser.Database;
                            }
                        }
                        mailboxExchangeLegacyDn = aduser.LegacyExchangeDN;
                    }
                    else if (adsystemMailbox != null)
                    {
                        guid = adsystemMailbox.ExchangeGuid;
                        mailboxExchangeLegacyDn = adsystemMailbox.LegacyExchangeDN;
                        adobjectId = adsystemMailbox.Database;
                    }
                    else if (adsystemAttendantMailbox != null)
                    {
                        guid = adsystemAttendantMailbox.Guid;
                        mailboxExchangeLegacyDn = adsystemAttendantMailbox.LegacyExchangeDN;
                        adobjectId = adsystemAttendantMailbox.Database;
                    }
                    else if (adpublicDatabase != null)
                    {
                        mailboxExchangeLegacyDn = adpublicDatabase.LegacyExchangeDN;
                        adobjectId = (ADObjectId)adpublicDatabase.Identity;
                    }
                    if (adobjectId == null)
                    {
                        string    name4      = adrecipient.GetType().Name;
                        TIdentity tidentity8 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name4, tidentity8.ToString(), IADMailStorageSchema.Database.Name)), ErrorCategory.InvalidArgument, adrecipient);
                    }
                    databaseIdParameter = new DatabaseIdParameter(adobjectId);
                    if (this.isRunningLogonStatisticsTask)
                    {
                        this.identity = new MailboxId(mailboxExchangeLegacyDn);
                    }
                    else
                    {
                        this.identity = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(adobjectId), guid);
                    }
                }
            }
            if (databaseIdParameter != null)
            {
                databaseIdParameter.AllowLegacy = true;
                LocalizedString empty  = LocalizedString.Empty;
                LocalizedString empty2 = LocalizedString.Empty;
                Database        database;
                if (this.isRunningLogonStatisticsTask)
                {
                    database = (Database)base.GetDataObject <Database>(databaseIdParameter, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(databaseIdParameter.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(databaseIdParameter.ToString())));
                }
                else
                {
                    database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(databaseIdParameter, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorMailboxDatabaseNotFound(databaseIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxDatabaseNotUnique(databaseIdParameter.ToString())));
                }
                if (database.Server == null)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(this.isRunningLogonStatisticsTask ? typeof(Database).Name : typeof(MailboxDatabase).Name, databaseIdParameter.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, database);
                }
                this.databases = new List <Database>(new Database[]
                {
                    database
                });
                if (this.CopyOnServer != null)
                {
                    serverIdParameter = this.CopyOnServer;
                }
                else
                {
                    DatabaseLocationInfo serverForDatabase = activeManagerInstance.GetServerForDatabase(database.Guid);
                    serverIdParameter = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                }
            }
            if (this.Server != null)
            {
                serverIdParameter = this.Server;
                this.server       = MapiTaskHelper.GetMailboxServer(this.Server, base.GlobalConfigSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            else
            {
                this.server = (Server)base.GetDataObject <Server>(serverIdParameter, base.GlobalConfigSession, null, new LocalizedString?((this.Identity == null && this.Database == null) ? Strings.ErrorLocalMachineIsNotExchangeServer : Strings.ErrorServerNotFound(serverIdParameter.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(serverIdParameter.ToString())));
                if (!this.server.IsExchange2007OrLater || !this.server.IsMailboxServer)
                {
                    if (this.Identity != null)
                    {
                        TIdentity tidentity9 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorMailboxInNonMailboxServer(tidentity9.ToString())), ErrorCategory.InvalidArgument, this.server);
                    }
                    if (this.Database != null)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorDatabaseInNonMailboxServer(this.Database.ToString())), ErrorCategory.InvalidArgument, this.server);
                    }
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorLocalServerIsNotMailboxServer), ErrorCategory.InvalidArgument, this.server);
                }
            }
            if (string.IsNullOrEmpty(this.server.ExchangeLegacyDN))
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, serverIdParameter.ToString(), ServerSchema.ExchangeLegacyDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
            }
            if (this.databases.Count == 0)
            {
                if (this.isRunningLogonStatisticsTask)
                {
                    this.FilterActiveDatabases(activeManagerInstance, this.server.GetDatabases());
                    return;
                }
                this.FilterActiveDatabases(activeManagerInstance, this.server.GetMailboxDatabases());
            }
        }
Exemple #17
0
 public ADSystemMailboxGenericWrapper(ADSystemMailbox systemMailbox)
 {
     ArgumentValidator.ThrowIfNull("systemMailbox", systemMailbox);
     this.systemMailbox = systemMailbox;
 }
 private void RollbackOperation(MailboxDatabase mdb, DatabaseCopy dbCopy, ADSystemMailbox systemMailbox)
 {
     if (mdb == null || dbCopy == null)
     {
         if (systemMailbox != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteSystemMailbox(systemMailbox.Id.ToString()));
                 this.RecipientSessionForSystemMailbox.Delete(systemMailbox);
             }
             catch (DataSourceTransientException ex)
             {
                 this.WriteWarning(Strings.FailedToDeleteSystemMailbox(systemMailbox.Identity.ToString(), ex.Message));
                 TaskLogger.Trace("Failed to delete System Mailbox {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     systemMailbox.Identity,
                     mdb.Identity,
                     ex.ToString()
                 });
             }
             catch (DataSourceOperationException ex2)
             {
                 this.WriteWarning(Strings.FailedToDeleteSystemMailbox(systemMailbox.Identity.ToString(), ex2.Message));
                 TaskLogger.Trace("Failed to delete System Mailbox {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     systemMailbox.Identity,
                     mdb.Identity,
                     ex2.ToString()
                 });
             }
         }
         if (dbCopy != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteDBCopy(dbCopy.Id.ToString()));
                 base.DataSession.Delete(dbCopy);
             }
             catch (DataSourceTransientException ex3)
             {
                 this.WriteWarning(Strings.FailedToDeleteDatabaseCopy(dbCopy.Identity.ToString(), ex3.Message));
                 TaskLogger.Trace("Failed to delete Database Copy {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     dbCopy.Identity,
                     mdb.Identity,
                     ex3.ToString()
                 });
             }
             catch (DataSourceOperationException ex4)
             {
                 this.WriteWarning(Strings.FailedToDeleteDatabaseCopy(dbCopy.Identity.ToString(), ex4.Message));
                 TaskLogger.Trace("Failed to delete Database Copy {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     dbCopy.Identity,
                     mdb.Identity,
                     ex4.ToString()
                 });
             }
         }
         if (mdb != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteMDB(mdb.Id.ToString()));
                 base.DataSession.Delete(mdb);
                 DatabaseTasksHelper.RemoveDatabaseFromClusterDB((ITopologyConfigurationSession)base.DataSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError), mdb);
             }
             catch (DataSourceTransientException ex5)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex5.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex5.ToString()
                 });
             }
             catch (DataSourceOperationException ex6)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex6.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex6.ToString()
                 });
             }
             catch (ClusterException ex7)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex7.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex7.ToString()
                 });
             }
         }
     }
 }
Exemple #19
0
        // Token: 0x060003B5 RID: 949 RVA: 0x00015440 File Offset: 0x00013640
        internal static ADObject CreateAndInitializeRecipientObject <TRecipientObject>(ADPropertyBag propertyBag, ADRawEntry dummyObject, IRecipientSession recipientSession) where TRecipientObject : IConfigurable, new()
        {
            ArgumentValidator.ThrowIfNull("propertyBag", propertyBag);
            ArgumentValidator.ThrowIfNull("dummyObject", dummyObject);
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[ADObjectSchema.ObjectClass];
            ADObject adobject;

            if (dummyObject is OWAMiniRecipient)
            {
                adobject = new OWAMiniRecipient();
            }
            else if (dummyObject is ActiveSyncMiniRecipient)
            {
                adobject = new ActiveSyncMiniRecipient();
            }
            else if (dummyObject is StorageMiniRecipient)
            {
                adobject = new StorageMiniRecipient();
            }
            else if (dummyObject is TransportMiniRecipient)
            {
                adobject = new TransportMiniRecipient();
            }
            else if (dummyObject is LoadBalancingMiniRecipient)
            {
                adobject = new LoadBalancingMiniRecipient();
            }
            else if (dummyObject is MiniRecipientWithTokenGroups)
            {
                adobject = new MiniRecipientWithTokenGroups();
            }
            else if (dummyObject is FrontEndMiniRecipient)
            {
                adobject = new FrontEndMiniRecipient();
            }
            else if (dummyObject is MiniRecipient)
            {
                adobject = new MiniRecipient();
            }
            else if (dummyObject is RemovedMailbox)
            {
                adobject = new RemovedMailbox();
            }
            else if (dummyObject is DeletedRecipient)
            {
                adobject = new DeletedRecipient();
            }
            else if (multiValuedProperty.Contains(ADComputerRecipient.MostDerivedClass))
            {
                adobject = new ADComputerRecipient();
            }
            else if (multiValuedProperty.Contains(ADUser.MostDerivedClass))
            {
                adobject = new ADUser();
            }
            else if (multiValuedProperty.Contains(ADContact.MostDerivedClass))
            {
                adobject = new ADContact();
            }
            else if (multiValuedProperty.Contains(ADGroup.MostDerivedClass))
            {
                adobject = new ADGroup();
            }
            else if (multiValuedProperty.Contains(ADDynamicGroup.MostDerivedClass))
            {
                adobject = new ADDynamicGroup();
            }
            else if (multiValuedProperty.Contains(ADPublicFolder.MostDerivedClass))
            {
                adobject = new ADPublicFolder();
            }
            else if (multiValuedProperty.Contains(ADSystemAttendantMailbox.MostDerivedClass))
            {
                adobject = new ADSystemAttendantMailbox();
            }
            else if (multiValuedProperty.Contains(ADSystemMailbox.MostDerivedClass))
            {
                adobject = new ADSystemMailbox();
            }
            else if (multiValuedProperty.Contains(ADPublicDatabase.MostDerivedClass))
            {
                adobject = new ADPublicDatabase();
            }
            else
            {
                if (!multiValuedProperty.Contains(ADMicrosoftExchangeRecipient.MostDerivedClass))
                {
                    string objectClass = string.Empty;
                    foreach (string text in multiValuedProperty)
                    {
                        objectClass = text;
                    }
                    ObjectValidationError error = new ObjectValidationError(DirectoryStrings.UnsupportedObjectClass(objectClass), (ADObjectId)propertyBag[ADObjectSchema.Id], string.Empty);
                    ADProviderPerf.UpdateProcessCounter(Counter.ProcessRateCriticalValidationFailures, UpdateType.Update, 1U);
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_VALIDATION_FAILED_FCO_MODE_RECIPIENT, ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToString(), new object[]
                    {
                        ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToDNString()
                    });
                    throw new DataValidationException(error);
                }
                adobject = new ADMicrosoftExchangeRecipient();
            }
            adobject.m_Session   = recipientSession;
            adobject.propertyBag = propertyBag;
            adobject.Initialize();
            adobject.ResetChangeTracking(true);
            if (recipientSession != null)
            {
                adobject.SetIsReadOnly(recipientSession.ReadOnly);
            }
            ExTraceGlobals.ADReadDetailsTracer.TraceDebug <string, RecipientType>((long)((recipientSession != null) ? recipientSession.GetHashCode() : 0), "ADRecipientObjectSession::CreateObject - Got {0} as {1}", adobject.DistinguishedName, (RecipientType)adobject[ADRecipientSchema.RecipientType]);
            return(adobject);
        }
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            ADObjectId  adobjectId  = null;
            ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(this.Identity, this.recipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.Identity.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.Identity.ToString())));
            ADUser      aduser      = adrecipient as ADUser;

            if (aduser != null)
            {
                this.exchangeGuid = aduser.ExchangeGuid;
                adobjectId        = aduser.Database;
            }
            else
            {
                ADSystemMailbox adsystemMailbox = adrecipient as ADSystemMailbox;
                if (adsystemMailbox != null)
                {
                    this.exchangeGuid = adsystemMailbox.ExchangeGuid;
                    adobjectId        = adsystemMailbox.Database;
                }
            }
            if (adobjectId == null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(adrecipient.GetType().Name, this.Identity.ToString(), IADMailStorageSchema.Database.Name)), ErrorCategory.InvalidArgument, adrecipient);
            }
            DatabaseIdParameter id = new DatabaseIdParameter(adobjectId);

            this.database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(id, this.systemConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(adobjectId.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(adobjectId.ToString())));
            try
            {
                this.dbLocationInfo = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(this.database.Id.ObjectGuid);
                this.server         = this.DbLocationInfo.ServerFqdn.Split(new char[]
                {
                    '.'
                })[0];
            }
            catch (DatabaseNotFoundException exception)
            {
                base.WriteError(exception, ExchangeErrorCategory.ServerOperation, null);
            }
            catch (ObjectNotFoundException exception2)
            {
                base.WriteError(exception2, ExchangeErrorCategory.ServerOperation, null);
            }
            try
            {
                if (this.registryKeyHive == null)
                {
                    this.registryKeyHive = this.OpenHive(this.dbLocationInfo.ServerFqdn);
                }
            }
            catch (IOException ex)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex.ToString()), ErrorCategory.ObjectNotFound, null);
            }
            catch (SecurityException ex2)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex2.ToString()), ErrorCategory.SecurityError, null);
            }
            catch (UnauthorizedAccessException ex3)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex3.ToString()), ErrorCategory.PermissionDenied, null);
            }
            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();
     }
 }