예제 #1
0
        public string GenerateScriptListAll()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_ListAll);

            TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS");

            TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT");
                selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                selectColumnsSectionList.AddSection(selectColumnsSection);
            }

            template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ",");

            template.ReplaceTag("LISTALL_STORED_PROCEDURE", ListAllStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #2
0
        /// <summary>
        /// Generars the codigo domain.
        /// </summary>
        /// <returns></returns>
        public string GenerateCodeDomain()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_Domain);

            TemplateSection sectionProperties = template.ExtractSection("PROPERTIES");
            TemplateSection sectionParameters = template.ExtractSection("PARAMETERS");

            TemplateSectionCollection propertiesSectionList = new TemplateSectionCollection();
            TemplateSectionCollection parametersSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection propertySection = sectionProperties.ExtractSection(entityField.SimpleTypeName);
                propertySection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesSectionList.AddSection(propertySection);

                TemplateSection parameterSection = sectionParameters.ExtractSection(entityField.SimpleTypeName);
                parameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                parametersSectionList.AddSection(parameterSection);
            }

            template.ReplaceSection("PROPERTIES", propertiesSectionList);
            template.ReplaceSection("PARAMETERS", parametersSectionList);
            template.ReplaceTag("NAMESPACE_DOMAIN", Settings[CodeBaseConstants.NAMESPACE_DOMAIN].Value, false);
            template.ReplaceTag("CLASS_NAME_DOMAIN", DomainClassName, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #3
0
        internal string GenerateViewIndex()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Index);

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            TemplateSection sectionHeader = template.ExtractSection("HEADER");
            TemplateSection sectionRow    = template.ExtractSection("ROW");

            TemplateSectionCollection propertiesHeaderList = new TemplateSectionCollection();
            TemplateSectionCollection propertiesRowList    = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection columnSection = sectionHeader.ExtractSection("COLUMN");
                columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesHeaderList.AddSection(columnSection);

                columnSection = sectionRow.ExtractSection("COLUMN");
                columnSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesRowList.AddSection(columnSection);
            }

            template.ReplaceSection("HEADER", propertiesHeaderList);
            template.ReplaceSection("ROW", propertiesRowList);

            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false);
            template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false);

            template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false);
            template.ReplaceTag("CREATE_VIEWNAME", Settings[AspNetMvcCoreConstants.CREATE_VIEWNAME].Value, false);
            template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false);
            template.ReplaceTag("DETAILS_VIEWNAME", Settings[AspNetMvcCoreConstants.DETAILS_VIEWNAME].Value, false);
            template.ReplaceTag("DELETE_VIEWNAME", Settings[AspNetMvcCoreConstants.DELETE_VIEWNAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #4
0
        internal string GenerateViewEdit()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.HTML, Resources.view_Edit);

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            TemplateSection sectionForm = template.ExtractSection("FORM");

            TemplateSectionCollection propertiesFormList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields.Where(f => !f.IsPrimaryKey))
            {
                TemplateSection fieldSection = sectionForm.ExtractSection("FIELD");
                fieldSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                propertiesFormList.AddSection(fieldSection);
            }

            template.ReplaceSection("FORM", propertiesFormList);

            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("NAMESPACE_MODELS", Settings[AspNetMvcCoreConstants.NAMESPACE_MODELS].Value, false);
            template.ReplaceTag("CLASS_NAME_MODEL", ModelClassName, false);

            template.ReplaceTag("EDIT_VIEWNAME", Settings[AspNetMvcCoreConstants.EDIT_VIEWNAME].Value, false);
            template.ReplaceTag("INDEX_VIEWNAME", Settings[AspNetMvcCoreConstants.INDEX_VIEWNAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[AspNetMvcCoreConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #5
0
        public string GenerateScriptGetById()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_GetByID);

            TemplateSection sectionSelectColumns = template.ExtractSection("SELECT_COLUMNS");

            TemplateSectionCollection selectColumnsSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection selectColumnsSection = sectionSelectColumns.ExtractSection("DEFAULT");
                selectColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                selectColumnsSectionList.AddSection(selectColumnsSection);
            }

            template.ReplaceSection("SELECT_COLUMNS", selectColumnsSectionList, ",");

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false);

            template.ReplaceTag("GETBYID_STORED_PROCEDURE", GetByIdStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #6
0
        public string GenerateScriptSave()
        {
            TemplateFile template = TemplateFile.LoadTemplate(TemplateType.SQL, Resources.sp_Save);

            TemplateSection sectionParameters       = template.ExtractSection("PARAMETERS");
            TemplateSection sectionUpdateParameters = template.ExtractSection("UPDATE_PARAMETERS");
            TemplateSection sectionInsertColumns    = template.ExtractSection("INSERT_COLUMNS");
            TemplateSection sectionInsertParameters = template.ExtractSection("INSERT_PARAMETERS");

            TemplateSectionCollection parameterSectionList       = new TemplateSectionCollection();
            TemplateSectionCollection updateParameterSectionList = new TemplateSectionCollection();
            TemplateSectionCollection insertColumnsSectionList   = new TemplateSectionCollection();
            TemplateSectionCollection insertParameterSectionList = new TemplateSectionCollection();

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection parameterSection = sectionParameters.ExtractSection("DEFAULT");
                parameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                parameterSection.ReplaceTag("DATATYPE", entityField.TypeName);
                parameterSectionList.AddSection(parameterSection);

                if (!entityField.IsPrimaryKey)
                {
                    TemplateSection updateParameterSection = sectionUpdateParameters.ExtractSection("DEFAULT");
                    updateParameterSection.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                    updateParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                    updateParameterSectionList.AddSection(updateParameterSection);

                    TemplateSection insertColumnsSection = sectionInsertColumns.ExtractSection("DEFAULT");
                    insertColumnsSection.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                    insertColumnsSectionList.AddSection(insertColumnsSection);

                    TemplateSection insertParameterSection = sectionInsertParameters.ExtractSection("DEFAULT");
                    insertParameterSection.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                    insertParameterSectionList.AddSection(insertParameterSection);
                }
            }

            template.ReplaceSection("PARAMETERS", parameterSectionList, ",");
            template.ReplaceSection("UPDATE_PARAMETERS", updateParameterSectionList, ",");
            template.ReplaceSection("INSERT_COLUMNS", insertColumnsSectionList, ",");
            template.ReplaceSection("INSERT_PARAMETERS", insertParameterSectionList, ",");

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            template.ReplaceTag("PRIMARYKEY_DATATYPE", primaryEntityField.TypeName, false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_PROPERTYNAME", primaryEntityField.ColumnName, false);

            template.ReplaceTag("SAVE_STORED_PROCEDURE", SaveStoredProcedureName, false);
            template.ReplaceTag("ENTITY_NAME", Entity.Name, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }
예제 #7
0
        public string GenerateCodeDataAccessAsync()
        {
            TemplateFile template;
            string       templateType = Settings[CodeBaseConstants.DATAACCESS_TEMPLATE].Value;

            if (templateType.Equals("en"))
            {
                template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async_en);
            }
            else if (templateType.Equals("es"))
            {
                template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async_es);
            }
            else
            {
                template = TemplateFile.LoadTemplate(TemplateType.CS, Resources.class_DataAccess_async);
            }

            var primaryEntityField = Entity.Fields.FirstOrDefault(f => f.IsPrimaryKey);

            if (primaryEntityField == null)
            {
                throw new DataException("Entity [" + Entity.Name + "] doesn't have primary key");
            }

            TemplateSection sectionParameters      = template.ExtractSection("PARAMETERS");
            TemplateSection sectionParametersAsync = template.ExtractSection("PARAMETERS_ASYNC");
            TemplateSection sectionProperties      = template.ExtractSection("PROPERTIES");
            TemplateSection sectionPropertiesAsync = template.ExtractSection("PROPERTIES_ASYNC");

            TemplateSectionCollection sectionParameterList      = new TemplateSectionCollection();
            TemplateSectionCollection sectionParameterAsyncList = new TemplateSectionCollection();
            TemplateSectionCollection sectionPropertyList       = new TemplateSectionCollection();
            TemplateSectionCollection sectionPropertyAsyncList  = new TemplateSectionCollection();

            var instanceEntityName = StringHelper.ConverToInstanceName(CleanEntityName);

            foreach (var entityField in Entity.Fields)
            {
                TemplateSection sectionProperty = sectionProperties.ExtractSection(entityField.SimpleTypeName);
                sectionProperty.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                sectionProperty.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                sectionPropertyList.AddSection(sectionProperty);

                TemplateSection sectionPropertyAsync = sectionPropertiesAsync.ExtractSection(entityField.SimpleTypeName);
                sectionPropertyAsync.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                sectionPropertyAsync.ReplaceTag("COLUMNNAME", entityField.ColumnName);
                sectionPropertyAsyncList.AddSection(sectionPropertyAsync);

                TemplateSection sectionParameter = sectionParameters.ExtractSection(entityField.SimpleTypeName);
                sectionParameter.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                sectionParameter.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                sectionParameter.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false);
                sectionParameterList.AddSection(sectionParameter);

                TemplateSection sectionParameterAsync = sectionParametersAsync.ExtractSection(entityField.SimpleTypeName);
                sectionParameterAsync.ReplaceTag("PARAMETERNAME", entityField.ColumnName);
                sectionParameterAsync.ReplaceTag("PROPERTYNAME", entityField.ColumnName);
                sectionParameterAsync.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false);
                sectionParameterAsyncList.AddSection(sectionParameterAsync);
            }

            template.ReplaceSection("PARAMETERS", sectionParameterList);
            template.ReplaceSection("PARAMETERS_ASYNC", sectionParameterAsyncList);
            template.ReplaceSection("PROPERTIES", sectionPropertyList);
            template.ReplaceSection("PROPERTIES_ASYNC", sectionPropertyAsyncList);

            template.ReplaceTag("PRIMARYKEY_DATATYPE", DataTypeHelper.GetCSharpType(primaryEntityField.SimpleTypeName), false);
            template.ReplaceTag("PRIMARYKEY_PARAMETERNAME", primaryEntityField.ColumnName, false);
            template.ReplaceTag("PRIMARYKEY_LOCAL_VARIABLE", StringHelper.ConverToInstanceName(StringHelper.ConvertToSafeCodeName(primaryEntityField.ColumnName)), false);

            template.ReplaceTag("NAMESPACE_DOMAIN", Settings[CodeBaseConstants.NAMESPACE_DOMAIN].Value, false);
            template.ReplaceTag("NAMESPACE_DATAACCESS", Settings[CodeBaseConstants.NAMESPACE_DATAACCESS].Value, false);
            template.ReplaceTag("NAMESPACE_DBHELPER", Settings[CodeBaseConstants.NAMESPACE_DBHELPER].Value, false);
            template.ReplaceTag("NAMESPACE_ACCESS_MODEL", Settings[CodeBaseConstants.NAMESPACE_ACCESS_MODEL].Value, false);

            template.ReplaceTag("INSTANCE_NAME_DOMAIN", instanceEntityName, false);
            template.ReplaceTag("CLASS_NAME_DOMAIN", DomainClassName, false);
            template.ReplaceTag("CLASS_NAME_DATAACCESS", DataAccessClassName, false);

            template.ReplaceTag("SAVE_STORED_PROCEDURE", SaveStoredProcedureName, false);
            template.ReplaceTag("GETBYID_STORED_PROCEDURE", GetByIdStoredProcedureName, false);
            template.ReplaceTag("LISTALL_STORED_PROCEDURE", ListAllStoredProcedureName, false);
            template.ReplaceTag("DELETE_STORED_PROCEDURE", DeleteStoredProcedureName, false);

            template.ReplaceTag("SAVE_METHODNAME", Settings[CodeBaseConstants.SAVE_METHODNAME].Value, false);
            template.ReplaceTag("GETBYID_METHODNAME", Settings[CodeBaseConstants.GETBYID_METHODNAME].Value, false);
            template.ReplaceTag("LISTALL_METHODNAME", Settings[CodeBaseConstants.LISTALL_METHODNAME].Value, false);
            template.ReplaceTag("DELETE_METHODNAME", Settings[CodeBaseConstants.DELETE_METHODNAME].Value, false);
            template.ReplaceTag("BUILDFUNCTION_METHODNAME", Settings[CodeBaseConstants.BUILDFUNCTION_METHODNAME].Value, false);
            template.ReplaceTag("ASYNC_METHODS_SUFFIX", Settings[CodeBaseConstants.ASYNC_METHODS_SUFFIX].Value, false);

            template.ReplaceTag("CONNECTIONSTRING_KEY", Settings[CodeBaseConstants.CONNECTIONSTRING_KEY].Value, false);
            template.ReplaceTag("DBHELPER_INSTANCEOBJECT", Settings[CodeBaseConstants.DBHELPER_INSTANCEOBJECT].Value, false);
            template.ReplaceTag("GETSCALAR_METHODNAME", Settings[CodeBaseConstants.GETSCALAR_METHODNAME].Value, false);
            template.ReplaceTag("GETENTITY_METHODNAME", Settings[CodeBaseConstants.GETENTITY_METHODNAME].Value, false);
            template.ReplaceTag("GETDATATABLE_METHODNAME", Settings[CodeBaseConstants.GETDATATABLE_METHODNAME].Value, false);
            template.ReplaceTag("EXECUTESP_METHODNAME", Settings[CodeBaseConstants.EXECUTESP_METHODNAME].Value, false);

            template.ReplaceTag("GETSCALAR_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETSCALAR_ASYNC_METHODNAME].Value, false);
            template.ReplaceTag("GETENTITY_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETENTITY_ASYNC_METHODNAME].Value, false);
            template.ReplaceTag("GETDATATABLE_ASYNC_METHODNAME", Settings[CodeBaseConstants.GETDATATABLE_ASYNC_METHODNAME].Value, false);
            template.ReplaceTag("EXECUTESP_ASYNC_METHODNAME", Settings[CodeBaseConstants.EXECUTESP_ASYNC_METHODNAME].Value, false);

            template.ReplaceTag("AUTHOR_NAME", Settings[CodeBaseConstants.AUTHOR_NAME].Value, false);
            template.ReplaceTag("CREATION_DATE", GetSimpleDate(DateTime.Now), false);

            return(template.Content);
        }