Example #1
0
        public static void GenerateModule(IBase baseObject, AngularModule angularModule, string moduleFolderPath, string moduleName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports)
        {
            var host = new TemplateEngineHost();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // Module class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("ModuleName", angularModule.Name);
                sessionVariables.Add("AngularModule", angularModule);
                sessionVariables.Add("AppName", generatorConfiguration.AppName);
                sessionVariables.Add("Imports", imports);

                fileLocation = moduleFolderPath;

                filePath = PathCombine(fileLocation, "app.module.ts");
                fileInfo = new FileInfo(filePath);

                if (!generatorConfiguration.NoFileCreation)
                {
                    output = host.Generate <AppModuleClassTemplate>(sessionVariables, false);
                }
                else
                {
                    output = host.Generate <BlankAppModuleClassTemplate>(sessionVariables, false);
                }

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule);

                // Routing module class

                sessionVariables = new Dictionary <string, object>();

                angularModule.AddImportsAndRoutes(imports);

                sessionVariables.Add("ModuleName", angularModule.RoutingName);
                sessionVariables.Add("IsRoot", angularModule.UILoadKind == DataAnnotations.UILoadKind.RootPage);
                sessionVariables.Add("Routes", angularModule.Routes);

                fileLocation = moduleFolderPath;

                filePath = PathCombine(fileLocation, "app-routing.module.ts");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <RoutingModuleClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule);
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateSchema(IBase baseObject, string graphQLPath, string name, string dataContext, string dataContextNamespace, IGeneratorConfiguration generatorConfiguration)
        {
            var host         = new TemplateEngineHost();
            var container    = (IEntityContainer)baseObject;
            var graphQLTypes = generatorConfiguration.GraphQLTypes;
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // GraphQL Schema class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("Name", name);
                sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);

                fileLocation = graphQLPath;
                filePath     = PathCombine(fileLocation, name + "Schema.cs");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <WebAPIGraphQLSchemaClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "GraphQL Schema class"));

                // GraphQL Query class

                sessionVariables.Add("EntitySets", container.EntitySets);
                sessionVariables.Add("DataContext", dataContext);
                sessionVariables.Add("DataContextNamespace", dataContextNamespace);
                sessionVariables.Add("GraphQLTypes", graphQLTypes);

                fileLocation = graphQLPath;
                filePath     = PathCombine(fileLocation, name + "Query.cs");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <WebAPIGraphQLQueryClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "GraphQL Query class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #3
