示例#1
0
        /// <summary>
        /// Populates the object based on an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute attributeNameAttribute = node.Attributes["attribute"];
            XmlAttribute regexFindAttibute      = node.Attributes["regex-find"];
            XmlAttribute regexReplaceAttribute  = node.Attributes["regex-replace"];

            if (attributeNameAttribute == null || string.IsNullOrWhiteSpace(attributeNameAttribute.Value))
            {
                throw new ArgumentNullException("An attribute attribute must be specified");
            }
            else
            {
                MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value);
                this.Attribute = MASchema.Attributes[attributeNameAttribute.Value];
            }

            if (regexFindAttibute == null || string.IsNullOrWhiteSpace(regexFindAttibute.Value))
            {
                throw new ArgumentNullException("A regex-find attribute must be specified");
            }
            else
            {
                this.RegexFind = regexFindAttibute.Value;
            }

            if (regexReplaceAttribute == null || string.IsNullOrWhiteSpace(regexReplaceAttribute.Value))
            {
                throw new ArgumentNullException("A regex-replace attribute must be specified");
            }
            else
            {
                this.RegexReplace = regexReplaceAttribute.Value;
            }
        }
        /// <summary>
        /// Populates the rule based on an XML representation of the object
        /// </summary>
        /// <param name="node">The XmlNode representation of the object</param>
        protected override void FromXml(XmlNode node)
        {
            base.FromXml(node);

            XmlAttribute attributeNameAttribute = node.Attributes["attribute"];
            XmlAttribute triggerAttribute       = node.Attributes["triggers"];

            if (attributeNameAttribute == null || triggerAttribute == null)
            {
                throw new ArgumentException("The attribute name and trigger must be specified");
            }

            MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value);
            this.AttributeName = attributeNameAttribute.Value;

            TriggerEvents events;

            if (Enum.TryParse(triggerAttribute.Value, true, out events))
            {
                this.TriggerEvents = events;
            }
            else
            {
                throw new ArgumentException("The trigger value is unknown or unsupported");
            }
        }
        /// <summary>
        /// Populates the RuleSet object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        protected override void FromXml(XmlNode node)
        {
            base.FromXml(node);

            XmlAttribute attributeNameAttribute = node.Attributes["attribute"];
            XmlAttribute operatorAttribute      = node.Attributes["operator"];
            XmlAttribute valueAttribute         = node.Attributes["value"];

            if (attributeNameAttribute == null)
            {
                throw new ArgumentNullException("The 'attribute' attribute must be specified");
            }
            else
            {
                MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value);
                this.AttributeName = attributeNameAttribute.Value;
            }

            ValueOperator valueOperator = ValueOperator.Equals;

            if (Enum.TryParse(operatorAttribute.Value, true, out valueOperator))
            {
                this.Operator = valueOperator;
            }
            else
            {
                throw new ArgumentException(string.Format("The value operator '{0}' is unknown", operatorAttribute.Value));
            }

            if (valueAttribute != null)
            {
                this.Value = valueAttribute.Value;
            }
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the MASchemaObject class
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        public MASchemaObject(XmlNode node)
            : this()
        {
            XmlAttribute objectClassAttribute = node.Attributes["object-class"];

            if (objectClassAttribute == null || string.IsNullOrWhiteSpace(objectClassAttribute.Value))
            {
                throw new ArgumentException("The schema-entry element must have a 'object-class' attribute");
            }

            this.ObjectClass = objectClassAttribute.Value;

            XmlNode dnConstructor = node.SelectSingleNode("dn-format");

            this.DNFormat = new ValueDeclaration(dnConstructor);

            if (string.IsNullOrWhiteSpace(this.DNFormat.DeclarationText) || this.DNFormat.AttributeReferences.Count == 0)
            {
                throw new ArgumentNullException("A dn-format attribute must be specified and contain at least one attribute reference");
            }

            foreach (XmlNode child in node.SelectNodes("attributes/attribute"))
            {
                MASchema.ThrowOnMissingAttribute(child.InnerText);

                this.Attributes.Add(MASchema.Attributes[child.InnerText]);

                if (MASchema.Attributes[child.InnerText].CanResurrect)
                {
                    this.ResurrectionAttributes.Add(MASchema.Attributes[child.InnerText]);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Populates the object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute attributeNameAttribute = node.Attributes["attribute"];
            XmlAttribute operatorAttribute      = node.Attributes["operator"];

            if (attributeNameAttribute == null)
            {
                throw new ArgumentNullException("The 'attribute' attribute must be specified");
            }
            else
            {
                MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value);
                this.Attribute = MASchema.Attributes[attributeNameAttribute.Value];
            }

            ValueOperator valueOperator = ValueOperator.Equals;

            if (Enum.TryParse(operatorAttribute.Value, true, out valueOperator))
            {
                this.Operator = valueOperator;
            }
            else
            {
                throw new ArgumentException(string.Format("The value operator '{0}' is unknown", operatorAttribute.Value));
            }

            this.Value = node.InnerText;
        }
        /// <summary>
        /// Populates the object from its XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute captureGroupAttribute  = node.Attributes["capture-group-name"];
            XmlAttribute attributeNameAttribute = node.Attributes["attribute"];

            if (attributeNameAttribute == null || string.IsNullOrWhiteSpace(attributeNameAttribute.Value))
            {
                throw new ArgumentNullException("The 'attribute' attribute must be specified");
            }
            else
            {
                MASchema.ThrowOnMissingAttribute(attributeNameAttribute.Value);
                this.Attribute = MASchema.Attributes[attributeNameAttribute.Value];
            }

            if (captureGroupAttribute == null || string.IsNullOrWhiteSpace(captureGroupAttribute.Value))
            {
                throw new ArgumentNullException("The 'capture-group-name' attribute must be specified");
            }
            else
            {
                this.CaptureGroupName = captureGroupAttribute.Value;
            }

            if (string.IsNullOrWhiteSpace(node.InnerText))
            {
                throw new ArgumentNullException("A regular expression capture must be specified");
            }

            this.MappingRegEx = node.InnerText;
        }
