当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryContext.isRootDomain方法代码示例

本文整理汇总了C#中System.DirectoryServices.ActiveDirectory.DirectoryContext.isRootDomain方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryContext.isRootDomain方法的具体用法?C# DirectoryContext.isRootDomain怎么用?C# DirectoryContext.isRootDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DirectoryServices.ActiveDirectory.DirectoryContext的用法示例。


在下文中一共展示了DirectoryContext.isRootDomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ActiveDirectorySchemaProperty

 public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName)
 {
     this.syntax = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId = null;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (ldapDisplayName == null)
     {
         throw new ArgumentNullException("ldapDisplayName");
     }
     if (ldapDisplayName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
     }
     this.context = new DirectoryContext(context);
     this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
     this.schemaEntry.Bind(true);
     this.ldapDisplayName = ldapDisplayName;
     this.commonName = ldapDisplayName;
     this.isBound = false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:ActiveDirectorySchemaProperty.cs

示例2: ActiveDirectorySchemaClass

        public ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayName)
        {
            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 or a server
                if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || (context.isServer())))
                {
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
                }
            }

            if (ldapDisplayName == null)
            {
                throw new ArgumentNullException("ldapDisplayName");
            }

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

            _context = new DirectoryContext(context);

            // validate the context 
            _schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
            _schemaEntry.Bind(true);

            _ldapDisplayName = ldapDisplayName;
            // the common name will default to the ldap display name
            _commonName = ldapDisplayName;

            // set the bind flag
            this.isBound = false;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:44,代码来源:ActiveDirectorySchemaClass.cs

示例3: GetForest

 public static Forest GetForest(DirectoryContext context)
 {
     DirectoryEntryManager directoryEntryMgr = null;
     DirectoryEntry rootDSE = null;
     string distinguishedName = null;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.ContextType != DirectoryContextType.Forest) && (context.ContextType != DirectoryContextType.DirectoryServer))
     {
         throw new ArgumentException(Res.GetString("TargetShouldBeServerORForest"), "context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(Forest), null);
     }
     if (((context.Name != null) && !context.isRootDomain()) && !context.isServer())
     {
         if (context.ContextType == DirectoryContextType.Forest)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(Forest), context.Name);
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Forest), null);
     }
     context = new DirectoryContext(context);
     directoryEntryMgr = new DirectoryEntryManager(context);
     try
     {
         rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
         if (context.isServer() && !Utils.CheckCapability(rootDSE, Capability.ActiveDirectory))
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Forest), null);
         }
         distinguishedName = (string) PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext);
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode != -2147016646)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         if (context.ContextType == DirectoryContextType.Forest)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(Forest), context.Name);
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Forest), null);
     }
     return new Forest(context, Utils.GetDnsNameFromDN(distinguishedName), directoryEntryMgr);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:50,代码来源:Forest.cs

示例4: GetSchema

        public static ActiveDirectorySchema GetSchema(DirectoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // contexttype should be Forest, DirectoryServer or ConfigurationSet
            if ((context.ContextType != DirectoryContextType.Forest) &&
                (context.ContextType != DirectoryContextType.ConfigurationSet) &&
                (context.ContextType != DirectoryContextType.DirectoryServer))
            {
                throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
            }

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

            if (context.Name != null)
            {
                // the target should be a valid forest name or a server
                if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || (context.isServer())))
                {
                    if (context.ContextType == DirectoryContextType.Forest)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ForestNotFound), typeof(ActiveDirectorySchema), context.Name);
                    }
                    else if (context.ContextType == DirectoryContextType.ConfigurationSet)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ConfigSetNotFound), typeof(ActiveDirectorySchema), context.Name);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ServerNotFound, context.Name), typeof(ActiveDirectorySchema), null);
                    }
                }
            }

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

            DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
            string schemaNC = null;
            try
            {
                DirectoryEntry rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);

                if ((context.isServer()) && (!Utils.CheckCapability(rootDSE, Capability.ActiveDirectoryOrADAM)))
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ServerNotFound, context.Name), typeof(ActiveDirectorySchema), null);
                }

                schemaNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.SchemaNamingContext);
            }
            catch (COMException e)
            {
                int errorCode = e.ErrorCode;

                if (errorCode == unchecked((int)0x8007203a))
                {
                    if (context.ContextType == DirectoryContextType.Forest)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ForestNotFound), typeof(ActiveDirectorySchema), context.Name);
                    }
                    else if (context.ContextType == DirectoryContextType.ConfigurationSet)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ConfigSetNotFound), typeof(ActiveDirectorySchema), context.Name);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ServerNotFound, context.Name), typeof(ActiveDirectorySchema), null);
                    }
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                if (context.ContextType == DirectoryContextType.ConfigurationSet)
                {
                    // 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 ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ConfigSetNotFound), typeof(ActiveDirectorySchema), context.Name);
                }
                else
                    throw;
            }

            return new ActiveDirectorySchema(context, schemaNC, directoryEntryMgr);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:93,代码来源:ActiveDirectorySchema.cs

