/// <summary>
        /// Populates the internal definition of the schema based on the representation contained in the metadata set
        /// </summary>
        /// <param name="set">The metadata set describing the schema</param>
        private static void PopulateSchemaFromMetadata(MetadataSet set)
        {
            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            if (set.MetadataSections.Count != 1)
            {
                throw new NotSupportedException("The metadata returned from the resource management service did not contain the expected number of sections");
            }

            MetadataSection section = set.MetadataSections[0];

            XmlSchema metadata = section.Metadata as XmlSchema;

            if (metadata == null)
            {
                throw new NotSupportedException("The metadata returned from the resource management service did not contain the expected metadata section");
            }

            ResourceManagementSchema.ObjectTypes.Clear();

            foreach (XmlSchemaComplexType complexType in metadata.Items.OfType <XmlSchemaComplexType>())
            {
                if (!ResourceManagementSchema.ElementsToIgnore.Contains(complexType.Name))
                {
                    ObjectTypeDefinition definition = new ObjectTypeDefinition(complexType);
                    ResourceManagementSchema.ObjectTypes.TryAdd(definition.SystemName, definition);
                }
            }
        }
        /// <summary>
        /// Populates the ResourceObject from a partial response to a Get request
        /// </summary>
        /// <param name="objectElements">A collection of XmlElements defining the object</param>
        private void PopulateResourceFromPartialResponse(IEnumerable<XmlElement> objectElements)
        {
            Dictionary<string, List<string>> values = new Dictionary<string, List<string>>();

            foreach (XmlElement partialAttributeElement in objectElements.Where(t => t.LocalName == "PartialAttribute"))
            {
                foreach (XmlElement attributeElement in partialAttributeElement.ChildNodes.OfType<XmlElement>())
                {
                    if (!values.ContainsKey(attributeElement.LocalName))
                    {
                        values.Add(attributeElement.LocalName, new List<string>());
                    }

                    values[attributeElement.LocalName].Add(attributeElement.InnerText);
                }
            }

            if (values.ContainsKey(AttributeNames.ObjectType))
            {
                string objectTypeName = values[AttributeNames.ObjectType].First();
                ObjectTypeDefinition objectType = ResourceManagementSchema.ObjectTypes[objectTypeName];
                this.ObjectType = objectType;
            }
            else
            {
                throw new ArgumentException("No object type was specified in the response");
            }

            this.SetInitialAttributeValues(values);
        }
        private static void LoadNameValidationRegularExpressions()
        {
            ObjectTypeDefinition    objectTypeDefinition = ResourceManagementSchema.ObjectTypes[ObjectTypeNames.AttributeTypeDescription];
            AttributeTypeDefinition nameAttribute        = objectTypeDefinition.Attributes.First(t => t.SystemName == AttributeNames.Name);

            ResourceManagementSchema.AttributeNameValidationRegex = new Regex(nameAttribute.Regex);

            objectTypeDefinition = ResourceManagementSchema.ObjectTypes[ObjectTypeNames.ObjectTypeDescription];
            nameAttribute        = objectTypeDefinition.Attributes.First(t => t.SystemName == AttributeNames.Name);
            ResourceManagementSchema.ObjectTypeNameValidationRegex = new Regex(nameAttribute.Regex);
        }
        /// <summary>
        /// Populates the ResourceObject from a partial response to a Get request
        /// </summary>
        /// <param name="objectElements">A collection of XmlElements defining the object</param>
        private void PopulateResourceFromPartialResponse(IEnumerable <XmlElement> objectElements)
        {
            Dictionary <string, List <string> >      values      = new Dictionary <string, List <string> >();
            Dictionary <string, AttributePermission> permissions = new Dictionary <string, AttributePermission>();

            foreach (XmlElement partialAttributeElement in objectElements.Where(t => t.LocalName == "PartialAttribute"))
            {
                foreach (XmlElement attributeElement in partialAttributeElement.ChildNodes.OfType <XmlElement>())
                {
                    if (!values.ContainsKey(attributeElement.LocalName))
                    {
                        values.Add(attributeElement.LocalName, new List <string>());
                    }

                    AttributePermission p;
                    if (Enum.TryParse(attributeElement.GetAttribute("permissions", Namespaces.ResourceManagement), out p))
                    {
                        if (!permissions.ContainsKey(attributeElement.LocalName))
                        {
                            permissions.Add(attributeElement.LocalName, p);
                        }
                        else
                        {
                            permissions[attributeElement.LocalName] = p;
                        }
                    }

                    string value = attributeElement.InnerText;

                    if (!string.IsNullOrEmpty(value))
                    {
                        values[attributeElement.LocalName].Add(value);
                    }
                }
            }

            if (values.ContainsKey(AttributeNames.ObjectType))
            {
                string objectTypeName           = values[AttributeNames.ObjectType].First();
                ObjectTypeDefinition objectType = ResourceManagementSchema.GetObjectType(objectTypeName);
                this.ObjectType = objectType;
            }
            else
            {
                throw new ArgumentException("No object type was specified in the response");
            }

            this.SetInitialAttributeValues(values, permissions);
        }