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());
            }
        }
示例#2
0
        public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration)
        {
            var    container    = (IEntityContainer)baseObject;
            var    servicesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.WebAPIServicesRoot];
            var    graphQLPath  = FileSystemObject.PathCombine(servicesPath, "GraphQL");
            string name;
            string dataContext;
            string dataContextNamespace;

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

                name                 = (string)((RestEntityContainer)container).Variables["title"];
                dataContext          = "I" + name + "DataContext";
                dataContextNamespace = ((RestEntityContainer)container).Namespace + ".Models." + entityWithPathPrefix.PathPrefix;
            }
            else
            {
                name                 = baseObject.Name.RemoveEndIfMatches("Entities", "Context");
                dataContext          = "I" + baseObject.Name;
                dataContextNamespace = ((Entity_Container)container).Namespace;
            }

            WebAPIGraphQLSchemaGenerator.GenerateSchema(baseObject, graphQLPath, name, dataContext, dataContextNamespace, generatorConfiguration);

            return(true);
        }
        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());
            }
        }
示例#4
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());
            }
        }
示例#5
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());
            }
        }