示例5: ActiveDirectorySchemaClass

		public ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayName)
		{
			this.type = SchemaClassType.Structural;
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer())
					{
						if (ldapDisplayName != null)
						{
							if (ldapDisplayName.Length != 0)
							{
								this.context = new DirectoryContext(context);
								this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
								//TODO: REVIEW: URGENT!!:this.schemaEntry.Bind(true);
								this.ldapDisplayName = ldapDisplayName;
								this.commonName = ldapDisplayName;
								this.isBound = false;
								return;
							}
							else
							{
								throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
							}
						}
						else
						{
							throw new ArgumentNullException("ldapDisplayName");
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:46,代码来源:ActiveDirectorySchemaClass.cs

示例6: FindByName

        public static ActiveDirectorySchemaClass FindByName(DirectoryContext context, string ldapDisplayName)
        {
            ActiveDirectorySchemaClass schemaClass = 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)
            {
                if (!(context.isRootDomain() || context.isServer() || context.isADAMConfigSet()))
                {
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
                }
            }

            if (ldapDisplayName == null)
            {
                throw new ArgumentNullException("ldapDisplayName");
            }

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

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

            // create a schema class 
            schemaClass = new ActiveDirectorySchemaClass(context, ldapDisplayName, (DirectoryEntry)null, null);

            return schemaClass;
        }
开发者ID:chcosta,项目名称:corefx,代码行数:40,代码来源:ActiveDirectorySchemaClass.cs

示例7: GetForest

		public static Forest GetForest(DirectoryContext context)
		{
			string propertyValue = null;
			if (context != null)
			{
				if (context.ContextType == DirectoryContextType.Forest || context.ContextType == DirectoryContextType.DirectoryServer)
				{
					if (context.Name != null || context.isRootDomain())
					{
						if (context.Name == null || context.isRootDomain() || context.isServer())
						{
							context = new DirectoryContext(context);
							DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
							try
							{
								DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
								if (!context.isServer() || Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectory))
								{
									propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.RootDomainNamingContext);
								}
								else
								{
									object[] name = new object[1];
									name[0] = context.Name;
									throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", name), typeof(Forest), null);
								}
							}
							catch (COMException cOMException1)
							{
								COMException cOMException = cOMException1;
								int errorCode = cOMException.ErrorCode;
								if (errorCode != -2147016646)
								{
									throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
								}
								else
								{
									if (context.ContextType != DirectoryContextType.Forest)
									{
										object[] objArray = new object[1];
										objArray[0] = context.Name;
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", objArray), typeof(Forest), null);
									}
									else
									{
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(Forest), context.Name);
									}
								}
							}
							return new Forest(context, Utils.GetDnsNameFromDN(propertyValue), directoryEntryManager);
						}
						else
						{
							if (context.ContextType != DirectoryContextType.Forest)
							{
								object[] name1 = new object[1];
								name1[0] = context.Name;
								throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", name1), typeof(Forest), null);
							}
							else
							{
								throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(Forest), context.Name);
							}
						}
					}
					else
					{
						throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(Forest), null);
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("TargetShouldBeServerORForest"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:80,代码来源:Forest.cs

示例8: FindByTransportType

		public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
		{
			DirectoryEntry directoryEntry;
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isServer() || context.isADAMConfigSet())
					{
						if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
						{
							throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
						}
						else
						{
							context = new DirectoryContext(context);
							try
							{
								directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
								string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
								string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue);
								if (transport != ActiveDirectoryTransportType.Rpc)
								{
									str = string.Concat("CN=SMTP,", str);
								}
								else
								{
									str = string.Concat("CN=IP,", str);
								}
								directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
							}
							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));
							}
							try
							{
								string[] strArrays = new string[1];
								strArrays[0] = "options";
								directoryEntry.RefreshCache(strArrays);
							}
							catch (COMException cOMException3)
							{
								COMException cOMException2 = cOMException3;
								if (cOMException2.ErrorCode != -2147016656)
								{
									throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
								}
								else
								{
									DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
									if (!Utils.CheckCapability(directoryEntry1, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp)
									{
										object[] objArray = new object[1];
										objArray[0] = transport.ToString();
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("TransportNotFound", objArray), typeof(ActiveDirectoryInterSiteTransport), transport.ToString());
									}
									else
									{
										throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
									}
								}
							}
							return new ActiveDirectoryInterSiteTransport(context, transport, directoryEntry);
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:88,代码来源:ActiveDirectoryInterSiteTransport.cs

