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.º 2
0
        /// <summary>
        /// Method first tries to find the ProfileElementStereotype object with given fullName isInside the
        /// (static) StereotypeList, and if it doesn't find it, it creates new stereotype objects
        /// and adds it to this list.
        /// <remarks>If the fullStereotypeName is null, method will return null.</remarks>
        /// </summary>
        /// <param fullName="fullStereotypeName">full fullName of stereotype which is being searched</param>
        /// <returns>ProfileElementStereotype object with given fullName founded (or added) in StereotypeList</returns>
        public static ProfileElementStereotype FindOrCreateStereotypeForName(string fullStereotypeName)
        {
            ProfileElementStereotype stereotype = null;

            if (!string.IsNullOrEmpty(fullStereotypeName))
            {
                string shortName = StringManipulationManager.ExtractShortestName(fullStereotypeName, StringManipulationManager.SeparatorSharp);

                foreach (ProfileElementStereotype existingStereotype in Profile.StereotypeList)
                {
                    if (existingStereotype.Name.Equals(fullStereotypeName) || existingStereotype.Name.Equals(shortName))
                    {
                        stereotype = existingStereotype;
                        break;
                    }
                }

                if (stereotype == null)
                {
                    stereotype = new ProfileElementStereotype(Profile.StereotypeList.Count, fullStereotypeName);
                    Profile.StereotypeList.Add(stereotype);
                }
            }
            return(stereotype);
        }
Exemplo n.º 3
0
        private void CreatePropertyForField(CodeTypeDeclaration file, string dataType, CodeMemberField att, bool get, bool set)
        {
            CodeMemberProperty prop = new CodeMemberProperty();

            prop.Attributes = MemberAttributes.Public;

            prop.Type = new CodeTypeReference(dataType);
            prop.Name = StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4));
            if (prop.Name.Equals(file.Name))
            {
                prop.Name = prop.Name + "P";
            }
            if (get)
            {
                prop.HasGet = true;
                prop.GetStatements.Add(new CodeSnippetExpression("return this." + att.Name + ((String.Compare(dataType, "system.string", true) == 0)?"":".GetValueOrDefault()")));
            }
            if (set)
            {
                prop.HasSet = true;
                prop.SetStatements.Add(new CodeSnippetExpression("this." + att.Name + " = value"));
            }
            file.Members.Add(prop);

            CreateHasValueProperty(file, att);
        }
Exemplo n.º 4
0
        private void CreateIsMandatoryFieldAndProperty(CodeTypeDeclaration file, CodeMemberField att, Property field)
        {
            CodeMemberField fieldIsMandatory = new CodeMemberField();

            fieldIsMandatory.Attributes = MemberAttributes.Private | MemberAttributes.Const;
            fieldIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            fieldIsMandatory.Name       = "is" + StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "Mandatory";

            //switch case and set true or false
            if (ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString1) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityExactlyOneString2) || ExtractSimpleNameFromResourceURI(field.MultiplicityAsString).Equals(MultiplicityOneOrMoreString))
            {
                fieldIsMandatory.InitExpression = new CodePrimitiveExpression(true);
            }
            else
            {
                fieldIsMandatory.InitExpression = new CodePrimitiveExpression(false);
            }
            file.Members.Add(fieldIsMandatory);

            CodeMemberProperty propIsMandatory = new CodeMemberProperty();

            propIsMandatory.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            propIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            propIsMandatory.Name       = "Is" + StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "Mandatory";
            propIsMandatory.HasGet     = true;
            propIsMandatory.HasSet     = false;
            propIsMandatory.GetStatements.Add(new CodeSnippetExpression("return " + fieldIsMandatory.Name));

            file.Members.Add(propIsMandatory);
        }
Exemplo n.º 5
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.º 6
0
        /// <summary>
        /// Method creates property field for member field <c>att</c> inside <c>file</c> class
        /// </summary>
        /// <param name="file">CodeTypeDeclaration class that property is added to</param>
        /// <param name="att">CodeMemberField member field that property is made for</param>
        /// <param name="get">bool value - if <c>true</c> get will be added to property field</param>
        /// <param name="set">bool value - if <c>true</c> set will be added to property field</param>
        private static void CreatePropertyForField(CodeTypeDeclaration file, CodeMemberField att, bool get, bool set)
        {
            CodeMemberProperty prop = new CodeMemberProperty();

            prop.Attributes = MemberAttributes.Public;

            prop.Type = att.Type;
            prop.Name = StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4));
            if (prop.Name.Equals(file.Name))
            {
                prop.Name = prop.Name + "P";
            }
            if (get)
            {
                prop.HasGet = true;
                prop.GetStatements.Add(new CodeSnippetExpression("return this." + att.Name));
            }
            if (set)
            {
                prop.HasSet = true;
                prop.SetStatements.Add(new CodeSnippetExpression("this." + att.Name + " = value"));
            }
            file.Members.Add(prop);

            CreateHasValueProperty(file, att);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Method creates constant field and its property which contains prefix of the property
        /// </summary>
        /// <param name="file">CodeTypeDeclaration class that field and its property  are been added to</param>
        /// <param name="att">CodeMemberField member attribute that prefix field and its property are made for</param>
        /// <param name="field">Property which is being processing</param>
        private void CreateFieldPrefix(CodeTypeDeclaration file, CodeMemberField att, Property field)
        {
            CodeMemberField fieldPrefix = new CodeMemberField();

            fieldPrefix.Attributes = MemberAttributes.Private | MemberAttributes.Const;
            fieldPrefix.Type       = new CodeTypeReference(typeof(string));
            fieldPrefix.Name       = "_" + att.Name.Substring(4) + "Prefix";
            //set prefix
            if (field.GetUndefinedStereotypes() != null && field.GetUndefinedStereotypes().Count > 0)
            {
                fieldPrefix.InitExpression = new CodePrimitiveExpression(StringManipulationManager.ExtractShortestName(field.GetUndefinedStereotypes().ElementAt(0).Name, separator));
            }
            else
            {
                fieldPrefix.InitExpression = new CodePrimitiveExpression("cim");
            }

            file.Members.Add(fieldPrefix);

            CodeMemberProperty propFieldPrefix = new CodeMemberProperty();

            propFieldPrefix.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            propFieldPrefix.Type       = new CodeTypeReference(typeof(string));
            propFieldPrefix.Name       = StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "Prefix";
            propFieldPrefix.HasGet     = true;
            propFieldPrefix.HasSet     = false;
            propFieldPrefix.GetStatements.Add(new CodeSnippetExpression("return " + fieldPrefix.Name));

            file.Members.Add(propFieldPrefix);
        }
