public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_webApiDataServiceInterface);
                string filepath      = outputfile;
                var    generator     = new WebApiDataServiceInterfaceGenerator(inflector: Inflector);
                var    generatedCode = generator.GenerateWebApiDataServiceInterface(dtoNamespace: DtoNamespace,
                                                                                    defaultCriteria: DefaultCriteria,
                                                                                    baseNamespace: BaseNamespace,
                                                                                    webApiDataServiceInterfaceNamespace: WebApiDataServiceInterfaceNamespace,
                                                                                    webApiDataServiceInterfaceClassName: WebApiDataServiceInterfaceClassName,
                                                                                    prependSchemaNameIndicator: PrependSchemaNameIndicator,
                                                                                    EntityTypes: ProcessModel.MetadataSourceModel.EntityTypes
                                                                                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_automapperProfile);
                string filepath = outputfile;

                var    generator     = new AutomapperProfileControllerGenerator(inflector: Inflector);
                string generatedCode = generator.GenerateAutomapperProfile(
                    baseNamespace: BaseNamespace,
                    namespacePostfix: NamespacePostfix,
                    dtoNamespace: DtoNamespace,
                    repositoryEntitiesNamespace: RepositoryEntitiesNamespace,
                    entityTypes: ProcessModel.MetadataSourceModel.EntityTypes,
                    excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties);

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });

                AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            return(retVal);
        }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string interfaceRepository = $"I{NamespacePostfix}Repository";
                string outputfile          = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity, fileName: Consts.OUT_apiBaseController);

                string className = BaseApiControllerClassName;
                if (UseAuthorizedBaseController)
                {
                    outputfile = outputfile.Replace(".cs", "Authorized.cs");
                    if (!className.Contains("Authorized"))
                    {
                        className = $"{className}Authorized";
                    }
                }

                var generator = new APIBaseControllerGenerator(inflector: Inflector);
                List <NamespaceItem> usings = generator.BuildBaseApiControllerUsings(
                    repositoryNamespace: RepositoryNamespace,
                    repositoryInterfaceNamespace: RepositoryInterfaceNamespace,
                    autoInvalidateCacheOutput: AutoInvalidateCacheOutput);

                var values = ProcessModel.MetadataSourceProperties;

                //string dbContextFullyQualifiedTypeName = ProcessModel.MetadataSourceModel.ModelFullyQualifiedTypeName;
                //if (values.KeyValues.ContainsKey(cghConsts.METADATASOURCE_PROPERTYNAME_FQTypeName))
                //{
                //    dbContextName = values.KeyValues[cghConsts.METADATASOURCE_PROPERTYNAME_FQTypeName];
                //}

                string generatedCode = generator.GenerateBaseApiController(
                    usings: usings,
                    namespacePostfix: NamespacePostfix,
                    className: className, // "Authorized" gets appended if useAuthorizedBaseController = true.
                    classNamespace: BaseApiControllerNameSpace,
                    interfaceRepository: interfaceRepository,
                    repositoryEntitiesNamespace: RepositoryEntitiesNamespace,
                    dbContextName: DbContextName,
                    autoInvalidateCacheOutput: AutoInvalidateCacheOutput,
                    useAuthorizedBaseController: UseAuthorizedBaseController,
                    useIdentityBasicAuthenticationAttribute: UseIdentityBasicAuthenticationAttribute
                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = outputfile
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #4
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_repositoryInterfaceCrud);
                string filepath = outputfile;

                var    generator     = new RepositoryInterfaceCrudGenerator(inflector: Inflector);
                string generatedCode = generator.GenerateRepositoryInterfaceCrud(
                    repositoryInterfaceNamespace: RepositoryInterfaceNamespace,
                    namespacePostfix: NamespacePostfix,
                    repositoryEntitiesNamespace: RepositoryEntitiesNamespace,
                    EntityTypes: ProcessModel.MetadataSourceModel.EntityTypes
                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #5
0
 protected void AddTemplateVariablesManagerErrorsToRetVal(ref TemplateOutput retVal, Enums.LogLevel logLevel)
 {
     foreach (var errorItem in TemplateVariablesManager.Errors)
     {
         retVal.Errors.Add(new TemplateError()
         {
             ErrorLevel       = logLevel,
             Message          = errorItem,
             TemplateIdentity = ProcessModel.TemplateIdentity.Copy()
         });
     }
 }
Example #6
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_mapperDtoToSqliteModelDataAndMvvmLightModelObject);
                string filepath = outputfile;

                string modelObjNamespacePrefix  = $"obj{NamespacePostfix}";
                string modelDataNamespacePrefix = $"data{NamespacePostfix}";
                string modelDtoNamespacePrefix  = $"dto{NamespacePostfix}";
                string regexExclude             = RegexExclude;

                var usings = new List <string>
                {
                    $"using {modelObjNamespacePrefix} = {SqliteModelObjectNamespace};",
                    $"using {modelDataNamespacePrefix} = {SqliteModelDataNamespace};",
                    $"using {modelDtoNamespacePrefix} = {DtoNamespace};"
                };

                var    entityTypes   = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude);
                var    generator     = new MapperDtoToSqliteModelDataAndMvvmLightModelObjectGenerator(inflector: Inflector);
                string generatedCode = generator.GenerateMapperDtoTosqliteModelDataAndMvvmLightModelObject(
                    usings: usings,
                    classNamespace: SqliteModelMapperClassNamespace,
                    className: SqliteModelMapperClassName,
                    modelObjNamespacePrefix: modelObjNamespacePrefix,
                    modelDataNamespacePrefix: modelDataNamespacePrefix,
                    modelDtoNamespacePrefix: modelDtoNamespacePrefix,
                    prependSchemaNameIndicator: PrependSchemaNameIndicator,
                    entityTypes: entityTypes
                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_webApiControllerPartialMethods);
                    outputfile = outputfile.Replace("[tablename]", Inflector.Humanize(entity.ClrType.Name)).Replace("[tablepluralname]", Inflector.Pluralize(entity.ClrType.Name));
                    string filepath = outputfile;

                    string baseControllerName = $"{NamespacePostfix}BaseApiController";

                    if (UseAuthorizedBaseController) //!string.IsNullOrEmpty(UseAuthorizedBaseController) && UseAuthorizedBaseController.ToLowerInvariant() == "true")
                    {
                        baseControllerName = $"{NamespacePostfix}BaseApiControllerAuthorized";
                    }

                    var    generator     = new WebApiControllerPartialMethodsGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateWebApiControllerPartialMethods(
                        namespacePostfix: NamespacePostfix,
                        classNamespace: WebApiControllerNamespace,
                        baseControllerName: baseControllerName,
                        efEntityNamespacePrefix: $"ent{NamespacePostfix}",
                        efEntityNamespace: RepositoryEntitiesNamespace,
                        dbContextName: DbContextName,
                        entity: entity,
                        excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties,
                        allowUpsertDuringPut: AllowUpsertDuringPut
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #8
0
        internal void AddError(ref TemplateOutput templateOutput, Exception ex, Enums.LogLevel logLevel)
        {
            while (ex != null)
            {
                TemplateError te = new TemplateError()
                {
                    ErrorLevel       = logLevel,
                    Message          = ex.Message,
                    StackTrace       = ex.StackTrace,
                    TemplateIdentity = ProcessModel.TemplateIdentity.Copy()
                };

                templateOutput.Errors.Add(te);
                ex = ex.InnerException;
            }
        }
Example #9
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string entityName = Inflector.Humanize(entity.ClrType.Name);
                    string generatedCode;
                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_Blazor_CSLA_Razor_Edit);
                    outputfile = outputfile.Replace("[entityname]", $"{entityName}");
                    string filepath = outputfile;

                    if (UseBootstrap)
                    {
                        var generator = new CSLAEditRazorGeneratorBootstrap(inflector: Inflector);
                        generatedCode = generator.GenerateRazor(baseNamespace: BaseNamespace,
                                                                namespacePostfix: NamespacePostfix,
                                                                entity: entity, AuthorizeRoles: AuthorizeRoles);
                    }
                    else
                    {
                        var generator = new CSLAEditRazorGenerator(inflector: Inflector);
                        generatedCode = generator.GenerateRazor(baseNamespace: BaseNamespace,
                                                                namespacePostfix: NamespacePostfix,
                                                                entity: entity, AuthorizeRoles: AuthorizeRoles);
                    }

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #10
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                if (retVal.Errors.Count > 0)
                {
                    return(retVal);
                }

                var entityTypes = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude);
                foreach (var entity in entityTypes)
                {
                    // Determine the navigation properties that should be excluded due to the RegEx patterns.
                    var excludedNavigationProperties = GetExcludedNavigationProperties(entity, entityTypes, ProcessModel.ExcludedNavigationProperties);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_mvvmLightModelObject);
                    string entityName = Inflector.Humanize(entity.ClrType.Name);
                    outputfile = outputfile.Replace("[tablename]", entityName);
                    string filepath = outputfile;

                    var    generator     = new MvvmLightModelObjectGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateMvvmLightModelObject(
                        classNamespace: SqliteModelObjectNamespace,
                        baseAuditEditNamespace: SqliteModelObjectBaseAuditEditNamespace,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        entity: entity,
                        excludedNavigationProperties: excludedNavigationProperties);
                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
        //  [TemplateVariable(Consts.STG_sqliteModelObjectBaseAuditEditNamespace_DEFAULTVALUE)]
        //  public string SqliteModelObjectBaseAuditEditNamespace { get; set; }

        #endregion TemplateVariables

        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string entityName = Inflector.Humanize(entity.ClrType.Name);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity, fileName: Consts.OUT_ModelsBackedByDto);
                    //outputfile = outputfile.Replace("[tablename]", table.NameHumanCaseSingular).Replace("[tablepluralname]", table.NamePlural);
                    outputfile = outputfile.Replace("[tablename]", entityName).Replace("[tablepluralname]", entityName);
                    string filepath = outputfile;

                    var    generator     = new ModelsBackedByDtoGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateModelsBackedByDto(
                        baseNamespace: BaseNamespace,
                        namespacePostfix: NamespacePostfix,
                        classNamespace: ClassNameSpace,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        modelsBackedByDtoInterfaceNamespace: ModelsBackedByDtoInterfaceNamespace,
                        webApiDataServiceInterfaceNamespace: WebApiDataServiceInterfaceNamespace,
                        webApiDataServiceInterfaceClassName: WebApiDataServiceInterfaceClassName,
                        excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties,
                        entity: entity
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            //AddTemplateVariablesManagerErrorsToRetVal(ref retVal);
            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #12
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.ToDataMapper_OutFileVariableName);
                string filepath = outputfile;

                var usings = new List <string>
                {
                    $"using System;",
                    $"using System.Linq;",
                    $"using System.Collections.Generic;",
                    $"using System.Reflection;",
                    $"using cEnums = CGH.Common.Enums;",
                    $"using xData = {EntitiesNamespace};",
                    $"using xModel = {ModelNamespace};",
                };

                var    generator     = new ToDataMapperGenerator(inflector: Inflector);
                string generatedCode = generator.Generate(
                    usings: usings,
                    ToDataMapperClassNamespace,
                    prependSchemaNameIndicator: PrependSchemaNameIndicator,
                    entityTypes: ProcessModel.MetadataSourceModel.EntityTypes
                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #13
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                var entityTypes = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude);
                foreach (var entity in entityTypes)
                {
                    string entityName = Inflector.Humanize(entity.ClrType.Name);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity, fileName: Consts.OUT_dto);
                    outputfile = outputfile.Replace("[tablename]", entityName).Replace("[tablepluralname]", Inflector.Pluralize(entityName));
                    string filepath = outputfile;

                    var    generator     = new DTOSimpleGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateDTO(
                        excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties,
                        entity: entity,
                        namespacePostfix: NamespacePostfix,
                        baseNamespace: BaseNamespace,
                        dtoIncludeRelatedObjects: DTOIncludeRelatedObjects,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        dtoNamespace: DTONamespace
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }

                AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            return(retVal);
        }
