public int IndexOf(ApplicationPartition applicationPartition)
    {
      Contract.Requires(applicationPartition != null);

      Contract.Ensures(Contract.Result<int>() >= -1);
      Contract.Ensures(Contract.Result<int>() < this.Count);

      return default(int);
    }
        public int IndexOf(ApplicationPartition applicationPartition)
        {
            Contract.Requires(applicationPartition != null);

            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() < this.Count);

            return(default(int));
        }
 public bool Contains(ApplicationPartition applicationPartition)
 {
     if (applicationPartition == null)
     {
         throw new ArgumentNullException("applicationPartition");
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ApplicationPartition partition = (ApplicationPartition) base.InnerList[i];
         if (Utils.Compare(partition.Name, applicationPartition.Name) == 0)
         {
             return true;
         }
     }
     return false;
 }
 public int IndexOf(ApplicationPartition applicationPartition)
 {
     if (applicationPartition == null)
     {
         throw new ArgumentNullException("applicationPartition");
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ApplicationPartition partition = (ApplicationPartition) base.InnerList[i];
         if (Utils.Compare(partition.Name, applicationPartition.Name) == 0)
         {
             return i;
         }
     }
     return -1;
 }
 public bool Contains(ApplicationPartition applicationPartition)
 {
     if (applicationPartition == null)
     {
         throw new ArgumentNullException("applicationPartition");
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ApplicationPartition partition = (ApplicationPartition)base.InnerList[i];
         if (Utils.Compare(partition.Name, applicationPartition.Name) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
 public int IndexOf(ApplicationPartition applicationPartition)
 {
     if (applicationPartition == null)
     {
         throw new ArgumentNullException("applicationPartition");
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ApplicationPartition partition = (ApplicationPartition)base.InnerList[i];
         if (Utils.Compare(partition.Name, applicationPartition.Name) == 0)
         {
             return(i);
         }
     }
     return(-1);
 }
        public bool Contains(ApplicationPartition applicationPartition)
        {
            if (applicationPartition == null)
            {
                throw new ArgumentNullException(nameof(applicationPartition));
            }

            for (int i = 0; i < InnerList.Count; i++)
            {
                ApplicationPartition tmp = (ApplicationPartition)InnerList[i] !;
                if (Utils.Compare(tmp.Name, applicationPartition.Name) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        public int IndexOf(ApplicationPartition applicationPartition)
        {
            if (applicationPartition == null)
            {
                throw new ArgumentNullException(nameof(applicationPartition));
            }

            for (int i = 0; i < InnerList.Count; i++)
            {
                ApplicationPartition tmp = (ApplicationPartition)InnerList[i] !;
                if (Utils.Compare(tmp.Name, applicationPartition.Name) == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
		public int IndexOf(ApplicationPartition applicationPartition)
		{
			if (applicationPartition != null)
			{
				int num = 0;
				while (num < base.InnerList.Count)
				{
					ApplicationPartition item = (ApplicationPartition)base.InnerList[num];
					if (Utils.Compare(item.Name, applicationPartition.Name) != 0)
					{
						num++;
					}
					else
					{
						return num;
					}
				}
				return -1;
			}
			else
			{
				throw new ArgumentNullException("applicationPartition");
			}
		}
 public int IndexOf(ApplicationPartition applicationPartition)
 {
     if (applicationPartition != null)
     {
         int num = 0;
         while (num < base.InnerList.Count)
         {
             ApplicationPartition item = (ApplicationPartition)base.InnerList[num];
             if (Utils.Compare(item.Name, applicationPartition.Name) != 0)
             {
                 num++;
             }
             else
             {
                 return(num);
             }
         }
         return(-1);
     }
     else
     {
         throw new ArgumentNullException("applicationPartition");
     }
 }
        public bool Contains(ApplicationPartition applicationPartition)
        {
            Contract.Requires(applicationPartition != null);

            return(default(bool));
        }
 public int IndexOf(ApplicationPartition applicationPartition)
 {
     throw new NotImplementedException();
 }
		public bool Contains (ApplicationPartition applicationPartition)
		{
			throw new NotImplementedException ();
		}
예제 #14
0
        public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName)
        {
            ApplicationPartition partition = null;
            DirectoryEntryManager directoryEntryMgr = null;
            DirectoryContext appNCContext = null;

            // check that the argument is not null
            if (context == null)
                throw new ArgumentNullException("context");

            if ((context.Name == null) && (!context.isRootDomain()))
            {
                throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context");
            }

            if (context.Name != null)
            {
                // the target should be a valid forest name, configset name or a server
                if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || context.isServer()))
                {
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
                }
            }

            // check that the distingushed name of the application partition is not null or empty
            if (distinguishedName == null)
                throw new ArgumentNullException("distinguishedName");

            if (distinguishedName.Length == 0)
                throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "distinguishedName");

            if (!Utils.IsValidDNFormat(distinguishedName))
                throw new ArgumentException(Res.GetString(Res.InvalidDNFormat), "distinguishedName");

            //  work with copy of the context
            context = new DirectoryContext(context);

            // search in the partitions container of the forest for 
            // crossRef objects that have their nCName set to the specified distinguishedName
            directoryEntryMgr = new DirectoryEntryManager(context);
            DirectoryEntry partitionsEntry = null;

            try
            {
                partitionsEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            // build the filter
            StringBuilder str = new StringBuilder(15);
            str.Append("(&(");
            str.Append(PropertyManager.ObjectCategory);
            str.Append("=crossRef)(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.804:=");
            str.Append((int)SystemFlag.SystemFlagNtdsNC);
            str.Append(")(!(");
            str.Append(PropertyManager.SystemFlags);
            str.Append(":1.2.840.113556.1.4.803:=");
            str.Append((int)SystemFlag.SystemFlagNtdsDomain);
            str.Append("))(");
            str.Append(PropertyManager.NCName);
            str.Append("=");
            str.Append(Utils.GetEscapedFilterValue(distinguishedName));
            str.Append("))");

            string filter = str.ToString();
            string[] propertiesToLoad = new string[2];

            propertiesToLoad[0] = PropertyManager.DnsRoot;
            propertiesToLoad[1] = PropertyManager.NCName;

            ADSearcher searcher = new ADSearcher(partitionsEntry, filter, propertiesToLoad, SearchScope.OneLevel, false /*not paged search*/, false /*no cached results*/);
            SearchResult res = null;

            try
            {
                res = searcher.FindOne();
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // object is not found since we cannot even find the container in which to search
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName);
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }
            finally
            {
                partitionsEntry.Dispose();
            }

            if (res == null)
            {
                // the specified application partition could not be found in the given forest
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName);
            }

            string appNCDnsName = null;
            try
            {
                appNCDnsName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? (string)res.Properties[PropertyManager.DnsRoot][0] : null;
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            // verify that if the target is a server, then this partition is a naming context on it
            ApplicationPartitionType appType = GetApplicationPartitionType(context);
            if (context.ContextType == DirectoryContextType.DirectoryServer)
            {
                bool hostsCurrentPartition = false;
                DistinguishedName appNCDN = new DistinguishedName(distinguishedName);
                DirectoryEntry rootDSE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);

                try
                {
                    foreach (string namingContext in rootDSE.Properties[PropertyManager.NamingContexts])
                    {
                        DistinguishedName dn = new DistinguishedName(namingContext);

                        if (dn.Equals(appNCDN))
                        {
                            hostsCurrentPartition = true;
                            break;
                        }
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
                finally
                {
                    rootDSE.Dispose();
                }

                if (!hostsCurrentPartition)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName);
                }

                appNCContext = context;
            }
            else
            {
                // we need to find a server which hosts this application partition
                if (appType == ApplicationPartitionType.ADApplicationPartition)
                {
                    int errorCode = 0;
                    DomainControllerInfo domainControllerInfo;

                    errorCode = Locator.DsGetDcNameWrapper(null, appNCDnsName, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded, out domainControllerInfo);

                    if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.AppNCNotFound), typeof(ApplicationPartition), distinguishedName);
                    }
                    else if (errorCode != 0)
                    {
                        throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
                    }

                    Debug.Assert(domainControllerInfo.DomainControllerName.Length > 2, "ApplicationPartition:FindByName - domainControllerInfo.DomainControllerName.Length <= 2");
                    string serverName = domainControllerInfo.DomainControllerName.Substring(2);
                    appNCContext = Utils.GetNewDirectoryContext(serverName, DirectoryContextType.DirectoryServer, context);
                }
                else
                {
                    // this will find an adam instance that hosts this partition and which is alive and responding.
                    string adamInstName = ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name;
                    appNCContext = Utils.GetNewDirectoryContext(adamInstName, DirectoryContextType.DirectoryServer, context);
                }
            }
            partition = new ApplicationPartition(appNCContext, (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.NCName), appNCDnsName, appType, directoryEntryMgr);

            return partition;
        }
		public int IndexOf (ApplicationPartition applicationPartition)
		{
			throw new NotImplementedException ();
		}
		public void CopyTo (ApplicationPartition[] applicationPartitions, int index)
		{
			throw new NotImplementedException ();
		}
 public bool Contains(ApplicationPartition applicationPartition)
 {
     throw new NotImplementedException();
 }
    public bool Contains(ApplicationPartition applicationPartition)
    {
      Contract.Requires(applicationPartition != null);

      return default(bool);
    }
    public void CopyTo(ApplicationPartition[] applicationPartitions, int index)
    {
      Contract.Requires(applicationPartitions != null);

    }
 public void CopyTo(ApplicationPartition[] applicationPartitions, int index)
 {
     InnerList.CopyTo(applicationPartitions, index);
 }
예제 #21
0
		public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName)
		{
			DomainControllerInfo domainControllerInfo = null;
			string item;
			DirectoryContext newDirectoryContext = null;
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer())
					{
						if (distinguishedName != null)
						{
							if (distinguishedName.Length != 0)
							{
								if (Utils.IsValidDNFormat(distinguishedName))
								{
									context = new DirectoryContext(context);
									DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
									DirectoryEntry directoryEntry = null;
									try
									{
										directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryManager.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
									}
									catch (COMException cOMException1)
									{
										COMException cOMException = cOMException1;
										throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
									}
									catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
									{
										object[] name = new object[1];
										name[0] = context.Name;
										throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
									}
									StringBuilder stringBuilder = new StringBuilder(15);
									stringBuilder.Append("(&(");
									stringBuilder.Append(PropertyManager.ObjectCategory);
									stringBuilder.Append("=crossRef)(");
									stringBuilder.Append(PropertyManager.SystemFlags);
									stringBuilder.Append(":1.2.840.113556.1.4.804:=");
									stringBuilder.Append(1);
									stringBuilder.Append(")(!(");
									stringBuilder.Append(PropertyManager.SystemFlags);
									stringBuilder.Append(":1.2.840.113556.1.4.803:=");
									stringBuilder.Append(2);
									stringBuilder.Append("))(");
									stringBuilder.Append(PropertyManager.NCName);
									stringBuilder.Append("=");
									stringBuilder.Append(Utils.GetEscapedFilterValue(distinguishedName));
									stringBuilder.Append("))");
									string str = stringBuilder.ToString();
									string[] dnsRoot = new string[2];
									dnsRoot[0] = PropertyManager.DnsRoot;
									dnsRoot[1] = PropertyManager.NCName;
									ADSearcher aDSearcher = new ADSearcher(directoryEntry, str, dnsRoot, SearchScope.OneLevel, false, false);
									SearchResult searchResult = null;
									try
									{
										try
										{
											searchResult = aDSearcher.FindOne();
										}
										catch (COMException cOMException3)
										{
											COMException cOMException2 = cOMException3;
											if (cOMException2.ErrorCode != -2147016656)
											{
												throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
											}
											else
											{
												throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
											}
										}
									}
									finally
									{
										directoryEntry.Dispose();
									}
									if (searchResult != null)
									{
										string str1 = null;
										try
										{
											if (searchResult.Properties[PropertyManager.DnsRoot].Count > 0)
											{
												item = (string)searchResult.Properties[PropertyManager.DnsRoot][0];
											}
											else
											{
												item = null;
											}
											str1 = item;
										}
										catch (COMException cOMException5)
										{
											COMException cOMException4 = cOMException5;
											throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException4);
										}
										ApplicationPartitionType applicationPartitionType = ApplicationPartition.GetApplicationPartitionType(context);
										if (context.ContextType != DirectoryContextType.DirectoryServer)
										{
											if (applicationPartitionType != ApplicationPartitionType.ADApplicationPartition)
											{
												string name1 = ConfigurationSet.FindOneAdamInstance(context.Name, context, distinguishedName, null).Name;
												newDirectoryContext = Utils.GetNewDirectoryContext(name1, DirectoryContextType.DirectoryServer, context);
											}
											else
											{
												int num = Locator.DsGetDcNameWrapper(null, str1, null, (long)0x8000, out domainControllerInfo);
												if (num != 0x54b)
												{
													if (num == 0)
													{
														string str2 = domainControllerInfo.DomainControllerName.Substring(2);
														newDirectoryContext = Utils.GetNewDirectoryContext(str2, DirectoryContextType.DirectoryServer, context);
													}
													else
													{
														throw ExceptionHelper.GetExceptionFromErrorCode(num);
													}
												}
												else
												{
													throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
												}
											}
										}
										else
										{
											bool flag = false;
											DistinguishedName distinguishedName1 = new DistinguishedName(distinguishedName);
											DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
											try
											{
												try
												{
													foreach (string item1 in directoryEntry1.Properties[PropertyManager.NamingContexts])
													{
														DistinguishedName distinguishedName2 = new DistinguishedName(item1);
														if (!distinguishedName2.Equals(distinguishedName1))
														{
															continue;
														}
														flag = true;
														break;
													}
												}
												catch (COMException cOMException7)
												{
													COMException cOMException6 = cOMException7;
													throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException6);
												}
											}
											finally
											{
												directoryEntry1.Dispose();
											}
											if (flag)
											{
												newDirectoryContext = context;
											}
											else
											{
												throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
											}
										}
										ApplicationPartition applicationPartition = new ApplicationPartition(newDirectoryContext, (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.NCName), str1, applicationPartitionType, directoryEntryManager);
										return applicationPartition;
									}
									else
									{
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
									}
								}
								else
								{
									throw new ArgumentException(Res.GetString("InvalidDNFormat"), "distinguishedName");
								}
							}
							else
							{
								throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName");
							}
						}
						else
						{
							throw new ArgumentNullException("distinguishedName");
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}