Example #1
0
        public string[] ExtractModelClass(bool serializable, bool validationReady, bool validationMsgReady, bool ropSqlReady, bool gzipReady, bool wcfReady, bool jsonMinReady, FuncionalityConfig funcConfig)
        {
            string[] result = new string[2];
            List<string> defaultNamespaces = new List<string>();

            defaultNamespaces.Add("using System;");
            Model modelPreConfig = new Model()
            {
                Serializable = serializable,
                ValidationEnable = validationReady || validationMsgReady,
                ValidationMsgEnable = validationMsgReady,
                RopSqlEnable = ropSqlReady,
                GzipEnable = gzipReady,
                WcfEnable = wcfReady,
                JsonMinEnable = jsonMinReady,
                NavMenu = (funcConfig != null),

                Namespaces = defaultNamespaces
            };

            if (modelPreConfig.NavMenu)
            {
                modelPreConfig.FuncionalityGroup = funcConfig.Group;
                modelPreConfig.FuncionalitySubGroup = funcConfig.SubGroup;
                modelPreConfig.FuncionalityAccess = funcConfig.Access;
            }

            result[0] = parseScript(modelPreConfig, scpContent);
            result[1] = modelPreConfig.EntityName;

            return result;
        }
Example #2
0
        private void setEntityAttributeAnnotations(Model modelPreConfig, ref List<ModelAttribute> attributeList)
        {
            List<string> annotationList = null;

            int contAlpha = 97;
            int contComplem = 1;
            foreach (var attrib in attributeList)
            {
                if (contAlpha == 123)
                {
                    contAlpha = 97;
                    contComplem = 1;
                }

                annotationList = new List<string>();

                if (modelPreConfig.WcfEnable)
                    annotationList.Add("[DataMember]");

                annotationList.Add(string.Concat("[DisplayName(\"", attrib.AttributeName, "\")]"));

                if (modelPreConfig.RopSqlEnable && !attrib.Composition)
                {
                    var dataColumnConfig = string.Concat("[DataColumn(ColumnName = \"", attrib.AttributeColumn, "\"",
                                                         attrib.PrimaryKey ? ", PrimaryKey = true" : string.Empty,
                                                         attrib.AutoNumber ? ", AutoNumbering = true" : string.Empty,
                                                         attrib.Required ? ", Required = true" : string.Empty, ")]");

                    annotationList.Add(dataColumnConfig);
                }

                if (modelPreConfig.Serializable && modelPreConfig.JsonMinEnable)
                    annotationList.Add(string.Format("[JsonProperty(PropertyName = \"{0}\")]",
                                                    ((char)contAlpha++).ToString(), contComplem++.ToString()));

                if (modelPreConfig.ValidationEnable)
                {
                    if (attrib.Required)
                        if (modelPreConfig.ValidationMsgEnable)
                        {
                            var foreignKey = attrib.AttributeName.StartsWith("Id");
                            var reqMsg = string.Format(getValidationMsg(!foreignKey ? ValidationType.Required : ValidationType.ForeignKey),
                                                                        !foreignKey ? attrib.AttributeName :
                                                                        getCompositionEntity(attrib.AttributeName, attrib.AttributeColumn).AttributeName);
                            annotationList.Add(string.Concat("[Required(ErrorMessage = \"", reqMsg, "\")]"));
                        }
                        else
                            annotationList.Add("[Required]");

                    if (attrib.StringLength > 0)
                        if (modelPreConfig.ValidationMsgEnable)
                        {
                            var strLenMsg = string.Format(getValidationMsg(ValidationType.StringLength), attrib.AttributeName, attrib.StringLength);
                            annotationList.Add(string.Concat("[StringLength(", attrib.StringLength.ToString(), ", ErrorMessage = \"", strLenMsg, "\")]"));
                        }
                        else
                            annotationList.Add(string.Concat("[StringLength(", attrib.StringLength.ToString(), ")]"));

                    var numericTypes = new List<string> { "decimal", "float", "double" };
                    var numericTypesInt = new List<string> { "byte", "short", "int", "long" };
                    var numAttribMsg = string.Format(getValidationMsg(ValidationType.Numeric), attrib.AttributeName);
                    var numAttribMsgInt = string.Format(getValidationMsg(ValidationType.NumericInteger), attrib.AttributeName);
                    if (attrib.Required && modelPreConfig.ValidationMsgEnable)
                    {
                        if (numericTypes.Contains(attrib.AttributeType))
                            annotationList.Add(string.Concat("[RegularExpression(\"^[0-9]*\\\\.?\\\\,?[0-9]+$\", ErrorMessage = \"", numAttribMsg, "\")]"));
                        else if (numericTypesInt.Contains(attrib.AttributeType))
                            annotationList.Add(string.Concat("[RegularExpression(\"^[0-9]*$\", ErrorMessage = \"", numAttribMsgInt, "\")]"));
                    }
                }

                if (attrib.Composition)
                {
                    StringBuilder compositAnnot = new StringBuilder();
                    compositAnnot.AppendLine("[RelatedEntity(Cardinality = RelationCardinality.OneToOne,");
                    compositAnnot.AppendLine(string.Concat("\t\t\t\t\t   ForeignKeyAttribute = \"", getPascalCase(attrib.AttributeColumn), "\","));
                    compositAnnot.Append("\t\t\t\t\t   RecordableComposition = false)]");
                    annotationList.Add(compositAnnot.ToString());
                }

                attrib.Annotations = annotationList;
            }
        }
