Exemplo n.º 1
0
 private void ReplaceDataTypesWithSimpleTypes(PredefinedClasses cimPredefined)
 {
     if ((cimPredefined != null) && (profile != null) && (profile.PropertyCount > 0))
     {
         foreach (Property property in profile.ProfileMap[ProfileElementTypes.Property])
         {
             string dataTypeName = StringManipulationManager.ExtractAllAfterSeparator(property.DataType, StringManipulationManager.SeparatorSharp);
             if (string.IsNullOrEmpty(dataTypeName))
             {
                 //// support cim15
                 dataTypeName = StringManipulationManager.ExtractAllAfterSeparator(property.Range, StringManipulationManager.SeparatorSharp);
             }
             if (cimPredefined.PedifinedClassesList.Contains(dataTypeName))
             {
                 //// read the simple type from "value" attribute
                 Class dataTypeClass = profile.FindProfileElementByName(dataTypeName) as Class;
                 foreach (Property p in dataTypeClass.MyProperties)
                 {
                     if (string.Compare(p.Name, "value") == 0)
                     {
                         property.DataType = p.DataType;
                         if (!string.IsNullOrEmpty(property.Range))
                         {
                             property.Range         = null;
                             property.RangeAsObject = null;
                         }
                     }
                 }
             }
         }
     }
 }
        public void CreateEnumeration(Profile profile, string key)
        {
            Class enumeration = new Class();

            enumeration.Type = "Class";
            profile.ProfileMap[ProfileElementTypes.Class].Add(enumeration);
            List <string> enums;

            predifinedEnumerations.TryGetValue(key, out enums);
            if (enums != null)
            {
                foreach (string en in enums)
                {
                    EnumMember enumerationMember = new EnumMember();
                    //enumerationMember = new EnumMember();
                    enumerationMember.URI               = "#" + key + "." + en;
                    enumerationMember.Label             = en;
                    enumerationMember.EnumerationObject = enumeration;
                    enumeration.AddToMyEnumerationMembers(enumerationMember);
                }
                enumeration.URI = "#" + key;
                enumeration.BelongsToCategory         = "#Package_Core";
                enumeration.BelongsToCategoryAsObject = profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(enumeration.BelongsToCategory, StringManipulationManager.SeparatorSharp));
                ((ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(enumeration.BelongsToCategory, StringManipulationManager.SeparatorSharp))).AddToMembersOfClassCategory(enumeration);
            }
        }