示例9: GetSchema

 public static ActiveDirectorySchema GetSchema(DirectoryContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (((context.ContextType != DirectoryContextType.Forest) && (context.ContextType != DirectoryContextType.ConfigurationSet)) && (context.ContextType != DirectoryContextType.DirectoryServer))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(ActiveDirectorySchema), null);
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
     {
         if (context.ContextType == DirectoryContextType.Forest)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name);
         }
         if (context.ContextType == DirectoryContextType.ConfigurationSet)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null);
     }
     context = new DirectoryContext(context);
     DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
     string distinguishedName = null;
     try
     {
         DirectoryEntry cachedDirectoryEntry = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
         if (context.isServer() && !Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryOrADAM))
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null);
         }
         distinguishedName = (string) PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode != -2147016646)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         if (context.ContextType == DirectoryContextType.Forest)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name);
         }
         if (context.ContextType == DirectoryContextType.ConfigurationSet)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", new object[] { context.Name }), typeof(ActiveDirectorySchema), null);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         if (context.ContextType == DirectoryContextType.ConfigurationSet)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
         }
         throw;
     }
     return new ActiveDirectorySchema(context, distinguishedName, directoryEntryMgr);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:64,代码来源:ActiveDirectorySchema.cs

示例10: ValidateArgument

		private static void ValidateArgument(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
		{
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isServer() || context.isADAMConfigSet())
					{
						if (bridgeName != null)
						{
							if (bridgeName.Length != 0)
							{
								if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
								{
									throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
								}
								else
								{
									return;
								}
							}
							else
							{
								throw new ArgumentException(Res.GetString("EmptyStringParameter"), "bridgeName");
							}
						}
						else
						{
							throw new ArgumentNullException("bridgeName");
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:46,代码来源:ActiveDirectorySiteLinkBridge.cs

示例11: FindByName

		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);
										}
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:ApplicationPartition.cs

示例12: ValidateArgument

 private static void ValidateArgument(DirectoryContext context, string subnetName)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isServer() && !context.isADAMConfigSet()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (subnetName == null)
     {
         throw new ArgumentNullException("subnetName");
     }
     if (subnetName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "subnetName");
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:ActiveDirectorySubnet.cs

示例13: GetForest

        public static Forest GetForest(DirectoryContext context)
        {
            DirectoryEntryManager directoryEntryMgr = null;
            DirectoryEntry rootDSE = null;
            string rootDomainNC = null;

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

            // contexttype should be Forest or DirectoryServer
            if ((context.ContextType != DirectoryContextType.Forest) &&
                (context.ContextType != DirectoryContextType.DirectoryServer))
            {
                throw new ArgumentException(Res.GetString(Res.TargetShouldBeServerORForest), "context");
            }

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

            if (context.Name != null)
            {
                // the target should be a valid forest name or a server
                if (!((context.isRootDomain()) || (context.isServer())))
                {
                    if (context.ContextType == DirectoryContextType.Forest)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ForestNotFound), typeof(Forest), context.Name);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Forest), null);
                    }
                }
            }

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

            directoryEntryMgr = new DirectoryEntryManager(context);
            // at this point we know that the target is either a 
            // valid forest name or a server (may be a bogus server name -- to check bind to rootdse)
            // bind to the rootDSE of the forest specified in the context
            try
            {
                rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
                if ((context.isServer()) && (!Utils.CheckCapability(rootDSE, Capability.ActiveDirectory)))
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Forest), null);
                }
                rootDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.RootDomainNamingContext);
            }
            catch (COMException e)
            {
                int errorCode = e.ErrorCode;

                if (errorCode == unchecked((int)0x8007203a))
                {
                    if (context.ContextType == DirectoryContextType.Forest)
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ForestNotFound), typeof(Forest), context.Name);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Forest), null);
                    }
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }

            // return forest object

            return new Forest(context, Utils.GetDnsNameFromDN(rootDomainNC), directoryEntryMgr);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:79,代码来源:Forest.cs

