Пример #1
0
        internal static ADDomainTrustInfo ResolveAndValidateForestTrustForADDomain(Fqdn domainFqdn, Task.ErrorLoggerDelegate errorDelegate, IConfigurationSession configSession)
        {
            if (domainFqdn == null)
            {
                throw new ArgumentNullException("domainFqdn");
            }
            if (errorDelegate == null)
            {
                throw new ArgumentNullException("errorDelegate");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            ADForest localForest = ADForest.GetLocalForest();

            ADDomainTrustInfo[] array = localForest.FindTrustRelationshipsForDomain(domainFqdn);
            if (array == null || array.Length == 0)
            {
                errorDelegate(new ManagementObjectNotFoundException(Strings.ErrorManagementObjectNotFound(domainFqdn.ToString())), ExchangeErrorCategory.Client, null);
            }
            else if (array.Length != 1)
            {
                errorDelegate(new ManagementObjectAmbiguousException(Strings.ErrorManagementObjectAmbiguous(domainFqdn.ToString())), ExchangeErrorCategory.Client, null);
            }
            ADDomainTrustInfo addomainTrustInfo = array[0];

            AccountPartition[] array2 = configSession.Find <AccountPartition>(configSession.GetOrgContainerId().GetChildId(AccountPartition.AccountForestContainerName), QueryScope.OneLevel, new ComparisonFilter(ComparisonOperator.Equal, AccountPartitionSchema.TrustedDomainLink, addomainTrustInfo.DistinguishedName), null, 1);
            if (array2 != null && array2.Length != 0)
            {
                errorDelegate(new LocalizedException(Strings.ErrorTrustAlreadyInUse(addomainTrustInfo.Name, array2[0].Name)), ExchangeErrorCategory.Client, null);
            }
            return(addomainTrustInfo);
        }