Example #3
0
        private string parseScript(Model modelPreConfig, string scriptContent)
        {
            modelPreConfig.EntityTable = getScriptEntityName(scriptContent);
            modelPreConfig.EntityName = getPascalCase(modelPreConfig.EntityTable);
            var attributeList = getScriptEntityAttributes(scriptContent);

            setEntityAnnotations(modelPreConfig);
            setEntityAttributeAnnotations(modelPreConfig, ref attributeList);

            modelPreConfig.Attributes = attributeList;

            return compositeModelClass(modelPreConfig);
        }
Example #4
0
        private void setEntityAnnotations(Model modelPreConfig)
        {
            List<string> annotationList = new List<string>();

            if (modelPreConfig.Serializable)
                annotationList.Add("[Serializable]");

            if (modelPreConfig.ValidationEnable)
            {
                modelPreConfig.Namespaces.Add("using System.ComponentModel;");
                modelPreConfig.Namespaces.Add("using System.ComponentModel.DataAnnotations;");
            }

            if (modelPreConfig.WcfEnable)
            {
                modelPreConfig.Namespaces.Add("using System.Runtime.Serialization;");
                annotationList.Add("[DataContract(IsReference = true)]");
            }

            if (modelPreConfig.RopSqlEnable)
            {
                modelPreConfig.Namespaces.Add("using System.Data.RopSql.DataAnnotations;");
                annotationList.Add(string.Concat("[DataTable(TableName = \"", modelPreConfig.EntityTable, "\")]"));
            }

            if (modelPreConfig.NavMenu)
            {
                modelPreConfig.Namespaces.Add("using System.Security.InMemProfile.Annotations;");
                annotationList.Add(string.Concat("[DisplayName(\"", modelPreConfig.EntityName, "\")]"));
                annotationList.Add(string.Concat("[Funcionality(FuncionalityGroup = \"", modelPreConfig.FuncionalityGroup, "\",", Environment.NewLine,
                                                 "                      FuncionalitySubGroup = \"", modelPreConfig.FuncionalitySubGroup, "\",", Environment.NewLine,
                                                 "                      FuncionalityAccess = \"/", modelPreConfig.EntityName, "\")]"));
            }

            modelPreConfig.Annotations = annotationList;
        }
Example #5
0
        private string compositeModelClass(Model modelPreConfig)
        {
            StringBuilder classBody = new StringBuilder();

            foreach (var nmspace in modelPreConfig.Namespaces)
                classBody.AppendLine(nmspace);

            classBody.AppendLine();
            classBody.Append("namespace ");
            classBody.Append(classNamespace);
            classBody.AppendLine(".Models");
            classBody.AppendLine("{");

            foreach (var annot in modelPreConfig.Annotations)
                classBody.AppendLine(string.Concat("\t", annot));

            classBody.Append("\tpublic class ");
            classBody.AppendLine(modelPreConfig.EntityName);
            classBody.AppendLine("\t{");

            foreach (var attrib in modelPreConfig.Attributes)
            {
                if (attrib.Annotations.Count > 0)
                    classBody.AppendLine();
                foreach(var anot in attrib.Annotations)
                    classBody.AppendLine(string.Concat("\t\t", anot));

                classBody.Append("\t\tpublic ");
                classBody.Append(string.Concat(attrib.AttributeType, " "));
                classBody.Append(string.Concat(attrib.AttributeName));
                classBody.AppendLine(" { get; set; }");
            }

            classBody.AppendLine("\t}");
            classBody.AppendLine("}");

            return classBody.ToString();
        }