コード例 #1
0
 public void Save()
 {
     this.CheckIfDisposed();
     if (!this.isBound)
     {
         try
         {
             if (this.schemaEntry == null)
             {
                 this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.SchemaNamingContext);
             }
             string escapedPath = Utils.GetEscapedPath("CN=" + this.commonName);
             this.classEntry = this.schemaEntry.Children.Add(escapedPath, "classSchema");
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
         }
         catch (ActiveDirectoryObjectNotFoundException)
         {
             throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { this.context.Name }));
         }
         this.SetProperty(PropertyManager.LdapDisplayName, this.ldapDisplayName);
         this.SetProperty(PropertyManager.GovernsID, this.oid);
         this.SetProperty(PropertyManager.Description, this.description);
         if (this.possibleSuperiors != null)
         {
             this.classEntry.Properties[PropertyManager.PossibleSuperiors].AddRange(this.possibleSuperiors.GetMultiValuedProperty());
         }
         if (this.mandatoryProperties != null)
         {
             this.classEntry.Properties[PropertyManager.MustContain].AddRange(this.mandatoryProperties.GetMultiValuedProperty());
         }
         if (this.optionalProperties != null)
         {
             this.classEntry.Properties[PropertyManager.MayContain].AddRange(this.optionalProperties.GetMultiValuedProperty());
         }
         if (this.subClassOf != null)
         {
             this.SetProperty(PropertyManager.SubClassOf, this.subClassOf.Name);
         }
         else
         {
             this.SetProperty(PropertyManager.SubClassOf, "top");
         }
         this.SetProperty(PropertyManager.ObjectClassCategory, this.type);
         if (this.schemaGuidBinaryForm != null)
         {
             this.SetProperty(PropertyManager.SchemaIDGuid, this.schemaGuidBinaryForm);
         }
         if (this.defaultSDSddlForm != null)
         {
             this.SetProperty(PropertyManager.DefaultSecurityDescriptor, this.defaultSDSddlForm);
         }
     }
     try
     {
         this.classEntry.CommitChanges();
         if (this.schema == null)
         {
             ActiveDirectorySchema schema    = ActiveDirectorySchema.GetSchema(this.context);
             bool            flag            = false;
             DirectoryServer schemaRoleOwner = null;
             try
             {
                 schemaRoleOwner = schema.SchemaRoleOwner;
                 if (Utils.Compare(schemaRoleOwner.Name, this.context.GetServerName()) != 0)
                 {
                     DirectoryContext context = Utils.GetNewDirectoryContext(schemaRoleOwner.Name, DirectoryContextType.DirectoryServer, this.context);
                     this.schema = ActiveDirectorySchema.GetSchema(context);
                 }
                 else
                 {
                     flag        = true;
                     this.schema = schema;
                 }
             }
             finally
             {
                 if (schemaRoleOwner != null)
                 {
                     schemaRoleOwner.Dispose();
                 }
                 if (!flag)
                 {
                     schema.Dispose();
                 }
             }
         }
         this.schema.RefreshSchema();
     }
     catch (COMException exception2)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception2);
     }
     this.isDefunctOnServer = this.isDefunct;
     this.commonName        = null;
     this.oid                                      = null;
     this.description                              = null;
     this.descriptionInitialized                   = false;
     this.possibleSuperiors                        = null;
     this.auxiliaryClasses                         = null;
     this.possibleInferiors                        = null;
     this.mandatoryProperties                      = null;
     this.optionalProperties                       = null;
     this.subClassOf                               = null;
     this.typeInitialized                          = false;
     this.schemaGuidBinaryForm                     = null;
     this.defaultSDSddlForm                        = null;
     this.defaultSDSddlFormInitialized             = false;
     this.propertiesFromSchemaContainerInitialized = false;
     this.isBound                                  = true;
 }
 public void Save()
 {
     this.CheckIfDisposed();
     if (!this.isBound)
     {
         try
         {
             if (this.schemaEntry == null)
             {
                 this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.SchemaNamingContext);
             }
             string escapedPath = Utils.GetEscapedPath("CN=" + this.commonName);
             this.propertyEntry = this.schemaEntry.Children.Add(escapedPath, "attributeSchema");
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
         }
         catch (ActiveDirectoryObjectNotFoundException)
         {
             throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { this.context.Name }));
         }
         this.SetProperty(PropertyManager.LdapDisplayName, this.ldapDisplayName);
         this.SetProperty(PropertyManager.AttributeID, this.oid);
         if (this.syntax != ~ActiveDirectorySyntax.CaseExactString)
         {
             this.SetSyntax(this.syntax);
         }
         this.SetProperty(PropertyManager.Description, this.description);
         this.propertyEntry.Properties[PropertyManager.IsSingleValued].Value = this.isSingleValued;
         this.propertyEntry.Properties[PropertyManager.IsMemberOfPartialAttributeSet].Value = this.isInGlobalCatalog;
         this.propertyEntry.Properties[PropertyManager.IsDefunct].Value = this.isDefunct;
         if (this.rangeLower.HasValue)
         {
             this.propertyEntry.Properties[PropertyManager.RangeLower].Value = this.rangeLower.Value;
         }
         if (this.rangeUpper.HasValue)
         {
             this.propertyEntry.Properties[PropertyManager.RangeUpper].Value = this.rangeUpper.Value;
         }
         if (this.searchFlags != SearchFlags.None)
         {
             this.propertyEntry.Properties[PropertyManager.SearchFlags].Value = (int)this.searchFlags;
         }
         if (this.linkId.HasValue)
         {
             this.propertyEntry.Properties[PropertyManager.LinkID].Value = this.linkId.Value;
         }
         if (this.schemaGuidBinaryForm != null)
         {
             this.SetProperty(PropertyManager.SchemaIDGuid, this.schemaGuidBinaryForm);
         }
     }
     try
     {
         this.propertyEntry.CommitChanges();
         if (this.schema == null)
         {
             ActiveDirectorySchema schema    = ActiveDirectorySchema.GetSchema(this.context);
             bool            flag            = false;
             DirectoryServer schemaRoleOwner = null;
             try
             {
                 schemaRoleOwner = schema.SchemaRoleOwner;
                 if (Utils.Compare(schemaRoleOwner.Name, this.context.GetServerName()) != 0)
                 {
                     DirectoryContext context = Utils.GetNewDirectoryContext(schemaRoleOwner.Name, DirectoryContextType.DirectoryServer, this.context);
                     this.schema = ActiveDirectorySchema.GetSchema(context);
                 }
                 else
                 {
                     flag        = true;
                     this.schema = schema;
                 }
             }
             finally
             {
                 if (schemaRoleOwner != null)
                 {
                     schemaRoleOwner.Dispose();
                 }
                 if (!flag)
                 {
                     schema.Dispose();
                 }
             }
         }
         this.schema.RefreshSchema();
     }
     catch (COMException exception2)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception2);
     }
     this.isDefunctOnServer = this.isDefunct;
     this.commonName        = null;
     this.oid = null;
     this.syntaxInitialized                        = false;
     this.descriptionInitialized                   = false;
     this.isSingleValuedInitialized                = false;
     this.isInGlobalCatalogInitialized             = false;
     this.rangeLowerInitialized                    = false;
     this.rangeUpperInitialized                    = false;
     this.searchFlagsInitialized                   = false;
     this.linkedPropertyInitialized                = false;
     this.linkIdInitialized                        = false;
     this.schemaGuidBinaryForm                     = null;
     this.propertiesFromSchemaContainerInitialized = false;
     this.isBound = true;
 }