0
        public static void GenerateModule(IBase baseObject, AngularModule angularModule, string moduleFolderPath, string moduleName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports)
        {
            var host = new TemplateEngineHost();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // Module class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("ModuleName", angularModule.Name);
                sessionVariables.Add("AngularModule", angularModule);
                sessionVariables.Add("Imports", imports);

                fileLocation = moduleFolderPath;

                filePath = PathCombine(fileLocation, moduleName.ToLower() + ".module.ts");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <RootModuleClassTemplate>(sessionVariables, false);

                sessionVariables.Add("Output", output);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, angularModule);
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #4
0
        public static void GenerateJson(string configPath, IGeneratorConfiguration generatorConfiguration)
        {
            var host = new TemplateEngineHost();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // config.json

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("ClientId", generatorConfiguration.ClientId);
                sessionVariables.Add("ClientSecret", generatorConfiguration.ClientSecret);
                sessionVariables.Add("Roles", generatorConfiguration.Roles);

                fileLocation = configPath;
                filePath     = PathCombine(fileLocation, "Config.json");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <ConfigJsonTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "Config.json"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateJson(IBase baseObject, string configPath, IGeneratorConfiguration generatorConfiguration)
        {
            var host       = new TemplateEngineHost();
            var container  = (RestEntityContainer)baseObject;
            var rootObject = (object)container.JsonRootObject;
            Dictionary <string, object> sessionVariables;
            Dictionary <string, string> nameValueDictionary;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPI Rest config json

                sessionVariables = new Dictionary <string, object>();

                nameValueDictionary = rootObject.GetDynamicMemberNameValueDictionary().Where(p => !p.Key.IsOneOf("$schema", "title", "type", "clientControllerRouteBase") && p.Value is string).ToDictionary(p => p.Key, p => (string)p.Value);

                sessionVariables.Add("NameValues", nameValueDictionary);

                fileLocation = configPath;
                filePath     = PathCombine(fileLocation, "Config.json");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <WebAPIRestConfigJsonTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "Config.json"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateTranslations(string i18nFolderPath, IGeneratorConfiguration generatorConfiguration)
        {
            var host         = new TemplateEngineHost();
            var pass         = generatorConfiguration.CurrentPass;
            var exports      = new List <ESModule>();
            var declarations = new List <IDeclarable>();
            Dictionary <string, object> sessionVariables;

            FolderStructure.File file;
            string fileLocation;
            string filePath;
            string output;

            try
            {
                foreach (var dictionary in generatorConfiguration.LanguageDictionary.LanguageSpecificDictionaries.Values)
                {
                    // LanguageTranslation file

                    sessionVariables = new Dictionary <string, object>();

                    sessionVariables.Add("Dictionary", dictionary);

                    fileLocation = i18nFolderPath;
                    filePath     = PathCombine(fileLocation, dictionary.LanguageCode + ".json");

                    output = host.Generate <LanguageTranslationFileTemplate>(sessionVariables, false);

                    if (pass == GeneratorPass.Files)
                    {
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        if (!Directory.Exists(fileLocation))
                        {
                            generatorConfiguration.CreateDirectory(fileLocation);
                        }

                        using (var fileStream = generatorConfiguration.CreateFile(filePath))
                        {
                            fileStream.Write(output);
                            generatorConfiguration.FileSystem.DeleteFile(filePath);

                            file = generatorConfiguration.FileSystem.AddSystemLocalProjectFile(new FileInfo(filePath));
                        }
                    }
                    else if (pass == GeneratorPass.HierarchyOnly)
                    {
                        file = generatorConfiguration.FileSystem.AddSystemLocalProjectFile(new FileInfo(filePath), generatorConfiguration.GenerateInfo(sessionVariables, "{\r\n\t\"Test\": \"Test\"\r\n}"));
                    }
                }
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateDataContext(IBase baseObject, string providerModelsPath, string title, IGeneratorConfiguration generatorConfiguration)
        {
            var host       = new TemplateEngineHost();
            var container  = (RestEntityContainer)baseObject;
            var rootObject = (object)container.JsonRootObject;
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   name;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPI Rest Data context (DbContext)

                sessionVariables = new Dictionary <string, object>();
                name             = (string)container.Variables["title"] + "DataContext";

                sessionVariables.Add("Name", name);
                sessionVariables.Add("Title", title);
                sessionVariables.Add("EntitySets", container.EntitySets);

                if (baseObject is IEntityWithPrefix)
                {
                    var entityWithPathPrefix = baseObject.CastTo <IEntityWithPrefix>();

                    fileLocation = PathCombine(providerModelsPath, baseObject.CastTo <IEntityWithPrefix>().PathPrefix);
                    sessionVariables.Add("RootNamespace", entityWithPathPrefix.Namespace);
                }
                else
                {
                    fileLocation = providerModelsPath;
                    sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);
                }

                filePath = PathCombine(fileLocation, name + ".cs");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <WebAPIRestProviderDataContextClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPI Rest Data Context"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateProvider(IBase baseObject, string providerFolderPath, string title, string providerName, string configPathString, NamingConvention namingConvention, IGeneratorConfiguration generatorConfiguration, List <ServiceMethod> serviceMethods)
        {
            var host              = new TemplateEngineHost();
            var container         = (RestEntityContainer)baseObject;
            var rootObject        = (object)container.JsonRootObject;
            var expressionHandler = generatorConfiguration.GetExpressionHandler(Guid.Parse(AbstraXProviderGuids.RestService));
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPI Rest provider class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("Title", title);
                sessionVariables.Add("ProviderName", providerName);
                sessionVariables.Add("ConfigPathString", configPathString);
                sessionVariables.Add("ServiceMethods", serviceMethods);
                sessionVariables.Add("NamingConvention", namingConvention);
                sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);

                if (baseObject is IEntityWithPrefix)
                {
                    fileLocation = PathCombine(providerFolderPath, baseObject.CastTo <IEntityWithPrefix>().PathPrefix);
                }
                else
                {
                    fileLocation = providerFolderPath;
                }

                filePath = PathCombine(fileLocation, providerName + ".cs");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <WebAPIRestServiceProviderClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIRestProvider Class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateStartupSchemas(string graphQLPath, IEnumerable <GraphQLSchema> schemas, IGeneratorConfiguration generatorConfiguration)
        {
            var host = new TemplateEngineHost();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            if (graphQLPath == null)
            {
                return;
            }

            try
            {
                // WebAPI StartupSchemas.cs

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);
                sessionVariables.Add("Schemas", schemas.Select(s => s.SchemaName).ToArray());

                fileLocation = graphQLPath;
                filePath     = PathCombine(fileLocation, "StartupSchemas.cs");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <WebAPIStartupGraphQLSchemasClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "StartupSchemas.cs"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #10
0
        public static void GeneratePage(IBase baseObject, string pagesFolderPath, string pageName, IGeneratorConfiguration generatorConfiguration, IModuleAssembly module, IDictionary <string, IEnumerable <ModuleImportDeclaration> > importGroups, List <IdentityField> identityFields, string loginTitleTranslationKey, string loginButtonTranslationKey)
        {
            var host = new TemplateEngineHost();
            var pass = generatorConfiguration.CurrentPass;
            var moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject);
            var resourcesHandler         = generatorConfiguration.ResourcesHandler;
            IEnumerable <ModuleImportDeclaration> importDeclarations;
            Dictionary <string, object>           sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // Login page

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("IdentityFields", identityFields);
                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.Add("LoginTitleTranslationKey", loginTitleTranslationKey);
                sessionVariables.Add("LoginButtonTranslationKey", loginButtonTranslationKey);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".html");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <LoginPageTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Login Page"));

                // Login class

                sessionVariables   = new Dictionary <string, object>();
                importDeclarations = importGroups["Page"];

                moduleAssemblyProperties.Imports = importDeclarations.Exclude(pageName + "Page");

                sessionVariables.Add("IdentityFields", identityFields);
                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("Authorize", generatorConfiguration.AuthorizedRoles);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                filePath = PathCombine(fileLocation, pageName.ToLower() + ".ts");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <LoginClassTemplate>(sessionVariables, false);

                module.ExportedComponents = sessionVariables.GetExportedComponents();
                module.ForChildFile       = generatorConfiguration.CreateFile(moduleAssemblyProperties, fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Login Page Class"));

                // Validator class

                sessionVariables   = new Dictionary <string, object>();
                importDeclarations = importGroups["Validator"];

                moduleAssemblyProperties.Clear();
                moduleAssemblyProperties.Imports = importDeclarations.Exclude(pageName + "Validator");

                sessionVariables.Add("FormFields", identityFields.Cast <FormField>().ToList());
                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("Authorize", generatorConfiguration.AuthorizedRoles);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                filePath = PathCombine(fileLocation, pageName.ToLower() + "-validator.ts");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <ValidatorClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(moduleAssemblyProperties, fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Login Validator Class"));

                // sass

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);

                filePath = PathCombine(fileLocation, pageName.ToLower() + ".scss");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <SassStyleSheetTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "page \r\n{\r\n}"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #11
0
        public static void GenerateModel(IBase baseObject, string modelsFolderPath, string modelName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports, List <FormField> formFields)
        {
            var                         host = new TemplateEngineHost();
            var                         pass = generatorConfiguration.CurrentPass;
            var                         moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject, imports);
            var                         newModules       = new List <ESModule>();
            var                         isIdentityEntity = generatorConfiguration.IsIdentityEntity(baseObject);
            List <ESModule>             modules          = null;
            Dictionary <string, object> sessionVariables;
            FileInfo                    fileInfo;
            string                      fileLocation;
            string                      filePath;
            string                      output;

            try
            {
                // Client Model class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("FormFields", formFields);
                sessionVariables.Add("ModelName", modelName);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.Add("IsIdentityEntity", isIdentityEntity);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                fileLocation = modelsFolderPath;
                filePath     = Path.Combine(fileLocation, modelName.ToLower() + ".model.ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <ClientModelClassTemplate>(sessionVariables, false);

                if (generatorConfiguration.KeyValuePairs.ContainsKey("Modules"))
                {
                    modules = (List <ESModule>)generatorConfiguration.KeyValuePairs["Modules"];
                }
                else
                {
                    modules = new List <ESModule>();

                    generatorConfiguration.KeyValuePairs.Add("Modules", modules);
                }

                foreach (var module in moduleAssemblyProperties.Modules)
                {
                    module.BaseObject = baseObject;

                    if (!modules.Contains(module))
                    {
                        modules.Add(module);
                    }

                    newModules.Add(module);
                }

                generatorConfiguration.CreateFile(fileInfo, newModules.Cast <Module>(), output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Client Model Class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #12
0
        public static void GeneratePage(IBase baseObject, string pagesFolderPath, string pageName, IGeneratorConfiguration generatorConfiguration, IModuleAssembly module, IEnumerable <ModuleImportDeclaration> imports, List <object> inputObjects)
        {
            var host = new TemplateEngineHost();
            var pass = generatorConfiguration.CurrentPass;
            var moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject, imports);
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // $basename$ page

                sessionVariables = new Dictionary <string, object>();

                // TODO - change this and the input variable inputObjects, preferably typed, to match your needs
                sessionVariables.Add("Input", inputObjects);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".html");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <$basename$PageTemplate> (sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "$basename$ Page"));

                // $basename$ class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("Input", inputObjects);
                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("Authorize", generatorConfiguration.AuthorizedRoles);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <$basename$ClassTemplate> (sessionVariables, false);

                module.ExportedComponents = sessionVariables.GetExportedComponents();
                module.ForChildFile       = generatorConfiguration.CreateFile(moduleAssemblyProperties, fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "$basename$ Page Class"));

                // sass

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".scss");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <SassStyleSheetTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "page \r\n{\r\n}"));
            }
            catch (Exception e)
            {
                generatorConfiguration.Engine.WriteError(e.ToString());
            }
        }
