コード例 #1
0
 internal static AdamInstance FindOneAdamInstance(string configSetName, DirectoryContext context, string partitionName, string siteName)
 {
     if (partitionName == null || partitionName.Length != 0)
     {
         if (siteName == null || siteName.Length != 0)
         {
             ArrayList replicaList = Utils.GetReplicaList(context, partitionName, siteName, false, true, false);
             if (replicaList.Count >= 1)
             {
                 return(ConfigurationSet.FindAliveAdamInstance(configSetName, context, replicaList));
             }
             else
             {
                 throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ADAMInstanceNotFound"), typeof(AdamInstance), null);
             }
         }
         else
         {
             throw new ArgumentException(Res.GetString("EmptyStringParameter"), "siteName");
         }
     }
     else
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "partitionName");
     }
 }
コード例 #2
0
 internal static AdamInstance FindAnyAdamInstance(DirectoryContext context)
 {
     if (context.ContextType == DirectoryContextType.ConfigurationSet)
     {
         DirectoryEntry searchRootEntry = ConfigurationSet.GetSearchRootEntry(Forest.GetCurrentForest());
         ArrayList      arrayLists      = new ArrayList();
         try
         {
             try
             {
                 StringBuilder stringBuilder = new StringBuilder(15);
                 stringBuilder.Append("(&(");
                 stringBuilder.Append(PropertyManager.ObjectCategory);
                 stringBuilder.Append("=serviceConnectionPoint)");
                 stringBuilder.Append("(");
                 stringBuilder.Append(PropertyManager.Keywords);
                 stringBuilder.Append("=1.2.840.113556.1.4.1851)(");
                 stringBuilder.Append(PropertyManager.Keywords);
                 stringBuilder.Append("=");
                 stringBuilder.Append(Utils.GetEscapedFilterValue(context.Name));
                 stringBuilder.Append("))");
                 string   str = stringBuilder.ToString();
                 string[] serviceBindingInformation = new string[1];
                 serviceBindingInformation[0] = PropertyManager.ServiceBindingInformation;
                 ADSearcher             aDSearcher = new ADSearcher(searchRootEntry, str, serviceBindingInformation, SearchScope.Subtree, false, false);
                 SearchResultCollection searchResultCollections = aDSearcher.FindAll();
                 try
                 {
                     foreach (SearchResult item in searchResultCollections)
                     {
                         string      str1       = "ldap://";
                         IEnumerator enumerator = item.Properties[PropertyManager.ServiceBindingInformation].GetEnumerator();
                         try
                         {
                             while (enumerator.MoveNext())
                             {
                                 string str2 = item.ToString();
                                 if (str2.Length <= str1.Length || string.Compare(str2.Substring(0, str1.Length), str1, StringComparison.OrdinalIgnoreCase) != 0)
                                 {
                                     continue;
                                 }
                                 arrayLists.Add(str2.Substring(str1.Length));
                             }
                         }
                         finally
                         {
                             IDisposable disposable = enumerator as IDisposable;
                             if (disposable != null)
                             {
                                 disposable.Dispose();
                             }
                         }
                     }
                 }
                 finally
                 {
                     searchResultCollections.Dispose();
                 }
             }
             catch (COMException cOMException1)
             {
                 COMException cOMException = cOMException1;
                 throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
             }
         }
         finally
         {
             searchRootEntry.Dispose();
         }
         return(ConfigurationSet.FindAliveAdamInstance(null, context, arrayLists));
     }
     else
     {
         DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
         DirectoryEntry        cachedDirectoryEntry  = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
         if (Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryApplicationMode))
         {
             string propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DnsHostName);
             return(new AdamInstance(context, propertyValue, directoryEntryManager));
         }
         else
         {
             directoryEntryManager.RemoveIfExists(directoryEntryManager.ExpandWellKnownDN(WellKnownDN.RootDSE));
             throw new ArgumentException(Res.GetString("TargetShouldBeServerORConfigSet"), "context");
         }
     }
 }