Exemplo n.º 8
0
        private void CreateIsMandatoryFieldAndProperty(CodeTypeDeclaration file, CodeMemberField att, EAPAttribute attribute)
        {
            CodeMemberField fieldIsMandatory = new CodeMemberField();

            fieldIsMandatory.Attributes = MemberAttributes.Private | MemberAttributes.Const;
            fieldIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            fieldIsMandatory.Name       = "is" + StringManipulationManager.CreateHungarianNotation(att.Name) + "Mandatory";

            //switch case and set true or false
            if (int.Parse(attribute.Min) == 1)
            {
                fieldIsMandatory.InitExpression = new CodePrimitiveExpression(true);
            }
            else
            {
                fieldIsMandatory.InitExpression = new CodePrimitiveExpression(false);
            }
            file.Members.Add(fieldIsMandatory);

            CodeMemberProperty propIsMandatory = new CodeMemberProperty();

            propIsMandatory.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            propIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            propIsMandatory.Name       = "Is" + StringManipulationManager.CreateHungarianNotation(att.Name) + "Mandatory";
            propIsMandatory.HasGet     = true;
            propIsMandatory.HasSet     = false;
            propIsMandatory.GetStatements.Add(new CodeSnippetExpression("return " + fieldIsMandatory.Name));

            file.Members.Add(propIsMandatory);
        }
Exemplo n.º 9
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;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 10
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.º 11
0
        private static void CreateHasValueProperty(CodeTypeDeclaration file, CodeMemberField att)
        {
            CodeMemberProperty propHasValue = new CodeMemberProperty();

            propHasValue.Attributes = MemberAttributes.Public;

            propHasValue.Type   = new CodeTypeReference(typeof(bool));
            propHasValue.Name   = StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "HasValue";
            propHasValue.HasGet = true;
            propHasValue.HasSet = false;
            propHasValue.GetStatements.Add(new CodeSnippetExpression("return this." + att.Name + " != null"));
            file.Members.Add(propHasValue);
        }
Exemplo n.º 12
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;
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Method creates CodeCompileUnit that represents enumeration
        /// NOTE: in this method if character '-' is found it is replaced by string "MINUS"
        /// so that the member field names in CodeCompileUnit ca be valid for C# code
        /// e.g. Hz-1 will become HzMINUS1
        /// </summary>
        /// <param name="package">ProfileElement element that represents the package</param>
        /// <param name="entity">ProfileElement element that represents enumeration</param>
        /// <returns>CodeCompileUnit unit representing enumeration</returns>
        private CodeCompileUnit CreateEnumeration(ProfileElement package, Class entity)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            string fullNS = package.Name;

            ProfileElement temp = package;

            /*while(temp.BelongsToCategoryAsObject != null)
             * {
             *  temp = temp.BelongsToCategoryAsObject;
             *  fullNS = temp.Name + "." + fullNS;
             * }
             * fullNS = defaultNS + "." + fullNS;*/
            //CodeNamespace nameSpace = new CodeNamespace(fullNS);
            CodeNamespace nameSpace = new CodeNamespace(defaultNS);

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            CodeTypeDeclaration enumeration = new CodeTypeDeclaration(entity.Name);

            enumeration.IsEnum         = true;
            enumeration.Attributes     = MemberAttributes.Public;
            enumeration.TypeAttributes = TypeAttributes.Public;

            if (entity.MyEnumerationMembers != null)
            {
                foreach (ProfileElement enumMember in entity.MyEnumerationMembers)
                {
                    /*
                     * REPLACES '-' with "MINUS" because in enumeration '-' is not a valid character
                     */
                    string value = enumMember.Name;
                    value = StringManipulationManager.ReplaceInvalidEnumerationCharacters(value);
                    CodeMemberField val = new CodeMemberField(typeof(int), value);
                    if (!string.IsNullOrEmpty(enumMember.Comment))
                    {
                        val.Comments.Add(new CodeCommentStatement(enumMember.Comment, true));
                    }
                    enumeration.Members.Add(val);
                }
            }
            nameSpace.Types.Add(enumeration);
            return(unit);
        }
