Esempio n. 1
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());
            }
        }
Esempio n. 2
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());
            }
        }
Esempio n. 3
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());
            }
        }
        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());
            }
        }