public int GetCardinality(EA.Attribute l_Attr, EAPAttribute l_MyAttr) { int cardinality = 0; foreach (EA.AttributeConstraint str in l_Attr.Constraints) { if (str.Name.ToLower() == "cardinality") { try { cardinality = Convert.ToInt32(str.Notes.Trim()); return(cardinality); } catch { if (Validate) { tw.WriteLine("Model Code: {0},", l_MyAttr.Code); tw.WriteLine("Name: {0},", l_MyAttr.Name); tw.WriteLine("Cardinality: {0},\n", str.Notes); tw.WriteLine(str + "cardinality value can not be converted in int."); tw.WriteLine("*************************************************************************"); tw.WriteLine("\n\n"); } } } } return(cardinality); }
public void FindType(EAPClass l_Class, EAPAttribute l_MyAttr, EA.Attribute l_Attr) { //PropertyType type = 0; if ((l_MyAttr.Code != null && l_MyAttr.Code != "") || true) { if (Enum.IsDefined(typeof(MeasurementType), l_Attr.Type.ToUpper())) { l_MyAttr.MeasurementType = l_Attr.Type; } else { List <string> typeStr = new List <string>() { "bool", "int", "long", "string", "short", "double", "float", "byte", "modelcode", "lid", "gid" }; if (l_Attr.Type.Split('<').Length > 1) { string helpString = l_Attr.Type.Remove(0, (l_Attr.Type.IndexOf('<') + 1)); // l_MyAttr.MeasurementType = helpString.Remove(helpString.IndexOf('>')); l_MyAttr.MeasurementType = l_Attr.Type; if (Enum.IsDefined(typeof(MeasurementType), helpString.Remove(helpString.IndexOf('>')))) { l_MyAttr.MeasurementType = helpString.Remove(helpString.IndexOf('>')); } else { l_MyAttr.MeasurementType = l_Attr.Type; } } else { if (!typeStr.Contains(l_Attr.Type.ToLower())) { l_MyAttr.MeasurementType = l_Attr.Type; } else if (typeStr.Contains(l_Attr.Type.ToLower())) { //GenerateUIControlsBasedOnPropType(l_Attr.Type.ToLower(), l_MyAttr, false); } } } } }
public bool GetSearchable(EA.Attribute l_Attr, EAPAttribute l_MyAttr) { bool searchable = false; foreach (EA.AttributeConstraint str in l_Attr.Constraints) { if (str.Name.ToLower() == "searchable") { try { if (str.Notes.Trim() == "0") { return(false); } else if (str.Notes.Trim() == "1") { return(true); } searchable = Convert.ToBoolean(str.Notes.Trim()); return(searchable); } catch { if (Validate) { tw.WriteLine("Model Code: {0},", l_MyAttr.Code); tw.WriteLine("Name: {0},", l_MyAttr.Name); tw.WriteLine("Searchable: {0},\n", str.Notes); tw.WriteLine(str.Notes + "searchable value can not be converted in bool."); tw.WriteLine("*************************************************************************"); tw.WriteLine("\n\n"); } } } } return(searchable); }
public bool GetAggregated(EA.Attribute l_Attr, EAPAttribute l_MyAttr) { bool aggregated = false; foreach (EA.AttributeConstraint str in l_Attr.Constraints) { if (str.Name.ToLower() == "aggregated") { try { if (str.Notes.Trim() == "0") { return(false); } else if (str.Notes.Trim() == "1") { return(true); } aggregated = Convert.ToBoolean(str.Notes.Trim()); return(aggregated); } catch { if (Validate) { tw.WriteLine("Model Code: {0},", l_MyAttr.Code); tw.WriteLine("Name: {0},", l_MyAttr.Name); tw.WriteLine("Aggregated: {0},\n", str.Notes); tw.WriteLine(str + "aggregated value can not be converted in bool."); tw.WriteLine("*************************************************************************"); tw.WriteLine("\n\n"); } } } } return(aggregated); }
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); }
public void CollectAttribute(EAPModel model, EA.Attribute l_Attr, EAPClass l_Class, bool group, EAPClass l_ClassGroup = null) { EAPAttribute l_MyAttr = new EAPAttribute(); l_MyAttr.Description = l_Attr.Notes; l_MyAttr.Settable = !l_Attr.IsConst; l_MyAttr.Max = l_Attr.UpperBound; l_MyAttr.Min = l_Attr.LowerBound; l_MyAttr.Index = l_Attr.Pos; l_MyAttr.Default = ReturnValue(l_MyAttr, l_Attr); l_MyAttr.Visible = !l_Attr.IsStatic; if (model.Enums.ContainsKey(l_Attr.Type)) { l_MyAttr.TypeCode = "Enum"; } if (model.Classes.ContainsKey(l_Attr.Type)) { l_MyAttr.TypeCode = "Class"; } if (group) { if (l_ClassGroup == null) { l_MyAttr.Group = l_Class.Code; } else { l_MyAttr.Group = l_ClassGroup.Code; } } 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.Style; l_MyAttr.Name = l_Attr.Name; 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.Style + ", already exists in Class name: " + l_Class.Name + ". (Look at EAP)"); tw.WriteLine("*************************************************************************"); tw.WriteLine("\n\n"); } } }
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"); } } }
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); }