Example #13
0
        public static void GenerateApp(string appFolderPath, string appName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports, IEnumerable <Page> pages)
        {
            var host        = new TemplateEngineHost();
            var pass        = generatorConfiguration.CurrentPass;
            var pagesPath   = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages];
            var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath];
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;
            string   initApp;

            try
            {
                fileLocation = appFolderPath;
                filePath     = PathCombine(fileLocation, appName.ToLower() + ".component.html");
                fileInfo     = new FileInfo(filePath);

                sessionVariables = new Dictionary <string, object>();

                output = host.Generate <AppComponentPageTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "App Component Page"));

                // todo - obfuscate

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("IdentityProvider", generatorConfiguration.IdentityProvider);

                initApp = host.Generate <InitApp>(sessionVariables, false);

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("AppName", generatorConfiguration.AppName);
                sessionVariables.Add("IdentityProvider", generatorConfiguration.IdentityProvider);
                sessionVariables.Add("InitApp", initApp);
                sessionVariables.Add("Imports", imports);
                sessionVariables.Add("Pages", pages);

                fileLocation = appFolderPath;
                filePath     = PathCombine(fileLocation, appName.ToLower() + ".component.ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <AppComponentClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "App Component Class"));

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("RootPage", pages.SingleOrDefault(p => p.UILoadKind == UILoadKind.RootPage));
                sessionVariables.Add("MainPage", pages.SingleOrDefault(p => p.UILoadKind == UILoadKind.MainPage));

                fileLocation = pagesPath;
                filePath     = PathCombine(fileLocation, "index.ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <PageIndexTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Page Index Class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #14
0
        public static void GeneratePage(IBase baseObject, string pagesFolderPath, string pageName, IGeneratorConfiguration generatorConfiguration, IModuleAssembly module, IEnumerable <ModuleImportDeclaration> imports, View view, RazorSemanticVisitor visitor)
        {
            var host = new TemplateEngineHost();
            var pass = generatorConfiguration.CurrentPass;
            var moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject, imports);
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // repeater page

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("RazorSemanticVisitor", visitor);
                sessionVariables.Add("View", view);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".html");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <RepeaterPageTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Repeater Page"));

                // repeater class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("RazorSemanticVisitor", visitor);
                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("Authorize", generatorConfiguration.AuthorizedRoles);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <RepeaterClassTemplate>(sessionVariables, false);

                module.ExportedComponents = sessionVariables.GetExportedComponents();
                module.ForChildFile       = generatorConfiguration.CreateFile(moduleAssemblyProperties, fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Repeater Page Class"));

                // sass

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);

                fileLocation = PathCombine(pagesFolderPath, pageName.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".scss");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <SassStyleSheetTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "page \r\n{\r\n}"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #15
0
        public static void GenerateModel(IBase baseObject, string modelsFolderPath, string modelName, IGeneratorConfiguration generatorConfiguration, List <Generators.EntityProperty> entityProperties)
        {
            var host             = new TemplateEngineHost();
            var pass             = generatorConfiguration.CurrentPass;
            var exports          = new List <ESModule>();
            var declarations     = new List <IDeclarable>();
            var isIdentityEntity = generatorConfiguration.IsIdentityEntity(baseObject);
            var root             = baseObject.Root;
            var isGeneratedModel = false;
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPIModelGenerator class

                if (root is IRootWithOptions)
                {
                    var rootWithOptions = (IRootWithOptions)root;

                    isGeneratedModel = rootWithOptions.IsGeneratedModel;
                }

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("EntityProperties", entityProperties);
                sessionVariables.Add("ModelName", modelName);
                sessionVariables.Add("IsGeneratedModel", isGeneratedModel);
                sessionVariables.Add("EntityName", baseObject.Name);

                if (baseObject is IEntityWithPrefix)
                {
                    var entityWithPathPrefix = baseObject.CastTo <IEntityWithPrefix>();

                    fileLocation = PathCombine(modelsFolderPath, entityWithPathPrefix.PathPrefix);

                    sessionVariables.Add("RootNamespace", entityWithPathPrefix.Namespace);
                    sessionVariables.Add("NamespaceSuffix", entityWithPathPrefix.PathPrefix);
                }
                else
                {
                    fileLocation = modelsFolderPath;
                    sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);
                }

                filePath = PathCombine(fileLocation, modelName + ".cs");
                fileInfo = new FileInfo(filePath);

                if (isIdentityEntity)
                {
                    output = host.Generate <WebAPIIdentityModelClassTemplate>(sessionVariables, false);
                }
                else
                {
                    output = host.Generate <WebAPIModelClassTemplate>(sessionVariables, false);
                }

                if (generatorConfiguration.FileSystem.Contains(fileInfo.FullName))
                {
                    if (pass != GeneratorPass.HierarchyOnly)
                    {
                        var file = (AbstraX.FolderStructure.File)generatorConfiguration.FileSystem[fileInfo.FullName];

                        if (file.Hash != 0 && file.Hash != output.GetHashCode())
                        {
                            DebugUtils.Break();
                        }

                        generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIModel Class"));
                    }
                }
                else
                {
                    generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIModel Class"));
                }
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GenerateProvider(IBase baseObject, string providersFolderPath, string providerName, IGeneratorConfiguration generatorConfiguration, IEnumerable <ModuleImportDeclaration> imports, List <RelatedEntity> relatedEntities)
        {
            var                         host = new TemplateEngineHost();
            var                         pass = generatorConfiguration.CurrentPass;
            var                         moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject, imports);
            var                         newProviders             = new List <Provider>();
            var                         isIdentityEntity         = generatorConfiguration.IsIdentityEntity(baseObject);
            List <Provider>             providers = null;
            Dictionary <string, object> sessionVariables;
            FileInfo                    fileInfo;
            string                      fileLocation;
            string                      filePath;
            string                      output;

            try
            {
                // Entity provider

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("ProviderName", providerName);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.Add("RelatedEntities", relatedEntities);
                sessionVariables.Add("IsIdentityEntity", isIdentityEntity);
                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                if (isIdentityEntity)
                {
                    var className = providerName + "Provider";

                    sessionVariables.Add("ClientId", generatorConfiguration.ClientId);
                    sessionVariables.Add("ClientSecret", generatorConfiguration.ClientSecret);

                    generatorConfiguration.IdentityProvider = className;
                }

                if (generatorConfiguration.CustomQueries.ContainsKey(baseObject))
                {
                    var queriesList = generatorConfiguration.CustomQueries[baseObject];

                    sessionVariables.Add("CustomQueries", queriesList);
                }
                else if (generatorConfiguration.CustomQueries.ContainsNavigationKey(baseObject))
                {
                    var queriesList = generatorConfiguration.CustomQueries.GetNavigationValue(baseObject);

                    sessionVariables.Add("CustomQueries", queriesList);
                }

                fileLocation = providersFolderPath;
                filePath     = PathCombine(fileLocation, providerName.ToLower() + ".provider.ts");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <EntityProviderClassTemplate>(sessionVariables, false);

                if (generatorConfiguration.KeyValuePairs.ContainsKey("Providers"))
                {
                    providers = (List <Provider>)generatorConfiguration.KeyValuePairs["Providers"];
                }
                else
                {
                    providers = new List <Provider>();

                    generatorConfiguration.KeyValuePairs.Add("Providers", providers);
                }

                foreach (var provider in moduleAssemblyProperties.Providers)
                {
                    provider.BaseObject = baseObject;

                    if (!providers.Contains(provider))
                    {
                        providers.Add(provider);
                    }

                    newProviders.Add(provider);
                }

                generatorConfiguration.CreateFile(fileInfo, newProviders.Cast <Module>(), output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Entity Provider Class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public static void GeneratePage(IBase baseObject, string pagesFolderPath, string pageName, IGeneratorConfiguration generatorConfiguration, IModuleAssembly module, IEnumerable <ModuleImportDeclaration> imports, IModuleAssembly angularModule, List <ManagedList> managedLists, List <GridColumn> gridColumns, bool isComponent)
        {
            var host = new TemplateEngineHost();
            var pass = generatorConfiguration.CurrentPass;
            var moduleAssemblyProperties = new AngularModuleAssemblyProperties(baseObject, imports);
            var parentElement            = (IParentBase)baseObject;
            var childElement             = parentElement.ChildElements.Single();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // grid page

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("EntityName", childElement.Name);
                sessionVariables.Add("IsComponent", isComponent);

                fileLocation = PathCombine(pagesFolderPath, childElement.Name.ToLower());
                filePath     = PathCombine(fileLocation, pageName.ToLower() + ".html");
                fileInfo     = new FileInfo(filePath);

                output = host.Generate <NavigationGridPageTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Navigation Grid Page"));

                // grid class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);
                sessionVariables.Add("Authorize", generatorConfiguration.AuthorizedRoles);
                sessionVariables.Add("EntityName", childElement.Name);
                sessionVariables.Add("ParentEntityName", parentElement.Name);
                sessionVariables.Add("IsComponent", isComponent);

                if (baseObject is IRelationProperty)
                {
                    var navigationProperty = (IRelationProperty)baseObject;
                    var thisPropertyRef    = navigationProperty.ThisPropertyRef;
                    var parentPropertyRef  = navigationProperty.ParentPropertyRef;
                    var thisPropertyType   = thisPropertyRef.GetScriptTypeName();
                    var thisShortType      = thisPropertyRef.GetShortType().ToLower();

                    switch (navigationProperty.ThisMultiplicity)
                    {
                    case "*":
                        sessionVariables.Add("EntityParentRefName", baseObject.Parent.Name);
                        sessionVariables.Add("EntityPropertyRefName", thisPropertyRef.Name);

                        break;

                    case "0..1":
                    case "1":
                        DebugUtils.Break();
                        break;

                    default:
                        DebugUtils.Break();
                        break;
                    }
                }

                sessionVariables.Add("ManagedLists", managedLists);
                sessionVariables.Add("GridColumns", gridColumns);

                if (generatorConfiguration.CustomQueries.ContainsKey(baseObject))
                {
                    var queriesList = generatorConfiguration.CustomQueries[baseObject];

                    sessionVariables.Add("CustomQueries", queriesList);
                }

                sessionVariables.AddModuleAssemblyProperties(moduleAssemblyProperties);

                filePath = PathCombine(fileLocation, pageName.ToLower() + ".ts");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <NavigationGridClassTemplate>(sessionVariables, false);

                module.ExportedComponents = sessionVariables.GetExportedComponents();
                module.ForChildFile       = generatorConfiguration.CreateFile(moduleAssemblyProperties, fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "Navigation Grid Class"));

                // sass

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("PageName", pageName);

                filePath = PathCombine(fileLocation, pageName.ToLower() + ".scss");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <SassStyleSheetTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Project, () => generatorConfiguration.GenerateInfo(sessionVariables, "page \r\n{\r\n}"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
Example #18
0
        public static void GenerateController(IBase baseObject, string controllersFolderPath, string controllerName, IGeneratorConfiguration generatorConfiguration, List <RelatedEntity> relatedEntities, List <Generators.EntityProperty> entityProperties)
        {
            var host             = new TemplateEngineHost();
            var pass             = generatorConfiguration.CurrentPass;
            var exports          = new List <ESModule>();
            var declarations     = new List <IDeclarable>();
            var isIdentityEntity = generatorConfiguration.IsIdentityEntity(baseObject);
            var element          = (IElement)baseObject;
            var keyAttribute     = element.GetKey();
            var keyType          = keyAttribute.GetShortType();
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPI controller class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("ControllerName", controllerName);
                sessionVariables.Add("EntityName", baseObject.Name);
                sessionVariables.Add("RelatedEntities", relatedEntities);
                sessionVariables.Add("EntityProperties", entityProperties);
                sessionVariables.Add("Container", baseObject.GetContainer());
                sessionVariables.Add("ContainerSet", baseObject.GetContainerSet().Name);
                sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);
                sessionVariables.Add("KeyName", keyAttribute.Name);
                sessionVariables.Add("KeyType", keyType);

                if (generatorConfiguration.CustomQueries.ContainsKey(baseObject))
                {
                    var queriesList = generatorConfiguration.CustomQueries[baseObject];

                    sessionVariables.Add("CustomQueries", queriesList);
                }
                else if (generatorConfiguration.CustomQueries.ContainsNavigationKey(baseObject))
                {
                    var queriesList = generatorConfiguration.CustomQueries.GetNavigationValue(baseObject);

                    sessionVariables.Add("CustomQueries", queriesList);
                }

                if (baseObject is IEntityWithPrefix)
                {
                    var entityWithPrefix = baseObject.CastTo <IEntityWithPrefix>();

                    fileLocation = PathCombine(controllersFolderPath, entityWithPrefix.PathPrefix, controllerName);

                    controllerName = entityWithPrefix.ControllerNamePrefix + controllerName;
                }
                else
                {
                    fileLocation = PathCombine(controllersFolderPath, controllerName);
                }

                filePath = PathCombine(fileLocation, controllerName + "Controller.cs");
                fileInfo = new FileInfo(filePath);

                if (baseObject is IElementWithSurrogateTemplateType)
                {
                    var elementWithSurrogateTemplateType = (IElementWithSurrogateTemplateType)baseObject;

                    if (elementWithSurrogateTemplateType.HasSurrogateTemplateType <WebAPIControllerClassTemplate>())
                    {
                        var templateType = elementWithSurrogateTemplateType.GetSurrogateTemplateType <WebAPIControllerClassTemplate>();

                        output = host.Generate(templateType, sessionVariables, false);

                        if (generatorConfiguration.FileSystem.Contains(fileInfo.FullName))
                        {
                            if (pass != GeneratorPass.HierarchyOnly)
                            {
                                var file = (AbstraX.FolderStructure.File)generatorConfiguration.FileSystem[fileInfo.FullName];

                                if (file.Hash != output.GetHashCode())
                                {
                                    // DebugUtils.Break();
                                }
                            }
                        }
                        else
                        {
                            generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIController Class"));
                        }

                        return;
                    }
                }

                if (isIdentityEntity)
                {
                    output = host.Generate <WebAPIIdentityControllerClassTemplate>(sessionVariables, false);
                }
                else
                {
                    output = host.Generate <WebAPIControllerClassTemplate>(sessionVariables, false);
                }

                if (generatorConfiguration.FileSystem.Contains(fileInfo.FullName))
                {
                    if (pass != GeneratorPass.HierarchyOnly)
                    {
                        var file = (AbstraX.FolderStructure.File)generatorConfiguration.FileSystem[fileInfo.FullName];

                        if (file.Hash != output.GetHashCode())
                        {
                            // DebugUtils.Break();
                        }
                    }
                }
                else
                {
                    generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIController Class"));
                }
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }