Пример #1
0
        /// <summary>
        /// Method adds new attribute into existing map of all attributes (ObjectAttributes) of this CIMObject.
        /// <para>If MyAttributes map is null, it will be initialized and then the attribute will be added.</para>
        /// <para>If attribute with given FullName property already exists in the MyAttributes map, it will be added into the
        /// MyDuplicateAttributes list.</para>
        /// </summary>
        /// <param name="attr">object attribute</param>
        /// <returns>true if attribute has been successfuly added, false if there was duplicate attribute</returns>
        public bool AddAttribute(ObjectAttribute attr)
        {
            bool success = false;

            if (myAttributes == null)
            {
                myAttributes = new SortedDictionary <int, List <ObjectAttribute> >();
            }

            List <ObjectAttribute> attrList = null;

            if (!myAttributes.ContainsKey(attr.Code))
            {
                attrList = new List <ObjectAttribute>();
                //// add attribute in list and in map
                attrList.Add(attr);
                myAttributes.Add(attr.Code, attrList);
                success = true;
            }
            else
            {
                myAttributes.TryGetValue(attr.Code, out attrList);
                attrList.Add(attr);
                success = true;
            }

            if (string.Compare(CIMConstants.AttributeNameIdentifiedObjectName, attr.FullName) == 0)
            {
                name = attr.Value;
            }
            return(success);
        }
Пример #2
0
 /// <summary>
 /// Method removes the given object attribute from the MyAttributes list of
 /// this CIMObject.
 /// </summary>
 /// <param name="objectAttribute">attribute from MyAttributes map of this CIM object</param>
 public void RemoveAttribute(ObjectAttribute objectAttribute)
 {
     if ((myAttributes != null) && (objectAttribute != null))
     {
         if (myAttributes.ContainsKey(objectAttribute.Code))
         {
             List <ObjectAttribute> attrList = null;
             myAttributes.TryGetValue(objectAttribute.Code, out attrList);
             if ((attrList != null) && (attrList.Contains(objectAttribute)))
             {
                 attrList.Remove(objectAttribute);
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Method creates ObjectAttribute instance with following property values:
        /// <para>FullName = type + ".Member_Of_" + embeddedCategory</para>
        /// <para>IsReference = true</para>
        /// <para>Value = parentId</para>
        /// <para>This ObjectAttribute represents artificial attribute for representing
        /// info about parent inside of which some CIMObject is embedded.</para>
        /// </summary>
        /// <param name="cimModelContext">model context</param>
        /// <param name="type">CIM type of embedded child object</param>
        /// <param name="embeddedCategory">name of embedded category</param>
        /// <param name="parentId">parent object ID</param>
        /// <returns>ObjectAttribute instance or null if some argument is missing</returns>
        public static ObjectAttribute ConstructEmbeddedParentAttribute(CIMModelContext cimModelContext, string type, string embeddedCategory, string parentId)
        {
            ObjectAttribute specialAtt = null;

            if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(embeddedCategory) && !string.IsNullOrEmpty(parentId))
            {
                if (embeddedCategory.Contains(StringManipulationManager.SeparatorColon))
                {
                    embeddedCategory = embeddedCategory.Substring(embeddedCategory.IndexOf(StringManipulationManager.SeparatorColon) + 1);
                }

                specialAtt             = new ObjectAttribute(cimModelContext, string.Format("{0}.Member_Of_{1}", type, embeddedCategory));
                specialAtt.IsReference = true;
                specialAtt.Value       = parentId;
            }
            return(specialAtt);
        }
Пример #4
0
        /// <summary>
        /// Method returns object attribute of this CIMObject with given FullName value,
        /// <para>or null if the requested fullName value isn't found as one of key values in the MyAttributes map.</para>
        /// </summary>
        /// <param fullName="fullName">value of FullName property of requested attribute from MyAttributes map of this CIM object</param>
        /// <param name="multipleAtts">in case that there are multiple attributes with same fullName, this is the list of duplicates (duplicates aren't always error - it depends on profile definition)</param>
        /// <returns>ObjectAttribute with given full fullName or null</returns>
        public ObjectAttribute GetAttribute(string fullName, out List <ObjectAttribute> multipleAtts)
        {
            int             attributeCode = modelContext.ReadCodeOfAttribute(fullName);
            ObjectAttribute attribute     = null;

            multipleAtts = null;
            if (myAttributes != null)
            {
                if (myAttributes.ContainsKey(attributeCode))
                {
                    if ((myAttributes[attributeCode] != null) && (myAttributes[attributeCode].Count > 0))
                    {
                        attribute = myAttributes[attributeCode][0];
                        if (myAttributes[attributeCode].Count > 1)
                        {
                            multipleAtts = myAttributes[attributeCode].GetRange(1, myAttributes[attributeCode].Count - 1);
                        }
                    }
                }
            }
            return(attribute);
        }