Exemplo n.º 3
0
        private void SetReferenceToProperty(CIMObject element, object something, string attValue, PropertyInfo prop, ConcreteModel model)
        {
            if (!string.IsNullOrEmpty(attValue))
            {
                Type   referencedType = prop.PropertyType;
                string referencedID   = StringManipulationManager.ExtractAllAfterSeparator(attValue, StringManipulationManager.SeparatorSharp);

                object referencedObject = model.GetObjectByID(referencedID);
                if (referencedObject == null)
                {
                    if (!(referencedType.GetProperty("Value") != null &&
                          referencedType.GetProperty("Multiplier") != null &&
                          referencedType.GetProperty("Unit") != null) && referencedType.Name != "AbsoluteDate")
                    {
                        OnMessage("Referenced object on property: " + prop.DeclaringType + "." + prop.Name + ", elements ID:" + element.ID + " not in model. Referenced: "
                                  + referencedType.ToString() + ", ID:" + referencedID
                                  , MessageLevel.WARNING);
                        string propertyType = StringManipulationManager.ExtractAllAfterSeparator(referencedType.FullName, StringManipulationManager.SeparatorDot);
                    }
                    //otherwise its DataType and its already set
                }
                else
                {
                    if (referencedObject.GetType().Equals(referencedType) || referencedObject.GetType().IsSubclassOf(referencedType))
                    {
                        prop.SetValue(something, referencedObject, null);
                    }
                    else
                    {
                        string referencedObjectType = StringManipulationManager.ExtractAllAfterSeparator(referencedObject.GetType().FullName, StringManipulationManager.SeparatorDot);
                        string propertyType         = StringManipulationManager.ExtractAllAfterSeparator(referencedType.FullName, StringManipulationManager.SeparatorDot);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void AddPredefined()
 {
     foreach (Class el in predefined)
     {
         el.BelongsToCategory         = "#Package_Core";
         el.BelongsToCategoryAsObject = profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(el.BelongsToCategory, StringManipulationManager.SeparatorSharp));
         ((ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(el.BelongsToCategory, StringManipulationManager.SeparatorSharp))).AddToMembersOfClassCategory(el);
     }
     predefined.Clear();
 }
Exemplo n.º 5
0
        public override void StartElement(string localName, string qName, SortedList <string, string> attributes, int lineNumber = 0, int columnNumber = 0)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(qName, rdfRootQ, true) == 0)
            {
                //// rdf:RDF element - extract attributes
                if ((attributes != null) && (attributes.Count > 0))
                {
                    foreach (string attrName in attributes.Keys)
                    {
                        if (!attrName.StartsWith(xmlnsPrefix, true, null))
                        {
                            namespaces.Add(attrName, attributes[attrName]);
                        }
                    }
                }
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                string id = TryReadRDFIdAttribute(attributes);
                //// start of new main element
                if (currentElement == null)
                {
                    if (id != null)
                    {
                        inLevel = Level.Element;
                        sourceText.Clear();
                        currentElement             = new CIMEntity();
                        currentElement.RdfID       = StringManipulationManager.ExtractAllAfterSeparator(id, StringManipulationManager.SeparatorSharp);
                        currentElement.StartLine   = lineNumber - 1;
                        currentElement.StartColumn = columnNumber;
                        GoToPosistion(lineNumber, columnNumber);
                        x = true;
                    }
                }
                //// start of new subelement (attribute or embedded element)
                else
                {
                    //// new attribute
                    inLevel = Level.Property;
                }
            }
        }
        public void CreatePackage(Profile profile, string key)
        {
            List <NameValuePair> packageProps = predefinedPackages[key];
            ClassCategory        package      = new ClassCategory();

            foreach (NameValuePair prop in packageProps)
            {
                if (prop.Name.Equals("URI"))
                {
                    package.URI = prop.Value;
                }
                else if (prop.Name.Equals("BelongsToCategory"))
                {
                    package.BelongsToCategory = prop.Value;
                }
                else if (prop.Name.Equals("Comment"))
                {
                    package.Comment = prop.Value;
                }
                else if (prop.Name.Equals("Label"))
                {
                    package.Label = prop.Value;
                }
                else if (prop.Name.Equals("Type"))
                {
                    package.Type = prop.Value;
                }
            }

            List <ProfileElement> elems = profile.ProfileMap[ProfileElementTypes.ClassCategory];

            if (elems == null)
            {
                elems = new List <ProfileElement>();
            }

            if (elems.Count > 0 && !elems.Contains(package))
            {
                elems.Add(package);
                profile.ProfileMap.Remove(ProfileElementTypes.ClassCategory);
                profile.ProfileMap.Add(ProfileElementTypes.ClassCategory, elems);
            }

            package.BelongsToCategoryAsObject = (ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(package.BelongsToCategory, StringManipulationManager.SeparatorSharp));
            ((ClassCategory)profile.FindProfileElementByName(StringManipulationManager.ExtractAllAfterSeparator(package.BelongsToCategory, StringManipulationManager.SeparatorSharp))).AddToMembersOfClassCategory(package);
        }
Exemplo n.º 7
0
        //// Method tries to read the "rdf:resource" attribute and if it is found,
        //// it connects the referenced object (parent) with child object.
        private void ReadAndProcessAttributeValue(ObjectAttribute objectAttribute, SortedList <string, string> atts)
        {
            if ((objectAttribute != null) && (atts != null))
            {
                //// if object attribute contains reference to another element,
                //// it is being read and put on stack of that element (parent element)
                if (atts.ContainsKey(rdfResource))
                {
                    string parentId = atts[rdfResource];
                    objectAttribute.Value       = parentId;
                    objectAttribute.IsReference = true;

                    if (parentId.StartsWith(StringManipulationManager.SeparatorSharp))
                    {
                        parentId = StringManipulationManager.ExtractAllAfterSeparator(parentId, StringManipulationManager.SeparatorSharp);
                    }
                    AddChildElementToReferencedParentElement(parentId);
                }
            }
        }
        /// <summary>
        /// Method adds reference to list on property prop
        /// </summary>
        /// <param name="list">list that reference will be added to</param>
        /// <param name="att">attribute containing information about reference</param>
        /// <param name="prop">property containing list</param>
        private void AddReferenceToList(CIMObject element, ref IList list, string attValue, PropertyInfo prop, ConcreteModel model)
        {
            if (!string.IsNullOrEmpty(attValue))
            {
                Type   referencedType = prop.PropertyType;
                string referencedID   = StringManipulationManager.ExtractAllAfterSeparator(attValue, StringManipulationManager.SeparatorSharp);

                string refType = referencedType.ToString();
                if (referencedType.IsGenericType)
                {
                    refType = referencedType.GetGenericArguments()[0].ToString();
                }

                //DataTypes? what about them if in list - should be a way to determine
                object referencedObject = model.GetObjectByID(referencedID);

                if (referencedObject != null)
                {
                    try
                    {
                        list.Add(referencedObject);
                    }
                    catch
                    {
                        OnMessage("Unsuccessful adding item to list on property: " + prop.DeclaringType + "." + prop.Name
                                  + ", elements ID:" + element.ID + " Referenced: " + refType + ", ID: " + referencedID
                                  , MessageLevel.ERROR);
                        string referencedTypeWithoutPrefix = StringManipulationManager.ExtractAllAfterSeparator(refType, StringManipulationManager.SeparatorDot);
                    }
                }
                else
                {
                    OnMessage("Referenced object on property: " + prop.DeclaringType + "." + prop.Name + ", elements ID:" + element.ID + " not in model. Referenced: "
                              + refType + ", ID:" + referencedID
                              , MessageLevel.WARNING);
                    string referencedTypeWithoutPrefix = StringManipulationManager.ExtractAllAfterSeparator(refType, StringManipulationManager.SeparatorDot);
                }
            }
        }
Exemplo n.º 9
0
        public override void StartElement(string localName, string qName, SortedList <string, string> attributes, int lineNumber = 0, int columnNumber = 0)
        {
            if (string.Compare(qName, forwardDiffQ, true) == 0)
            {
                changeType = ChangeType.Forward;
            }
            if (string.Compare(qName, reverseDiffQ, true) == 0)
            {
                changeType = ChangeType.Reverse;
            }
            string type = localName;

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                string id = TryReadRDFIdAttribute(attributes);
                //// start of new main element
                if (currentElement == null)
                {
                    if (id != null)
                    {
                        inLevel = Level.Element;
                        sourceText.Clear();
                        currentElement             = new CIMEntity();
                        currentElement.RdfID       = StringManipulationManager.ExtractAllAfterSeparator(id, StringManipulationManager.SeparatorSharp);
                        currentElement.StartLine   = lineNumber - 1;
                        currentElement.StartColumn = columnNumber;
                        GoToPosistion(lineNumber, columnNumber);
                        x = true;
                    }
                }
                //// start of new subelement (attribute or embedded element)
                else
                {
                    //// new attribute
                    inLevel = Level.Property;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds missing data to <c>entity</c> with respect to <c>modelClass</c>, and <c>package</c> from the model
        /// </summary>
        /// <param name="entity">ProfileElement element with missing data</param>
        /// <param name="modelClass">CClass from model</param>
        /// <param name="package">CPackage from model. Contains the <c>modelClass</c></param>
        private void updateClassData(ProfileElement entity, CClass modelClass, CPackage package)
        {
            entity.AddStereotype(ProfileElementStereotype.StereotypeConcrete);
            entity.URI = modelClass.name;
            //PACKAGE: name and object - added "Package_" because of the current scheme
            entity.BelongsToCategory = "Package_" + package.name;
            entity.TypeAsEnumValue   = ProfileElementTypes.Class;
            entity.Label             = StringManipulationManager.ExtractAllAfterSeparator(modelClass.name, StringManipulationManager.SeparatorSharp);
            List <ProfileElement> packages = profile.GetAllProfileElementsOfType(ProfileElementTypes.ClassCategory);

            foreach (ProfileElement pack in packages)
            {
                if (pack.UniqueName.Equals(entity.BelongsToCategory))
                {
                    entity.BelongsToCategoryAsObject = pack;
                    pack.AddToMembersOfClassCategory(entity);
                    break;
                }
            }
            //if package is not found, look for it in the model
            //-----------------------------------------------------------------------------


            if (entity.BelongsToCategoryAsObject == null)
            {
                //looking for package (and we know which one - CPackage) and adding it to hierarchy
                ProfileElement newPackage = new ProfileElement();
                newPackage.Label = package.name;
                newPackage.URI   = "Package_" + package.name;

                //create separate package - detached from hierarchy, because we wont need it
                newPackage.TypeAsEnumValue = ProfileElementTypes.ClassCategory;
                newPackage.AddToMembersOfClassCategory(entity);
                entity.BelongsToCategoryAsObject = newPackage;
                entity.BelongsToCategory         = newPackage.UniqueName;
                profile.GetAllProfileElementsOfType(ProfileElementTypes.ClassCategory).Add(newPackage);
            }

            //-----------------------------------------------------------------------------

            //PARENT: assumption is that all the classes needed are in profile,
            //we dont need to add additional, not mentioned in profile
            entity.SubClassOf = modelClass.parentClassName == null ? string.Empty : modelClass.parentClassName;
            if (!string.IsNullOrEmpty(entity.SubClassOf))
            {
                bool foundInModel             = false;
                List <ProfileElement> classes = profile.GetAllProfileElementsOfType(ProfileElementTypes.Class);
                foreach (ProfileElement temp in classes)
                {
                    if (temp.URI.Equals(entity.SubClassOf))
                    {
                        entity.SubClassOfAsObject = temp;
                        break;
                    }
                }
                if (!foundInModel)
                {
                    entity.SubClassOf = string.Empty;
                }
            }

            //FIELDS
            foreach (CAttribute att in modelClass.attributes)
            {
                addAttributeToElement(entity, att, modelClass);
            }
        }