Example #14
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string entityName = Inflector.Humanize(entity.ClrType.Name);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_Blazor_CSLA_EditBusiness);
                    outputfile = outputfile.Replace("[entityname]", $"{entityName}");
                    string filepath = outputfile;

                    var    generator     = new CSLAEditBusinessGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateActions(
                        baseNamespace: BaseNamespace,
                        namespacePostfix: NamespacePostfix,
                        classNamespace: ClassNameSpace,
                        InludeRelatedObjects: DataAccessIncludeRelatedObjects,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        excludeCircularReferenceNavigationProperties: ProcessModel.ExcludedNavigationProperties,
                        entity: entity
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #15
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string entityName = Inflector.Humanize(entity.ClrType.Name);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity, fileName: Consts.OUT_DataAccessEF);
                    outputfile = outputfile.Replace("[entityname]", entityName).Replace("[tablename]", entityName).Replace("[entitynamepluralname]", entityName).Replace("[tablenamepluralname]", entityName);
                    string filepath = outputfile;

                    string useNamespace = TemplateVariablesManager.GetValue(Consts.STG_dataAccessEFNamespace);

                    var    generator     = new DataAccessEFGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateDataAccessEF(
                        entity: entity,
                        useNamespace: useNamespace,
                        dbContextName: DBContextName
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }

                AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            return(retVal);
        }