Exemplo n.º 14
0
        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.º 15
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.º 17
0
        /// <summary>
        /// Method creates CodeCompileUnit that represents enumeration
        /// NOTE: in this method if character '-' is found it is replaced by string "MINUS"
        /// so that the member field names in CodeCompileUnit ca be valid for C# code
        /// e.g. Hz-1 will become HzMINUS1
        /// </summary>
        /// <param name="package">ProfileElement element that represents the package</param>
        /// <param name="entity">ProfileElement element that represents enumeration</param>
        /// <returns>CodeCompileUnit unit representing enumeration</returns>
        private CodeCompileUnit CreateEnumeration(ProfileElement package, Class entity)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            string fullNS = package.Name;

            ProfileElement temp = package;

            //CodeNamespace nameSpace = new CodeNamespace(fullNS);
            CodeNamespace nameSpace = new CodeNamespace(defaultNS);

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            CodeTypeDeclaration enumeration = new CodeTypeDeclaration(entity.Name);

            enumeration.IsEnum         = true;
            enumeration.Attributes     = MemberAttributes.Public;
            enumeration.TypeAttributes = TypeAttributes.Public;

            if (entity.MyEnumerationMembers != null)
            {
                foreach (ProfileElement enumMember in entity.MyEnumerationMembers)
                {
                    string value = enumMember.Name;
                    value = StringManipulationManager.ReplaceInvalidEnumerationCharacters(value);
                    CodeMemberField val = new CodeMemberField(typeof(int), value);
                    if (!string.IsNullOrEmpty(enumMember.Comment))
                    {
                        val.Comments.Add(new CodeCommentStatement(enumMember.Comment, true));
                    }
                    enumeration.Members.Add(val);
                }
            }
            nameSpace.Types.Add(enumeration);
            return(unit);
        }
Exemplo n.º 18
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;
                }
            }
        }
 /// <summary>
 /// Sets value of enumeration to property <c>prop</c> of object <c>instance</c>
 /// </summary>
 /// <param name="assembly">contains enumeration definition</param>
 /// <param name="instance">object that contains property</param>
 /// <param name="prop">property that value will be set to</param>
 /// <param name="att">attribute from model that cointains value and name of enumeration</param>
 private void SetEnumerationProperty(CIMObject element, Assembly assembly, object instance, PropertyInfo prop, ObjectAttribute att)
 {
     if (!string.IsNullOrEmpty(att.Value))
     {
         ////get type, that is, enumeration member that has name equal to the string value of attribute
         ////get the field with name casted into int and set itatt.Value
         Type      enumType = assembly.GetType(prop.PropertyType.ToString());
         FieldInfo enumVal  = enumType.GetField(StringManipulationManager.ReplaceInvalidEnumerationCharacters(att.Value));
         if (enumVal == null)
         {
             OnMessage("Error occured while trying to set value to field " +
                       prop.DeclaringType.Name + "." +
                       prop.Name + ", enumeration value <" +
                       prop.PropertyType.ToString() + "." + StringManipulationManager.ReplaceInvalidEnumerationCharacters(att.Value) + "> not found in assembly!"
                       + " elements ID: " + element.ID, MessageLevel.WARNING);
         }
         else
         {
             object newEnumValue = enumVal.GetValue(enumType);
             prop.SetValue(instance, newEnumValue, null);
         }
     }
 }
Exemplo n.º 20
0
        private void CreatePropertyForField(CodeTypeDeclaration file, EAPAttribute attribute, CodeMemberField att, bool get, bool set)
        {
            CodeMemberProperty prop = new CodeMemberProperty();

            prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            if (attribute.TypeCode != "")
            {
                if (attribute.TypeCode.Equals("Enum") || attribute.TypeCode.Equals("Class"))
                {
                    prop.Type = new CodeTypeReference(attribute.MeasurementType);
                }
            }
            else
            {
                if (attribute.MeasurementType != "")
                {
                    string dataType = StringManipulationManager.GetSystemType(attribute.MeasurementType);
                    prop.Type = new CodeTypeReference(dataType);
                }
            }
            prop.Name = StringManipulationManager.CreateHungarianNotation(att.Name);
            if (prop.Name.Equals(file.Name))
            {
                prop.Name = prop.Name + "P";
            }
            if (get)
            {
                prop.HasGet = true;
                prop.GetStatements.Add(new CodeSnippetExpression("return this." + att.Name));
            }
            if (set)
            {
                prop.HasSet = true;
                prop.SetStatements.Add(new CodeSnippetExpression("this." + att.Name + " = value"));
            }
            file.Members.Add(prop);
        }
Exemplo n.º 21
0
 private string ExtractSimpleNameFromResourceURI(string resourceUri)
 {
     return(StringManipulationManager.ExtractShortestName(resourceUri, separator));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Method creates predefined class that contains ID and other needed fields
        /// </summary>
        private void CreateParentClass()
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            CodeNamespace nameSpace = new CodeNamespace(defaultNS);

            unit.Namespaces.Add(nameSpace);

            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            //class
            CodeTypeDeclaration file = new CodeTypeDeclaration();

            file.IsClass        = true;
            file.Name           = "IDClass";
            file.TypeAttributes = TypeAttributes.Public;

            //create field
            string          fieldName = "cim_ID";
            CodeMemberField att       = new CodeMemberField(typeof(string), fieldName);

            att.Attributes = MemberAttributes.Private;
            att.Comments.Add(new CodeCommentStatement("ID used for reference purposes", true));

            file.Members.Add(att);

            //create property
            CodeMemberProperty prop = new CodeMemberProperty();

            prop.Attributes = MemberAttributes.Public;
            prop.Type       = new CodeTypeReference(typeof(string));
            prop.Name       = "ID";
            prop.HasGet     = true;
            prop.GetStatements.Add(new CodeSnippetExpression("return this." + fieldName));
            prop.HasSet = true;
            prop.SetStatements.Add(new CodeSnippetExpression("this." + fieldName + " = value"));

            file.Members.Add(prop);

            CodeMemberField fieldIsMandatory = new CodeMemberField();

            fieldIsMandatory.Attributes = MemberAttributes.Private | MemberAttributes.Const;
            fieldIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            fieldIsMandatory.Name       = "is" + StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "Mandatory";

            //switch case and set true or false
            fieldIsMandatory.InitExpression = new CodePrimitiveExpression(true);

            file.Members.Add(fieldIsMandatory);

            CodeMemberProperty propIsMandatory = new CodeMemberProperty();

            propIsMandatory.Attributes = MemberAttributes.Public;
            propIsMandatory.Type       = new CodeTypeReference(typeof(bool));
            propIsMandatory.Name       = "Is" + StringManipulationManager.CreateHungarianNotation(att.Name.Substring(4)) + "Mandatory";
            propIsMandatory.HasGet     = true;
            propIsMandatory.HasSet     = false;
            propIsMandatory.GetStatements.Add(new CodeSnippetExpression("return " + fieldIsMandatory.Name));

            file.Members.Add(propIsMandatory);

            nameSpace.Types.Add(file);

            Files.Add(unit);
        }
Exemplo n.º 23
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);
            }
        }
        private void ConnectModelElements(CIMModel CIM_Model, Assembly assembly, ref ConcreteModel concreteModel)
        {
            foreach (string type in CIM_Model.ModelMap.Keys)
            {
                SortedDictionary <string, CIMObject> objects = CIM_Model.ModelMap[type];
                foreach (string objID in objects.Keys)
                {
                    CIMObject element = objects[objID];
                    Type      classType;
                    classType = assembly.GetType(ActiveNamespace + "." + type);
                    if (classType == null)
                    {
                        OnMessage("Element (" + element.ID + ") not found in assembly:" + ActiveNamespace + "."
                                  + type + "  - validation of document failed!", MessageLevel.ERROR);
                        continue;
                    }

                    ////aquire object from concrete model
                    object currentObject = concreteModel.GetObjectByTypeAndID(classType, objID);
                    if (currentObject != null)
                    {
                        foreach (int attKey in element.MyAttributes.Keys)
                        {
                            string propertyName = StringManipulationManager.ExtractShortestName(CIM_Model.ModelContext.ReadAttributeWithCode(attKey), StringManipulationManager.SeparatorDot);
                            propertyName = StringManipulationManager.CreateHungarianNotation(propertyName);

                            if (propertyName.Equals(type))
                            {
                                propertyName = propertyName + "P";
                            }

                            PropertyInfo prop = classType.GetProperty(propertyName);
                            if (prop == null)
                            {
                                OnMessage("Property " + propertyName + " not found in class "
                                          + element.CIMType + ", elements ID:" + element.ID + "  - validation of document failed!", MessageLevel.ERROR);
                                continue;
                            }
                            ////if it is a list or collection of references
                            if (prop.PropertyType.IsGenericType)
                            {
                                Type propertyListType          = prop.PropertyType.GetGenericArguments()[0];
                                List <ObjectAttribute> attList = element.MyAttributes[attKey];
                                ////get the property as IList
                                IList list = (IList)prop.GetValue(currentObject, null);
                                foreach (ObjectAttribute att in attList)
                                {
                                    ////this part should add a reference to IList
                                    if (!IsSimpleValue(propertyListType) && !propertyListType.IsEnum)
                                    {
                                        AddReferenceToList(element, ref list, att.Value, prop, concreteModel);
                                    }
                                }
                            }
                            else
                            {
                                List <ObjectAttribute> attList = element.MyAttributes[attKey];
                                ////if its not a list...
                                ObjectAttribute att = attList.ElementAt(0);

                                if (null != prop && prop.CanWrite)
                                {
                                    if (!IsSimpleValue(prop.PropertyType) && !prop.PropertyType.IsEnum)
                                    {
                                        SetReferenceToProperty(element, currentObject, att.Value, prop, concreteModel);
                                    }
                                }
                            }
                        }
                        ////embeded elements - lists
                        if (element.GetEmbeddedChildren() != null)
                        {
                            foreach (string attKey in element.GetEmbeddedChildren().Keys)
                            {
                                ////first is the name of property
                                string propertyName = StringManipulationManager.ExtractShortestName(attKey, StringManipulationManager.SeparatorDot);
                                propertyName = StringManipulationManager.CreateHungarianNotation(propertyName);

                                if (propertyName.Equals(type))
                                {
                                    propertyName = propertyName + "P";
                                }
                                PropertyInfo prop = classType.GetProperty(propertyName);
                                if (prop != null && prop.PropertyType.IsGenericType)
                                {
                                    Type          propertyListType = prop.PropertyType.GetGenericArguments()[0];
                                    List <string> attList          = element.GetEmbeddedChildren()[attKey];
                                    ////get the property as IList
                                    IList list = (IList)prop.GetValue(currentObject, null);
                                    foreach (string att in attList)
                                    {
                                        ////this part should add a reference to IList
                                        if (!IsSimpleValue(propertyListType) && !propertyListType.IsEnum)
                                        {
                                            AddReferenceToList(element, ref list, att, prop, concreteModel);
                                        }
                                    }
                                }
                                else
                                {
                                    List <string> attList = element.GetEmbeddedChildren()[attKey];
                                    ////if its not a list...
                                    string att = attList.ElementAt(0);

                                    if (prop != null && prop.CanWrite)
                                    {
                                        if (!IsSimpleValue(prop.PropertyType) && !prop.PropertyType.IsEnum)
                                        {
                                            SetReferenceToProperty(element, currentObject, att, prop, concreteModel);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        OnMessage("Object of class:" + classType + ", with ID:" + objID + " not found in model! Unable to create concrete model."
                                  , MessageLevel.ERROR);
                    }
                }
            }
        }
        /// <summary>
        /// Reads all the "simple" values (not references) from attribute list and sets properties to the
        /// specified value
        /// </summary>
        /// <param name="assembly">assembly that contains class definitions</param>
        /// <param name="element">element being processes</param>
        /// <param name="classType">type of the instance</param>
        /// <param name="instance">instance of classType that will have properties set</param>
        private void ProcessAttributes(Assembly assembly, CIMObject element, Type classType, object instance)
        {
            foreach (int attKey in element.MyAttributes.Keys)
            {
                ////all properties have capital letters used for naming them
                string propertyName = StringManipulationManager.ExtractShortestName(element.ModelContext.ReadAttributeWithCode(attKey), StringManipulationManager.SeparatorDot);
                propertyName = StringManipulationManager.CreateHungarianNotation(propertyName);

                if (propertyName.Equals(element.CIMType))
                {
                    propertyName = propertyName + "P";
                }
                PropertyInfo prop = classType.GetProperty(propertyName);
                if (prop == null)
                {
                    OnMessage("Property " + propertyName + " not found in class "
                              + element.CIMType + " (element ID:" + element.ID + ")" + "  - validation of document failed!"
                              , MessageLevel.ERROR);
                    continue;
                }
                ////if it is a list or collection - though it always has to be a list
                if (prop.PropertyType.IsGenericType)
                {
                    ////gets the type of the items in list
                    Type propertyListType = prop.PropertyType.GetGenericArguments()[0];
                    ////get all the values for this property
                    List <ObjectAttribute> attList = element.MyAttributes[attKey];
                    ////get the property as IList
                    IList list = (IList)prop.GetValue(instance, null);

                    List <FTN.Commands> pomComm  = new List <FTN.Commands>();
                    List <FTN.States>   pomState = new List <FTN.States>();
                    if (attList.Count > 0)
                    {
                        string[] items = attList[0].Value.Split(' ');
                        foreach (var item in items)
                        {
                            if (item.Equals("Open"))
                            {
                                pomComm.Add(FTN.Commands.Open);
                            }
                            else if (item.Equals("Close"))
                            {
                                pomComm.Add(FTN.Commands.Close);
                            }
                        }
                        foreach (var item in items)
                        {
                            if (item.Equals("Opened"))
                            {
                                pomState.Add(FTN.States.Opened);
                            }
                            else if (item.Equals("Closed"))
                            {
                                pomState.Add(FTN.States.Closed);
                            }
                        }
                    }
                    foreach (ObjectAttribute att in attList)
                    {
                        ////Only add a simple value to IList, enumerations and references are not needed
                        if (IsSimpleValue(propertyListType))
                        {
                            AddSimpleValueToList(element, ref list, att, propertyListType);
                        }
                    }
                    if (pomComm.Count > 0)
                    {
                        prop.SetValue(instance, pomComm, null);
                    }
                    if (pomState.Count > 0)
                    {
                        prop.SetValue(instance, pomState, null);
                    }
                }
                else
                {
                    ////if property is not a list...
                    List <ObjectAttribute> attList = element.MyAttributes[attKey];
                    ////it only has one attribute value in list then
                    if (attList.Count <= 1)
                    {
                        ObjectAttribute att = attList.ElementAt(0);

                        if (null != prop)
                        {
                            if (IsSimpleValue(prop.PropertyType))
                            {
                                SetSimpleValue(element, instance, att, prop);
                            }
                            else
                            {
                                if (prop.PropertyType.IsEnum)
                                {
                                    SetEnumerationProperty(element, assembly, instance, prop, att);
                                }
                                else
                                {
                                    ////if it was not found up until now it has to be reference or data type
                                    ////if it is not empty and it is not any of the cases checked already it is DataType
                                    ////make instance of dataType and set value
                                    if (!IsSimpleValue(prop.PropertyType) && !string.IsNullOrEmpty(att.Value))
                                    {
                                        SetDataTypeProperty(element, assembly, instance, prop, att);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        OnMessage("Multiple values for attribute with multiplicity 1 on element with ID:" + element.ID + ". ATTRIBUTE: " + classType + "." + prop.Name
                                  , MessageLevel.WARNING);
                    }
                }
            }
        }
Exemplo n.º 26
0
        private void GenerateSetPropertyMethod(CodeTypeDeclaration file, EAPClass classPom)
        {
            CodeMemberMethod method = new CodeMemberMethod();

            method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            method.Name       = "SetProperty";
            method.ReturnType = new CodeTypeReference(typeof(void));
            method.Parameters.Add(new CodeParameterDeclarationExpression("Property", "property"));

            List <CodeSnippetStatement> snipets = new List <CodeSnippetStatement>()
            {
                new CodeSnippetStatement("\t\t\t\tswitch(property.Id)"), new CodeSnippetStatement("\t\t\t\t{")
            };

            foreach (EAPAttribute att in classPom.Attributes)
            {
                if (att.IsListOfReferences == true)
                {
                    continue;
                }
                CodeSnippetStatement css     = new CodeSnippetStatement("\t\t\t\t\tcase ModelCode." + att.Code + ":");
                CodeSnippetStatement cssProp = new CodeSnippetStatement();
                if (att.TypeCode != "" && att.TypeCode.Equals("Enum"))
                {
                    cssProp = new CodeSnippetStatement("\t\t\t\t\t\t" + att.Name + " = (" + att.MeasurementType + ") property.AsEnum();");
                }
                else if (att.IsReference == true || att.TypeCode.Equals("Class"))
                {
                    cssProp = new CodeSnippetStatement("\t\t\t\t\t\t" + att.Name + " = property.AsReference();");
                }
                else
                {
                    cssProp = new CodeSnippetStatement("\t\t\t\t\t\t" + att.Name + " = property." + StringManipulationManager.GetAsMethod(att.MeasurementType));
                }
                CodeSnippetStatement cssBreak = new CodeSnippetStatement("\t\t\t\t\t\tbreak;");
                snipets.Add(css); snipets.Add(cssProp); snipets.Add(cssBreak);
            }
            CodeSnippetStatement cssDefault      = new CodeSnippetStatement("\t\t\t\t\tdefault:");
            CodeSnippetStatement cssBase         = new CodeSnippetStatement("\t\t\t\t\t\tbase.SetProperty(property);");
            CodeSnippetStatement cssBreakDefault = new CodeSnippetStatement("\t\t\t\t\t\tbreak;");
            CodeSnippetStatement ccss            = new CodeSnippetStatement("\t\t\t\t}");

            snipets.Add(cssDefault); snipets.Add(cssBase); snipets.Add(cssBreakDefault); snipets.Add(ccss);
            foreach (var item in snipets)
            {
                method.Statements.Add(item);
            }

            file.Members.Add(method);
        }
Exemplo n.º 27
0
        public override string ToString()
        {
            StringBuilder toStringBuilder = new StringBuilder("Profile: \n");

            if (profileMap != null)
            {
                if (profileMap.ContainsKey(ProfileElementTypes.ClassCategory))
                {
                    foreach (ProfileElement package in profileMap[ProfileElementTypes.ClassCategory])
                    {
                        toStringBuilder.Append("* members of ");
                        toStringBuilder.AppendLine(package.UniqueName);
                        List <ProfileElement> list = (package as ClassCategory).MembersOfClassCategory;
                        if (list != null)
                        {
                            foreach (ProfileElement elem in list)
                            {
                                if (elem is Class)
                                {
                                    toStringBuilder.Append("\t ").AppendLine(elem.URI);
                                    toStringBuilder.Append("\t\t type = ").AppendLine(elem.Type);
                                    toStringBuilder.Append("\t\t label = ").AppendLine(elem.Label);
                                    if (elem.IsEnumeration)
                                    {
                                        toStringBuilder.AppendLine("\t\t Enumeration class");
                                    }

                                    if ((elem as Class).Stereotypes != null)
                                    {
                                        toStringBuilder.AppendLine("\t\t has Stereotypes : ");
                                        foreach (ProfileElementStereotype stereotype in (elem as Class).Stereotypes)
                                        {
                                            toStringBuilder.Append("\t\t\t").AppendLine(stereotype.ToString());
                                        }
                                    }

                                    toStringBuilder.Append("\t\t subClassOf = ").AppendLine((elem as Class).SubClassOf);
                                    toStringBuilder.Append("\t\t belongsToCategory = ").AppendLine((elem as Class).BelongsToCategory);
                                    if ((elem as Class).MyProperties != null)
                                    {
                                        toStringBuilder.AppendLine("\t\t has Properties : ");
                                        foreach (ProfileElement property in (elem as Class).MyProperties)
                                        {
                                            toStringBuilder.Append("\t\t\t").AppendLine(property.UniqueName);
                                            toStringBuilder.Append("\t\t\t\t label = ").AppendLine(property.Label);
                                            toStringBuilder.Append("\t\t\t\t dataType = ").AppendLine((property as Property).DataType);
                                            toStringBuilder.Append("\t\t\t\t range = ").AppendLine((property as Property).Range);
                                            toStringBuilder.Append("\t\t\t\t multiplicity = ").AppendLine(StringManipulationManager.ExtractShortestName(property.MultiplicityAsString, StringManipulationManager.SeparatorSharp));

                                            if (property.Stereotypes != null)
                                            {
                                                toStringBuilder.AppendLine("\t\t\t\t has Stereotypes : ");
                                                foreach (ProfileElementStereotype stereotype in property.Stereotypes)
                                                {
                                                    toStringBuilder.Append("\t\t\t\t\t").AppendLine(stereotype.ToString());
                                                }
                                            }
                                            toStringBuilder.AppendLine();
                                        }
                                    }

                                    if ((elem as Class).MyEnumerationMembers != null)
                                    {
                                        toStringBuilder.AppendLine("\t\t\t has enum members : ");
                                        foreach (ProfileElement enumMember in (elem as Class).MyEnumerationMembers)
                                        {
                                            toStringBuilder.Append("\t\t\t\t").AppendLine(enumMember.UniqueName);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(toStringBuilder.ToString());
        }
        private void CollenctConectors(EAPModel model, Connector l_Attr, EAPClass l_Class, bool group, EA.Element l_class)
        {
            EAPAttribute l_MyAttr = new EAPAttribute();

            l_MyAttr.Description = l_Attr.Notes;


            if (l_MyAttr.Description.Split(':').Length > 1)
            {
                l_MyAttr.Title       = l_MyAttr.Description.Split(':')[0];
                l_MyAttr.Description = l_MyAttr.Description.Remove(0, l_MyAttr.Title.Length + 1);
            }
            else
            {
                l_MyAttr.Title       = "";
                l_MyAttr.Description = l_MyAttr.Description.Trim();
            }

            l_MyAttr.Title       = l_MyAttr.Title.Replace("<b>", "").Replace("</b>", "").Replace("<i>", "").Replace("</i>", "").Trim();
            l_MyAttr.Description = l_MyAttr.Description.Replace("<b>", "").Replace("</b>", "").Replace("<i>", "").Replace("</i>", "").Trim();

            l_MyAttr.Code = l_Attr.Alias;
            bool pom = false;

            if (l_class.ElementID == l_Attr.ClientID)
            {
                l_MyAttr.Name = l_Attr.SupplierEnd.Role;
                l_MyAttr.Code = l_Attr.SupplierEnd.Alias;
                if (StringManipulationManager.GetMaxCardinality(l_Attr.SupplierEnd.Cardinality).Equals("*"))
                {
                    l_MyAttr.Max = "*";
                    string min = l_Attr.SupplierEnd.Cardinality.Substring(0, 1);
                    l_MyAttr.Min = min;
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.ClientEnd.Role, l_Attr.ClientEnd.Alias);
                }
                else if (StringManipulationManager.GetMaxCardinality(l_Attr.SupplierEnd.Cardinality).Equals("1"))
                {
                    l_MyAttr.Max = "1";
                    l_MyAttr.Min = "1";
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.ClientEnd.Role, l_Attr.ClientEnd.Alias);
                }
                else if (StringManipulationManager.GetMaxCardinality(l_Attr.ClientEnd.Cardinality).Equals("2"))
                {
                    l_MyAttr.Max = "2";
                    l_MyAttr.Min = "0";
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.ClientEnd.Role, l_Attr.ClientEnd.Alias);
                }
                pom = true;
            }
            else
            {
                l_MyAttr.Name = l_Attr.ClientEnd.Role;
                l_MyAttr.Code = l_Attr.ClientEnd.Alias;
                if (StringManipulationManager.GetMaxCardinality(l_Attr.ClientEnd.Cardinality).Equals("*"))
                {
                    l_MyAttr.Max = "*";
                    string min = l_Attr.ClientEnd.Cardinality.Substring(0, 1);
                    l_MyAttr.Min = min;
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.SupplierEnd.Role, l_Attr.SupplierEnd.Alias);
                }
                else if (StringManipulationManager.GetMaxCardinality(l_Attr.ClientEnd.Cardinality).Equals("1"))
                {
                    l_MyAttr.Max = "1";
                    l_MyAttr.Min = "1";
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.SupplierEnd.Role, l_Attr.SupplierEnd.Alias);
                }
                else if (StringManipulationManager.GetMaxCardinality(l_Attr.ClientEnd.Cardinality).Equals("2"))
                {
                    l_MyAttr.Max = "2";
                    l_MyAttr.Min = "0";
                    // pair of attributes on same connector for Add and Remove Ref
                    l_MyAttr.onSameConnectorPairAtt = new EAPAttribute(l_Attr.SupplierEnd.Role, l_Attr.SupplierEnd.Alias);
                }
            }

            if (l_MyAttr.Max == "*")
            {
                if (pom)
                {
                    l_MyAttr.MeasurementType = "List<" + FindClassById(l_Attr.SupplierID, MyModelCopy) + ">";
                }
                else
                {
                    l_MyAttr.MeasurementType = "List<" + FindClassById(l_Attr.ClientID, MyModelCopy) + ">";
                }

                l_MyAttr.IsListOfReferences = true;
            }
            else if (l_MyAttr.Max == "1")
            {
                l_MyAttr.MeasurementType = "long";
                l_MyAttr.IsReference     = true;
            }


            //  FindType(l_Class, l_MyAttr, l_Attr);

            //l_MyAttr.Aggregated = GetAggregated(l_Attr, l_MyAttr);
            //   l_MyAttr.Searchable = GetSearchable(l_Attr, l_MyAttr);
            //  l_MyAttr.Cardinality = GetCardinality(l_Attr, l_MyAttr) == 0 ? null : GetCardinality(l_Attr, l_MyAttr).ToString();

            if (!(l_Class.AddAttribute(l_MyAttr)))
            {
                if (Validate)
                {
                    tw.WriteLine("Attribute Model Code:" + l_Attr.Alias + ",  already exists in Class name: " + l_Class.Name + ". (Look at EAP)");

                    tw.WriteLine("*************************************************************************");
                    tw.WriteLine("\n\n");
                }
            }
        }
Exemplo n.º 29
0
        private CodeCompileUnit CreateClass(EAPModel model, EAPClass classPom, bool flagDb)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            //namespace
            CodeNamespace nameSpace = new CodeNamespace("Default_Namespace");

            unit.Namespaces.Add(nameSpace);
            //namespace imports
            nameSpace.Imports.Add(new CodeNamespaceImport("System"));

            CodeTypeDeclaration file = new CodeTypeDeclaration();

            file.IsClass        = true;
            file.Name           = classPom.Name;
            file.TypeAttributes = TypeAttributes.Public;
            file.Attributes     = MemberAttributes.Public;

            if (classPom.Parent != null)
            {
                file.BaseTypes.Add(new CodeTypeReference(classPom.Parent));

                nameSpace.Imports.Add(new CodeNamespaceImport("Default_Namespace"));
            }
            else
            {
                //if class doesn't have a parent,
                //it should extend IDClass as the root of hierarhy - for rdf:ID
                file.BaseTypes.Add(new CodeTypeReference("IDClass"));
                nameSpace.Imports.Add(new CodeNamespaceImport("Default_Namespace"));
            }

            if (!string.IsNullOrEmpty(classPom.Description))
            {
                file.Comments.Add(new CodeCommentStatement(classPom.Description, true));
            }
            //Generate constructor without param
            CodeConstructor baseStringConstructorSimple = new CodeConstructor();

            baseStringConstructorSimple.Attributes = MemberAttributes.Public;

            //Gererating constuctor with param
            CodeConstructor baseStringConstructor = new CodeConstructor();

            baseStringConstructor.Attributes = MemberAttributes.Public;
            baseStringConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("globalId"));
            baseStringConstructor.Parameters.Add(new CodeParameterDeclarationExpression("System.Int64", "globalId"));

            file.Members.Add(baseStringConstructorSimple);
            file.Members.Add(baseStringConstructor);

            List <EAPAttribute> attributes = new List <EAPAttribute>();


            if (classPom.Attributes.Count > 0)
            {
                foreach (EAPAttribute attribut in classPom.Attributes)
                {
                    CodeMemberField att = null;
                    if (attribut.MeasurementType != "")
                    {
                        if (Enum.IsDefined(typeof(MeasurementType), attribut.MeasurementType.ToUpper()) || attribut.MeasurementType.Contains("List<") || attribut.TypeCode.Equals("Enum") ||
                            attribut.TypeCode.Equals("Class"))
                        {
                            if (attribut.Max == "*")
                            {
                                nameSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));

                                string fieldName = attribut.Name;

                                att                = new CodeMemberField(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(attribut.MeasurementType.Split('<', '>')[1]) }), fieldName);
                                att.Attributes     = MemberAttributes.Private | MemberAttributes.Final;
                                att.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference("List", new CodeTypeReference[] { new CodeTypeReference(attribut.MeasurementType.Split('<', '>')[1]) }));
                                if (!string.IsNullOrEmpty(attribut.Description))
                                {
                                    att.Comments.Add(new CodeCommentStatement(attribut.Description, true));
                                }
                                file.Members.Add(att);

                                CreatePropertyForField(file, att, true, true);
                            }
                            else
                            {
                                string fieldName = attribut.Name;
                                string type      = attribut.MeasurementType;
                                // att = new CodeMemberField(StringManipulationManager.GetSystemType(type), fieldName);
                                if (attribut.TypeCode != null && attribut.TypeCode != "")
                                {
                                    if (attribut.TypeCode.Equals("Enum"))
                                    {
                                        att = new CodeMemberField(attribut.MeasurementType, fieldName);
                                    }
                                    if (attribut.TypeCode.Equals("Class"))
                                    {
                                        att = new CodeMemberField(attribut.MeasurementType, fieldName);
                                    }
                                }
                                else
                                {
                                    att = new CodeMemberField(StringManipulationManager.GetSystemType(type), fieldName);
                                }

                                att.Attributes = MemberAttributes.Private | MemberAttributes.Final;
                                if (!string.IsNullOrEmpty(attribut.Description))
                                {
                                    att.Comments.Add(new CodeCommentStatement(attribut.Description, true));
                                }
                                if (type.Equals("long") && attribut.IsReference == true)
                                {
                                    att.InitExpression = new CodeSnippetExpression("0");
                                }
                                file.Members.Add(att);

                                //property for the field
                                CreatePropertyForField(file, attribut, att, true, true);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                if (IsDbSelected && flagDb == false)
                {
                    GenerateIDForDb(file, classPom.Name);   // generate id if db checbox is selected
                }
                if (flagDb)
                {
                    GenerateEqualsMethod(file, classPom);
                    GenerateHashCodeMethod(file, classPom);
                    GenerateGetProperty(file, classPom);
                    GenerateHasPropertyMethod(file, classPom);
                    GenerateSetPropertyMethod(file, classPom);
                    GenerateIsReferencedProperty(file, classPom);
                    GenerateGetReferencesMethod(file, classPom);
                    GenerateAddreferenceMethod(file, classPom);
                    GenerateRemoveReferencMethod(file, classPom);
                }
            }
            else
            {
                if (flagDb)
                {
                    GenerateEqualsMethod(file, classPom);
                    GenerateHashCodeMethod(file, classPom);
                    GenerateGetProperty(file, classPom);
                    GenerateHasPropertyMethod(file, classPom);
                    GenerateSetPropertyMethod(file, classPom);
                    GenerateGetReferencesMethod(file, classPom);
                }
            }

            nameSpace.Types.Add(file);
            return(unit);
        }