示例14: FindByName

 public static ApplicationPartition FindByName(DirectoryContext context, string distinguishedName)
 {
     DirectoryEntryManager directoryEntryMgr = null;
     DirectoryContext context2 = null;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (distinguishedName == null)
     {
         throw new ArgumentNullException("distinguishedName");
     }
     if (distinguishedName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "distinguishedName");
     }
     if (!Utils.IsValidDNFormat(distinguishedName))
     {
         throw new ArgumentException(Res.GetString("InvalidDNFormat"), "distinguishedName");
     }
     context = new DirectoryContext(context);
     directoryEntryMgr = new DirectoryEntryManager(context);
     DirectoryEntry searchRoot = null;
     try
     {
         searchRoot = DirectoryEntryManager.GetDirectoryEntry(context, directoryEntryMgr.ExpandWellKnownDN(WellKnownDN.PartitionsContainer));
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     StringBuilder builder = new StringBuilder(15);
     builder.Append("(&(");
     builder.Append(PropertyManager.ObjectCategory);
     builder.Append("=crossRef)(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.804:=");
     builder.Append(1);
     builder.Append(")(!(");
     builder.Append(PropertyManager.SystemFlags);
     builder.Append(":1.2.840.113556.1.4.803:=");
     builder.Append(2);
     builder.Append("))(");
     builder.Append(PropertyManager.NCName);
     builder.Append("=");
     builder.Append(Utils.GetEscapedFilterValue(distinguishedName));
     builder.Append("))");
     string filter = builder.ToString();
     string[] propertiesToLoad = new string[] { PropertyManager.DnsRoot, PropertyManager.NCName };
     ADSearcher searcher = new ADSearcher(searchRoot, filter, propertiesToLoad, SearchScope.OneLevel, false, false);
     SearchResult res = null;
     try
     {
         res = searcher.FindOne();
     }
     catch (COMException exception2)
     {
         if (exception2.ErrorCode == -2147016656)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
     }
     finally
     {
         searchRoot.Dispose();
     }
     if (res == null)
     {
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("AppNCNotFound"), typeof(ApplicationPartition), distinguishedName);
     }
     string domainName = null;
     try
     {
         domainName = (res.Properties[PropertyManager.DnsRoot].Count > 0) ? ((string) res.Properties[PropertyManager.DnsRoot][0]) : null;
     }
     catch (COMException exception3)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
     }
     ApplicationPartitionType applicationPartitionType = GetApplicationPartitionType(context);
     if (context.ContextType != DirectoryContextType.DirectoryServer)
     {
         if (applicationPartitionType == ApplicationPartitionType.ADApplicationPartition)
         {
             DomainControllerInfo info;
             int errorCode = 0;
             errorCode = Locator.DsGetDcNameWrapper(null, domainName, null, 0x8000L, out info);
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ApplicationPartition.cs

示例15: GetSchema

		public static ActiveDirectorySchema GetSchema(DirectoryContext context)
		{
			if (context != null)
			{
				if (context.ContextType == DirectoryContextType.Forest || context.ContextType == DirectoryContextType.ConfigurationSet || context.ContextType == DirectoryContextType.DirectoryServer)
				{
					if (context.Name != null || context.isRootDomain())
					{
						if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer())
						{
							context = new DirectoryContext(context);
							DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
							string propertyValue = null;
							try
							{
								DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
								if (!context.isServer() || Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectoryOrADAM))
								{
									propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.SchemaNamingContext);
								}
								else
								{
									object[] name = new object[1];
									name[0] = context.Name;
									throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", name), typeof(ActiveDirectorySchema), null);
								}
							}
							catch (COMException cOMException1)
							{
								COMException cOMException = cOMException1;
								int errorCode = cOMException.ErrorCode;
								if (errorCode != -2147016646)
								{
									throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
								}
								else
								{
									if (context.ContextType != DirectoryContextType.Forest)
									{
										if (context.ContextType != DirectoryContextType.ConfigurationSet)
										{
											object[] objArray = new object[1];
											objArray[0] = context.Name;
											throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", objArray), typeof(ActiveDirectorySchema), null);
										}
										else
										{
											throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
										}
									}
									else
									{
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name);
									}
								}
							}
							catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
							{
								if (context.ContextType != DirectoryContextType.ConfigurationSet)
								{
									throw;
								}
								else
								{
									throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
								}
							}
							return new ActiveDirectorySchema(context, propertyValue, directoryEntryManager);
						}
						else
						{
							if (context.ContextType != DirectoryContextType.Forest)
							{
								if (context.ContextType != DirectoryContextType.ConfigurationSet)
								{
									object[] name1 = new object[1];
									name1[0] = context.Name;
									throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ServerNotFound", name1), typeof(ActiveDirectorySchema), null);
								}
								else
								{
									throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ConfigSetNotFound"), typeof(ActiveDirectorySchema), context.Name);
								}
							}
							else
							{
								throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestNotFound"), typeof(ActiveDirectorySchema), context.Name);
							}
						}
					}
					else
					{
						throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(ActiveDirectorySchema), null);
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
				}
			}
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:ActiveDirectorySchema.cs


注:本文中的System.DirectoryServices.ActiveDirectory.DirectoryContext.isRootDomain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。