Exemplo n.º 1
0
        /// <summary>
        /// Replace all values of 'attrName' with the empty string.
        /// </summary>
        /// <param name="propName">The name of the property / attribute to clear</param>
        public void ClearAttr(string attrName)
        {
            CheckForDeletion();
            attrName = attrName.ToLowerInvariant();

            if (this.GetAttrValueCount(attrName) > 0)
            {
                DirectoryAttributeModification dam;
                if (_changes.ContainsKey(attrName))
                {
                    dam = _changes[attrName];
                    if (dam.Operation == DirectoryAttributeOperation.Replace)
                    {
                        if (dam.Count == 0)
                        {
                            logger.Debug("Already contains request to set {0} with Replace/Clear", attrName);
                            return;
                        }
                    }

                    if (this.ConflictMode == ConflictModes.Error)
                    {
                        throw new IncompatibleMutationException(String.Format(
                                                                    "Change buffer already contains a non-blank request to modify attr {0} as {1}",
                                                                    attrName, dam.Operation));
                    }
                    else
                    {
                        logger.Info("Overriding non-blank {0} request on attr {1} with Replace/Clear",
                                    dam.Operation, attrName);


                        dam = new DirectoryAttributeModification()
                        {
                            Name = attrName, Operation = DirectoryAttributeOperation.Replace
                        };
                        dam.Clear();
                        _changes[attrName] = dam;

                        /*
                         * dam = new DirectoryAttributeModification() { Name = propName, Operation = DirectoryAttributeOperation.Delete };
                         * _changes[propName] = dam;
                         */
                        if (_changes.ContainsKey(attrName + "*d"))
                        {
                            logger.Warn("Removing useless single-value deletion on attr {0}", attrName);
                            _changes.Remove(attrName + "*d");
                        }
                    }
                }
                else
                {
                    dam = new DirectoryAttributeModification()
                    {
                        Name = attrName, Operation = DirectoryAttributeOperation.Replace
                    };
                    dam.Clear();
                    _changes[attrName] = dam;

                    logger.Debug("Set Replace/Clear on attr {0}", attrName);

                    if (_changes.ContainsKey(attrName + "*d"))
                    {
                        logger.Warn("Removing useless single-value deletion on attr {0}");
                        _changes.Remove(attrName + "*d");
                    }
                }
            }
        }