コード例 #1
0
        /// <summary>
        /// Sets up the query object and validates the passed in parameters to ensure they are compatible with each other
        /// </summary>
        /// <param name="attributeName">The name of the attribute being queried</param>
        /// <param name="comparisonOperator">THe value comparison operator to use</param>
        /// <param name="value">The value to use in the query</param>
        /// <param name="negate">Indicates if the query should be negated with the not() operator</param>
        /// <param name="attributeType">The type of the target attribute</param>
        /// <param name="isMultivalued">The multivalued status of the attribute being queried</param>
        private void SetupBuilder(string attributeName, ComparisonOperator comparisonOperator, object value, bool negate, AttributeType attributeType, bool isMultivalued)
        {
            if (string.IsNullOrWhiteSpace(attributeName))
            {
                throw new ArgumentNullException(attributeName);
            }

            ResourceManagementSchema.ValidateAttributeName(attributeName);

            if (value == null)
            {
                if (comparisonOperator != ComparisonOperator.IsNotPresent && comparisonOperator != ComparisonOperator.IsPresent)
                {
                    throw new InvalidOperationException("An object value is required unless the operator is IsPresent or IsNotPresent");
                }
            }

            this.AttributeName = attributeName;
            this.Operator      = comparisonOperator;
            this.Value         = value;
            this.Negate        = negate;

            this.attributeType = attributeType;
            this.isMultivalued = isMultivalued;

            this.ThrowOnInvalidTypeOperatorCombination();
            this.ThrowOnInvalidNegateCombination();
        }
コード例 #2
0
        /// <summary>
        /// Populates the ResourceObject from a collection of fragments received from an enumeration response
        /// </summary>
        /// <param name="element">The parent XmlElement containing the object definition</param>
        private void PopulateResourceFromFragment(XmlElement element)
        {
            Dictionary <string, List <string> > values = new Dictionary <string, List <string> >();

            string objectTypeName = element.LocalName;

            this.ObjectType = ResourceManagementSchema.GetObjectType(objectTypeName);


            foreach (XmlElement child in element.ChildNodes.OfType <XmlElement>())
            {
                if (!values.ContainsKey(child.LocalName))
                {
                    values.Add(child.LocalName, new List <string>());
                }

                string value = child.InnerText;

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

            this.SetInitialAttributeValues(values, null);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the XPathQuery class
        /// </summary>
        /// <param name="attributeName">The name of the attribute to compare against</param>
        /// <param name="comparisonOperator">The value comparison operator to use</param>
        /// <param name="value">The value to compare against</param>
        /// <param name="negate">Indicates if this query should be negated with the not() operator</param>
        public XPathQuery(string attributeName, ComparisonOperator comparisonOperator, object value, bool negate)
        {
            AttributeType attributeType = ResourceManagementSchema.GetAttributeType(attributeName);
            bool          isMultivalued = ResourceManagementSchema.IsAttributeMultivalued(attributeName);

            this.SetupBuilder(attributeName, comparisonOperator, value, negate, attributeType, isMultivalued);
        }
 internal static void LoadSchema(EndpointManager e)
 {
     if (!isLoaded)
     {
         ResourceManagementSchema.RefreshSchema(e);
     }
 }
        /// <summary>
        /// Gets a value indicating if the object type exists in the schema
        /// </summary>
        /// <param name="name">The system name of the object type</param>
        /// <returns>True if the object type exists in the schema, false if it does not</returns>
        public static bool ContainsObjectType(string name)
        {
            ResourceManagementSchema.schemaLock.WaitOne();

            ResourceManagementSchema.LoadSchema(ResourceManagementClient.EndpointManager);

            return(ResourceManagementSchema.ObjectTypes.ContainsKey(name));
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the ResourceObject class
 /// </summary>
 /// <param name="type">The object type that this object will represent</param>
 /// <param name="client">The client used for further operations on this object</param>
 internal ResourceObject(string type, ResourceManagementClient client)
     : this(OperationType.Create, client, null)
 {
     this.IsPlaceHolder = true;
     this.ObjectType    = ResourceManagementSchema.GetObjectType(type);
     this.AddRemainingAttributesFromSchema();
     this.attributes[AttributeNames.ObjectType].SetValue(type);
 }
        /// <summary>
        /// Gets each object type definition from the schema
        /// </summary>
        /// <returns>An enumeration of ObjectTypeDefinitions</returns>
        public static IEnumerable <ObjectTypeDefinition> GetObjectTypes()
        {
            ResourceManagementSchema.schemaLock.WaitOne();

            ResourceManagementSchema.LoadSchema(ResourceManagementClient.EndpointManager);

            return(ResourceManagementSchema.ObjectTypes.Values);
        }
コード例 #8
0
        /// <summary>
        /// Forces a download of the schema from the ResourceManagementService
        /// </summary>
        /// <remarks>
        /// This method should be called after making changes to ResourceObjects that form the schema
        /// </remarks>
        internal static void RefreshSchema(EndpointManager e)
        {
            lock (lockObject)
            {
                ResourceManagementSchema.ObjectTypes = new Dictionary <string, ObjectTypeDefinition>();

                MetadataSet set = ResourceManagementSchema.GetMetadataSet(e);
                ResourceManagementSchema.PopulateSchemaFromMetadata(set);
                isLoaded = true;
            }
        }
コード例 #9
0
 internal static void LoadSchema(EndpointManager e)
 {
     lock (lockObject)
     {
         if (!isLoaded)
         {
             ResourceManagementSchema.RefreshSchema(e);
             ResourceManagementSchema.LoadNameValidationRegularExpressions();
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// Gets an object type definition from the schema by name
        /// </summary>
        /// <param name="name">The system name of the object type</param>
        /// <returns>A ObjectTypeDefinition with a system name that matches the 'name' parameter</returns>
        /// <exception cref="NoSuchObjectTypeException">Throw when an object type could not be found in the schema with a matching name</exception>
        public static ObjectTypeDefinition GetObjectType(string name)
        {
            ResourceManagementSchema.LoadSchema(ResourceManagementClient.EndpointManager);

            if (ResourceManagementSchema.ObjectTypes.ContainsKey(name))
            {
                return(ResourceManagementSchema.ObjectTypes[name]);
            }
            else
            {
                throw new NoSuchObjectTypeException(name);
            }
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <summary>
        /// Gets a value indicating whether the specific attribute is multivalued
        /// </summary>
        /// <param name="attributeName">The attribute name</param>
        /// <returns>A value indicating whether the specific attribute is multivalued</returns>
        public static bool IsAttributeMultivalued(string attributeName)
        {
            ResourceManagementSchema.LoadSchema(ResourceManagementClient.EndpointManager);

            foreach (ObjectTypeDefinition objectType in ResourceManagementSchema.ObjectTypes.Values)
            {
                AttributeTypeDefinition attributeType = objectType.Attributes.FirstOrDefault(t => t.SystemName == attributeName);

                if (attributeType != null)
                {
                    return(attributeType.IsMultivalued);
                }
            }

            throw new NoSuchAttributeException(attributeName);
        }
コード例 #13
0
 /// <summary>
 /// Forces a download of the schema from the ResourceManagementService
 /// </summary>
 /// <remarks>
 /// This method should be called after making changes to ResourceObjects that form the schema
 /// </remarks>
 internal static void RefreshSchema(EndpointManager e)
 {
     try
     {
         ResourceManagementSchema.schemaLock.WaitOne();
         ResourceManagementSchema.schemaLock.Reset();
         MetadataSet set = ResourceManagementSchema.GetMetadataSet(e);
         ResourceManagementSchema.PopulateSchemaFromMetadata(set);
         ResourceManagementSchema.LoadNameValidationRegularExpressions();
         ResourceManagementSchema.SchemaEndpoint = e.MetadataEndpoint.Uri;
         isLoaded = true;
     }
     finally
     {
         ResourceManagementSchema.schemaLock.Set();
     }
 }
コード例 #14
0
        /// <summary>
        /// Populates the ResourceObject from its full object definition received from a Get request
        /// </summary>
        /// <param name="reader">The XmlDictionaryReader containing the full object definition</param>
        private void PopulateResourceFromFullObject(XmlDictionaryReader reader)
        {
            Dictionary <string, List <string> >      values      = new Dictionary <string, List <string> >();
            Dictionary <string, AttributePermission> permissions = new Dictionary <string, AttributePermission>();

            reader.MoveToStartElement();

            string objectTypeName = reader.LocalName;

            this.ObjectType = ResourceManagementSchema.GetObjectType(objectTypeName);

            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (!values.ContainsKey(reader.LocalName))
                {
                    values.Add(reader.LocalName, new List <string>());
                }

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

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

            this.SetInitialAttributeValues(values, permissions);
        }
コード例 #15
0
        /// <summary>
        /// Builds the XPath expression
        /// </summary>
        /// <returns>The string representation of the expression</returns>
        protected virtual string BuildExpression()
        {
            StringBuilder sb = new StringBuilder();

            if (this.ObjectType != "*")
            {
                ResourceManagementSchema.ValidateObjectTypeName(this.ObjectType);
            }

            sb.AppendFormat("/{0}", this.ObjectType);

            if (this.Query != null)
            {
                sb.AppendFormat("[{0}]", this.Query.BuildQueryString());
            }

            return(sb.ToString());
        }
コード例 #16
0
        /// <summary>
        /// Gets the data type of the specific attribute
        /// </summary>
        /// <param name="attributeName">The attribute name</param>
        /// <returns>An <c>AttributeType</c> value</returns>
        public static AttributeType GetAttributeType(string attributeName)
        {
            ResourceManagementSchema.schemaLock.WaitOne();

            ResourceManagementSchema.LoadSchema(ResourceManagementClient.EndpointManager);

            foreach (ObjectTypeDefinition objectType in ResourceManagementSchema.ObjectTypes.Values)
            {
                AttributeTypeDefinition attributeType = objectType.Attributes.FirstOrDefault(t => t.SystemName == attributeName);

                if (attributeType != null)
                {
                    return(attributeType.Type);
                }
            }

            throw new NoSuchAttributeException(attributeName);
        }
コード例 #17
0
        /// <summary>
        /// Deserializes an object from a serialization data set
        /// </summary>
        /// <param name="info">The serialization data</param>
        private void DeserializeObject(SerializationInfo info)
        {
            Dictionary <string, List <string> > values = new Dictionary <string, List <string> >();

            foreach (SerializationEntry entry in info)
            {
                IEnumerable <string> entryValues = entry.Value as IEnumerable <string>;

                if (entryValues != null)
                {
                    values.Add(entry.Name, entryValues.ToList());
                }
                else
                {
                    values.Add(entry.Name, new List <string>()
                    {
                        TypeConverter.ToString(entry.Value)
                    });
                }
            }

            if (!values.ContainsKey(AttributeNames.ObjectType))
            {
                throw new InvalidOperationException("The object type of the attribute was not present in the serialization data");
            }

            if (this.ModificationType == OperationType.None)
            {
                this.ModificationType = OperationType.Update;
            }

            string objectTypeName = values[AttributeNames.ObjectType].First();

            this.ObjectType = ResourceManagementSchema.GetObjectType(objectTypeName);
            this.SetInitialAttributeValues(values, null);
            this.AddRemainingAttributesFromSchema();
        }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of the XPathDereferencedExpression class
 /// </summary>
 /// <param name="objectType">The object type used in the expression</param>
 /// <param name="dereferenceAttribute">The name of the attribute to dereference</param>
 /// <param name="query">The query used to build the expression</param>
 /// <param name="wrapFilterXml">Indicates if the resulting expression should be wrapped in an XML filter element</param>
 public XPathDereferencedExpression(string objectType, string dereferenceAttribute, IXPathQueryObject query, bool wrapFilterXml)
     : base(objectType, query, wrapFilterXml)
 {
     this.DereferenceAttribute = dereferenceAttribute;
     ResourceManagementSchema.ValidateObjectTypeName(this.DereferenceAttribute);
 }