Example #16
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                var entityTypes = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude);

                foreach (var entity in entityTypes)
                {
                    string entityName = Inflector.Pascalize(entity.ClrType.Name);
                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_sqliteModelData);
                    outputfile = outputfile.Replace("[tablename]", entityName).Replace("[tablepluralname]", Inflector.Pluralize(entityName));
                    string filepath = outputfile;

                    var    generator     = new SqliteModelDataGenerator(inflector: Inflector);
                    string generatedCode = generator.GenerateSqliteModelData(
                        classNamespace: SqliteModelDataNamespace,
                        baseAuditEditNamespace: SqliteModelDataBaseAuditEditNamespace,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        entity: entity);

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_repositoryBasePartialMethods);
                string filepath = outputfile;

                var generator     = new RepositoryBasePartialMethodsGenerator(inflector: Inflector);
                var generatedCode = generator.GenerateRepositoryBasePartialMethods(
                    namespacePostfix: NamespacePostfix,
                    baseNamespace: BaseNamespace,
                    repositoryInterfaceNamespace: RepositoryInterfaceNamespace,
                    repositoryEntitiesNamespace: RepositoryEntitiesNamespace,
                    efEntityNamespacePrefix: $"ent{NamespacePostfix}",
                    dbContextName: DbContextName,
                    EntityTypes: ProcessModel.MetadataSourceModel.EntityTypes,
                    excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties
                    );

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                foreach (var entity in ProcessModel.MetadataSourceModel.EntityTypes)
                {
                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_webApiController);
                    outputfile = outputfile.Replace("[tablename]", Inflector.Humanize(entity.ClrType.Name)).Replace("[tablepluralname]", Inflector.Pluralize(entity.ClrType.Name));
                    string filepath = outputfile;

                    var maxRequestPerPageOverrides =
                        DeserializeJsonObject <List <NameValue> >(MaxRequestPerPageOverrideByTableName);

                    if (maxRequestPerPageOverrides == null)
                    {
                        maxRequestPerPageOverrides = new List <NameValue>();
                    }

                    string baseControllerName = $"{NamespacePostfix}BaseApiController";

                    if (UseAuthorizedBaseController) //!string.IsNullOrEmpty(UseAuthorizedBaseController) && UseAuthorizedBaseController.ToLowerInvariant() == "true")
                    {
                        baseControllerName = $"{NamespacePostfix}BaseApiControllerAuthorized";
                    }

                    WebApiControllerGenerator webApiControllerGenerator = new WebApiControllerGenerator(inflector: Inflector);
                    string generatedCode = webApiControllerGenerator.GenerateWebApiController(
                        baseNamespace: BaseNamespace,
                        namespacePostfix: NamespacePostfix,
                        classNamespace: WebApiControllerNamespace,
                        baseControllerName: baseControllerName,
                        apiHelpersNamespace: ApiHelpersNamespace,
                        iLoggingServiceNamespace: ILoggingServiceNamespace,
                        repositoryNamespace: RepositoryNamespace,
                        factoryNamespace: FactoryNamespace,
                        efEntityNamespacePrefix: $"ent{NamespacePostfix}",
                        efEntityNamespace: RepositoryEntitiesNamespace,
                        dtoNamespacePrefix: $"dto{NamespacePostfix}",
                        dtoNamespace: DtoNamespace,
                        enumNamespace: EnumNamespace,
                        repositoryInterfaceName: $"I{NamespacePostfix}Repository",
                        dbContextName: DbContextName,
                        maxRequestPerPageOverrides: maxRequestPerPageOverrides,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        entity: entity,
                        excludedNavigationProperties: ProcessModel.ExcludedNavigationProperties
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #19
0
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                var entityTypes = ProcessModel.MetadataSourceModel.GetEntityTypesByRegEx(excludeRegExPattern: RegexExclude, includeRegExPattern: RegexInclude);

                foreach (var entity in entityTypes)
                {
                    string entityName = Inflector.Pascalize(entity.ClrType.Name);

                    string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                               fileName: Consts.OUT_sampleData);
                    outputfile = outputfile.Replace("[tablename]", entityName).Replace("[tablepluralname]", Inflector.Pluralize(entityName));
                    string filepath = outputfile;

                    var generator = new SampleDataGenerator(inflector: Inflector);

                    int sampleDataCount = 0;
                    if (int.TryParse(SampleDataCount, out int sampleCount))
                    {
                        sampleDataCount = sampleCount;
                    }
                    else
                    {
                        ProcessModel.Errors.Add("Unable to parse the SampleDataCount from the blueprint");
                        sampleCount = 3; // Use 3 if we can parse the value
                    }

                    int sampleDataDigits = 2;
                    if (int.TryParse(SampleDataDigits, out int sampleDigits))
                    {
                        Debug.WriteLine($"Successfully parsed \"{SampleDataDigits}\" to {sampleDigits}");
                        sampleDataCount = sampleDigits;
                    }
                    else
                    {
                        Debug.WriteLine($"Failed trying to parse \"{SampleDataDigits}\" to a number");
                        ProcessModel.Errors.Add("Unable to parse the SampleDataDigits from the blueprint");
                        sampleCount = 2; // Use 2 if we can't parse the value
                    }

                    string generatedCode = generator.GenerateSampleData(
                        entity: entity,
                        sqliteModelDataNamespace: SqliteModelDataNamespace,
                        prependSchemaNameIndicator: PrependSchemaNameIndicator,
                        sampleDataCount: sampleDataCount,
                        sampleDataDigits: sampleDataDigits
                        );

                    retVal.Files.Add(new OutputFile()
                    {
                        Content = generatedCode,
                        Name    = filepath
                    });
                }
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }
Example #20
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method parses the template output into a parse tree.</summary>
 ///
 /// <returns>A ParseTree with the parsing results.</returns>
 ///--------------------------------------------------------------------------------
 public bool ParseOutput(bool showDialog = true)
 {
     try
     {
         OutputAST = null;
         if (String.IsNullOrEmpty(TemplateOutput))
         {
             HasErrors = true;
             Solution.ShowIssue(String.Format(DisplayValues.Exception_NoOutput, TemplateName), DisplayValues.Exception_ParsingTitle, showDialog);
             return(false);
         }
         ParseTree tree = Solution.SpecTemplateOutputParser.Parse(TemplateOutput);
         if (tree.ParserMessages.Count == 0 && tree.Root.AstNode is TemplateNode)
         {
             OutputAST = tree.Root.AstNode as TemplateNode;
             if (OutputAST.LineNumber == 0 || TemplateOutput.TrimStart().StartsWith("//") == true)
             {
                 // TODO: this is a hack, investigate why parsing result line numbers are sometimes zero based and
                 // sometimes one based. Need line numbers to be one based in line with text editors.
                 OutputAST.ExecuteVisitor(new IncrementLineNumberVisitor());
             }
             Solution.SpecTemplates[TemplateKey] = this;
         }
         else if (tree.ParserMessages.Count > 0)
         {
             HasErrors = true;
             StringBuilder messages = new StringBuilder();
             messages.Append(DisplayValues.Exception_Parsing);
             messages.Append("\r\n");
             messages.Append(DisplayValues.Exception_SolutionIntro);
             messages.Append(" ");
             messages.Append(Solution.SolutionName);
             messages.Append("\r\n");
             messages.Append(DisplayValues.Exception_NodeIntro);
             messages.Append(" ");
             messages.Append(NodeName);
             messages.Append("\r\n");
             messages.Append(DisplayValues.Exception_TemplateIntro);
             messages.Append(" ");
             messages.Append(TemplateName);
             messages.Append("\r\n");
             messages.Append(DisplayValues.Exception_InnerMessageIntro);
             messages.Append("\r\n");
             foreach (ParserMessage message in tree.ParserMessages)
             {
                 messages.Append(String.Format(DisplayValues.Message_TemplateOutputParseError, (message.Location.Line + 1).ToString(), (message.Location.Column + 1).ToString(), message.Message));
             }
             Solution.ShowIssue(messages.ToString(), DisplayValues.Exception_ParsingTitle, showDialog);
             return(false);
         }
         return(true);
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (System.Exception ex)
     {
         HasErrors = true;
         Solution.ShowIssue(ex.Message + ex.StackTrace, DisplayValues.Exception_ParsingTitle, showDialog);
     }
     return(false);
 }
        public override TemplateOutput Generate()
        {
            TemplateOutput retVal = new TemplateOutput();

            try
            {
                string classNamespace = $"{BaseNamespace}.API.Controllers.{NamespacePostfix}";
                string repositoryName = $"I{NamespacePostfix}Repository";

                List <NamespaceItem> usingNamespaceItems = new List <NamespaceItem>();
                usingNamespaceItems.Insert(0, new NamespaceItem()
                {
                    Namespace = "Microsoft.Extensions.Logging"
                });
                usingNamespaceItems.Insert(1, new NamespaceItem()
                {
                    Namespace = "System", NamespacePrefix = null, Name = null
                });
                usingNamespaceItems.Insert(2, new NamespaceItem()
                {
                    Namespace = "System.Threading.Tasks", NamespacePrefix = null, Name = null
                });
                usingNamespaceItems.Insert(3, new NamespaceItem()
                {
                    Namespace = "System.Web.Http", NamespacePrefix = null, Name = null
                });
                usingNamespaceItems.Insert(4, new NamespaceItem()
                {
                    Namespace = "CodeGenHero.Core.Enums", NamespacePrefix = "coreEnums"
                });
                usingNamespaceItems.Insert(5, new NamespaceItem()
                {
                    Namespace = "CodeGenHero.WebApi"
                });
                usingNamespaceItems.Insert(6, new NamespaceItem()
                {
                    Namespace = RepositoryInterfaceNamespace, NamespacePrefix = null, Name = null
                });

                string outputfile = TemplateVariablesManager.GetOutputFile(templateIdentity: ProcessModel.TemplateIdentity,
                                                                           fileName: Consts.OUT_apiStatusController);
                string filepath = outputfile;

                var    generator     = new APIStatusControllerGenerator(inflector: Inflector);
                string generatedCode = generator.GenerateApiStatusController(
                    usingNamespaceItems: usingNamespaceItems,
                    classnamePrefix: NamespacePostfix,
                    classNamespace: classNamespace,
                    repositoryname: repositoryName);

                retVal.Files.Add(new OutputFile()
                {
                    Content = generatedCode,
                    Name    = filepath
                });
            }
            catch (Exception ex)
            {
                base.AddError(ref retVal, ex, Enums.LogLevel.Error);
            }

            AddTemplateVariablesManagerErrorsToRetVal(ref retVal, Enums.LogLevel.Error);
            return(retVal);
        }