示例#1
0
 public static ADForest GetForest(string forestFqdn, NetworkCredential credentials)
 {
     if (string.IsNullOrEmpty(forestFqdn))
     {
         throw new ArgumentNullException("forestFqdn");
     }
     if (ADForest.IsLocalForestFqdn(forestFqdn))
     {
         if (credentials != null)
         {
             throw new ArgumentException("The use of credentials is not supported for the local forest '" + forestFqdn + "'");
         }
         return(ADForest.GetLocalForest());
     }
     else
     {
         PartitionId partitionId = new PartitionId(forestFqdn);
         if (ADAccountPartitionLocator.IsKnownPartition(partitionId))
         {
             return(ADForest.GetForest(partitionId));
         }
         ADServerInfo remoteServerFromDomainFqdn = TopologyProvider.GetInstance().GetRemoteServerFromDomainFqdn(forestFqdn, credentials);
         return(new ADForest(forestFqdn, remoteServerFromDomainFqdn.Fqdn, null, credentials, false));
     }
 }
示例#2
0
 private ADForest(string fqdn, string domainController, string globalCatalog, NetworkCredential networkCredential, bool knownForest)
 {
     this.fqdn              = fqdn;
     this.domainController  = domainController;
     this.globalCatalog     = globalCatalog;
     this.networkCredential = networkCredential;
     this.partitionId       = (Datacenter.IsMicrosoftHostedOnly(true) ? new PartitionId(fqdn) : PartitionId.LocalForest);
     this.isKnownForest     = knownForest;
     this.isLocalForest     = ADForest.IsLocalForestFqdn(fqdn);
 }
示例#3
0
        public static ADForest GetForest(PartitionId partitionId)
        {
            if (null == partitionId)
            {
                throw new ArgumentNullException("partitionId");
            }
            if (ADForest.IsLocalForestFqdn(partitionId.ForestFQDN))
            {
                return(ADForest.GetLocalForest());
            }
            IList <ADServerInfo> serversForRole  = TopologyProvider.GetInstance().GetServersForRole(partitionId.ForestFQDN, new List <string>(0), ADServerRole.DomainController, 1, false);
            IList <ADServerInfo> serversForRole2 = TopologyProvider.GetInstance().GetServersForRole(partitionId.ForestFQDN, new List <string>(0), ADServerRole.GlobalCatalog, 1, false);

            if (serversForRole == null || serversForRole2 == null || serversForRole.Count == 0 || serversForRole2.Count == 0)
            {
                throw new ADOperationException(DirectoryStrings.CannotGetForestInfo(partitionId.ForestFQDN));
            }
            return(new ADForest(partitionId.ForestFQDN, serversForRole[0].Fqdn, serversForRole2[0].Fqdn, null, true));
        }