示例#7
0
        /// <summary>
        /// Extracts the reference declarations referenced in the specified text
        /// </summary>
        /// <param name="value">The string to extract the attributes from</param>
        private void ExtractAttributeReferences(string value)
        {
            this.AttributeReferences.Clear();

            Regex           regex   = new Regex(@"\[(?<preText>[^\]\[]*?)\{((?<referenceAttributeName>\w+)->)?(?<attributeName>\w+)(\:(?<modifier>([^\d]))?(?<count>\d?))?\}(?<postText>.*?)\]|\{((?<referenceAttributeName>\w+)->)?(?<attributeName>(sshma\:)?\w+)(\:(?<modifier>([^\d]))?(?<count>\d?))?\}", RegexOptions.ExplicitCapture);
            MatchCollection matches = regex.Matches(value);

            foreach (Match match in matches)
            {
                ReferencedAttribute reference = new ReferencedAttribute();

                if (match.Groups["attributeName"] != null)
                {
                    MASchema.ThrowOnMissingAttribute(match.Groups["attributeName"].Value);
                    reference.AttributeName = match.Groups["attributeName"].Value;

                    if (match.Groups["count"] != null && !string.IsNullOrWhiteSpace(match.Groups["count"].Value))
                    {
                        if (MASchema.GetAttributeType(reference.AttributeName) != AttributeType.Reference)
                        {
                            throw new ArgumentException("A count value is only valid on a 'dn' or reference attribute");
                        }

                        reference.Count = int.Parse(match.Groups["count"].Value);
                    }

                    if (match.Groups["modifier"] != null && !string.IsNullOrWhiteSpace(match.Groups["modifier"].Value))
                    {
                        if (MASchema.GetAttributeType(reference.AttributeName) != AttributeType.Reference)
                        {
                            throw new ArgumentException("A modifier value is only valid on a 'dn' or reference attribute");
                        }

                        reference.Modifier = match.Groups["modifier"].Value;
                    }

                    if (match.Groups["referenceAttributeName"] != null && !string.IsNullOrWhiteSpace(match.Groups["referenceAttributeName"].Value))
                    {
                        throw new NotSupportedException("This MA does not support referenced attribute declarations");
                    }

                    if (match.Groups["preText"] != null)
                    {
                        reference.PreReferenceString = match.Groups["preText"].Value;
                    }

                    if (match.Groups["postText"] != null)
                    {
                        reference.PostReferenceString = match.Groups["postText"].Value;
                    }

                    reference.Declaration = match.Value;
                    this.AttributeReferences.Add(reference);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Retrieves the reference value from the specified object
        /// </summary>
        /// <param name="csentry">The source object</param>
        /// <param name="reference">The ReferencedAttribute to obtain the value for</param>
        /// <param name="throwOnMissingAttribute">Sets a value indicating whether an exception should be thrown if an attribute is not present in the CSEntryChange, otherwise replaces the declaration with an empty string</param>
        /// <param name="obfuscatePasswordFields">A value indicating if passwords should be obfuscated in the resulting output. Typically used for logging purposes</param>
        /// <returns>The value of the specified reference on the source object</returns>
        private string GetSourceAttributeValue(CSEntryChange csentry, ReferencedAttribute reference, bool throwOnMissingAttribute, bool obfuscatePasswordFields)
        {
            string sourceAttributeValue = string.Empty;

            if (MASchema.GetAttributeType(reference.AttributeName) == AttributeType.Reference)
            {
                return(this.GetReferencedDNComponent(csentry, reference));
            }

            if (csentry.AttributeChanges.Contains(reference.AttributeName))
            {
                ValueChange valueChange = csentry.AttributeChanges[reference.AttributeName].ValueChanges.FirstOrDefault(t => t.ModificationType == ValueModificationType.Add);

                if (valueChange != null)
                {
                    sourceAttributeValue = reference.PreReferenceString + valueChange.Value.ToString() + reference.PostReferenceString;
                }
            }
            else if (reference.AttributeName.StartsWith("sshma"))
            {
                switch (reference.AttributeName)
                {
                case "sshma:username":
                    return(ManagementAgent.MAParameters.Username);

                case "sshma:password":
                    if (obfuscatePasswordFields)
                    {
                        return("#hiddenpassword#");
                    }
                    else
                    {
                        return(ManagementAgent.MAParameters.GetPassword());
                    }
                }
            }
            else
            {
                if (throwOnMissingAttribute)
                {
                    throw new AttributeNotPresentException(reference.AttributeName);
                }
            }

            return(sourceAttributeValue);
        }
示例#9
0
        /// <summary>
        /// Gets an enumeration of expanded attribute value declarations for a multi-valued attribute
        /// </summary>
        /// <param name="csentry">The source object</param>
        /// <param name="multiValuedAttribute">The multi-valued attribute to expand</param>
        /// <param name="modificationType">Specifies which value modification types to expand during the enumeration</param>
        /// <returns>An enumeration of expanded declaration strings</returns>
        public IEnumerable <string> ExpandDeclarationWithMultiValued(CSEntryChange csentry, MASchemaAttribute multiValuedAttribute, ValueModificationType modificationType)
        {
            if (csentry == null)
            {
                yield return(this.DeclarationText);
            }

            string constructedValue = this.DeclarationText;

            foreach (ReferencedAttribute reference in this.AttributeReferences.Where(t => t.AttributeName != multiValuedAttribute.Name))
            {
                if (MASchema.GetAttributeType(reference.AttributeName) == AttributeType.Reference)
                {
                    constructedValue = constructedValue.Replace(reference.Declaration, this.GetReferencedDNComponent(csentry, reference));
                }
                else
                {
                    constructedValue = constructedValue.Replace(reference.Declaration, this.GetSourceAttributeValue(csentry, reference, false, false) ?? string.Empty);
                }
            }

            ReferencedAttribute mvattribute = this.AttributeReferences.FirstOrDefault(t => t.AttributeName == multiValuedAttribute.Name);

            if (mvattribute != null && csentry.AttributeChanges.Contains(multiValuedAttribute.Name))
            {
                AttributeChange change = csentry.AttributeChanges[multiValuedAttribute.Name];

                foreach (string value in this.GetSourceAttributeValues(change, mvattribute, modificationType))
                {
                    yield return(constructedValue.Replace(mvattribute.Declaration, value));
                }
            }
            else
            {
                yield return(constructedValue);
            }

            yield break;
        }
示例#10
0
        /// <summary>
        /// Reads the schema rootNode from the configuration file
        /// </summary>
        /// <param name="rootNode">The root rootNode of the Xml document</param>
        private static void ReadSchemaNode(XmlNode rootNode)
        {
            XmlNode node = rootNode.SelectSingleNode("schema");

            MASchema.FromXml(node);
        }
示例#11
0
        /// <summary>
        /// Populates the object from an XML representation
        /// </summary>
        /// <param name="node">The XML representation of the object</param>
        private void FromXml(XmlNode node)
        {
            XmlAttribute successCodes     = node.Attributes["success-codes"];
            XmlAttribute forEachAttribute = node.Attributes["for-each"];
            XmlAttribute valueModificationTypeAttribute = node.Attributes["value-modification"];
            XmlAttribute hasObjectsAttribute            = node.Attributes["result-has-objects"];

            if (hasObjectsAttribute != null && !string.IsNullOrWhiteSpace(hasObjectsAttribute.Value))
            {
                bool hasObjects = false;
                if (bool.TryParse(hasObjectsAttribute.Value, out hasObjects))
                {
                    this.HasObjects = hasObjects;
                }
                else
                {
                    throw new ArgumentException("The boolean value could not be parsed: " + hasObjectsAttribute.Value);
                }
            }

            if (forEachAttribute != null && !string.IsNullOrWhiteSpace(forEachAttribute.Value))
            {
                MASchema.ThrowOnMissingAttribute(forEachAttribute.Value);
                this.ForEachAttribute = MASchema.Attributes[forEachAttribute.Value];
            }

            if (successCodes != null)
            {
                string[] split = successCodes.Value.Split(',');
                foreach (string value in split)
                {
                    int result = 0;

                    if (int.TryParse(value, out result))
                    {
                        this.SuccessCodes.Add(result);
                    }
                    else
                    {
                        throw new ArgumentException("The specified success code value cannot be converted to an integer: " + value);
                    }
                }
            }

            if (this.SuccessCodes.Count == 0)
            {
                this.SuccessCodes.Add(0);
            }

            if (valueModificationTypeAttribute == null || string.IsNullOrWhiteSpace(valueModificationTypeAttribute.Value))
            {
                this.ForEachValueModificationType = ValueModificationType.Unconfigured;
            }
            else
            {
                ValueModificationType valueModificationType = ValueModificationType.Unconfigured;
                if (Enum.TryParse(valueModificationTypeAttribute.Value, true, out valueModificationType))
                {
                    this.ForEachValueModificationType = valueModificationType;
                }
                else
                {
                    throw new ArgumentException("The value modification type is unknown: " + valueModificationTypeAttribute.Value);
                }
            }

            this.Command = new ValueDeclaration(node);
        }