Esempio n. 1
0
        public void GenerateDomainProject(DomainDataService dataService, string outputFolder)
        {
            outputFolder = Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.Domain");
            var constantsFolder = Path.Combine(outputFolder, "Constants");
            var modelsFolder    = Path.Combine(outputFolder, "Models");
            var metadataFolder  = Path.Combine(outputFolder, "Metadata");

            ReplaceDirectories(constantsFolder, modelsFolder, metadataFolder);

            var session = new Dictionary <string, object>();

            session.Add("DomainDataService", dataService);

            DomainProjectTemplate projectTemplate = new DomainProjectTemplate();

            projectTemplate.Session = session;
            projectTemplate.Initialize();
            string content = projectTemplate.TransformText();

            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.Domain.csproj"), content);

            DomainConstantsTemplate constantsTemplate = new DomainConstantsTemplate();

            constantsTemplate.Session = session;
            constantsTemplate.Initialize();
            content = constantsTemplate.TransformText();
            File.WriteAllText(Path.Combine(constantsFolder, $"{dataService.Name}Constants.cs"), content);

            if (!(dataService.Schemas is null))
            {
                foreach (var domainObject in dataService.Schemas.SelectMany(s => s.Objects))
                {
                    session["CurrentObject"] = domainObject;

                    ModelTemplate modelTemplate = new ModelTemplate();
                    modelTemplate.Session = session;
                    modelTemplate.Initialize();
                    content = modelTemplate.TransformText();
                    File.WriteAllText(Path.Combine(modelsFolder, $"{domainObject.ObjectName}.cs"), content);

                    MetadataTemplate metadataTemplate = new MetadataTemplate();
                    metadataTemplate.Session = session;
                    metadataTemplate.Initialize();
                    content = metadataTemplate.TransformText();
                    File.WriteAllText(Path.Combine(metadataFolder, $"{domainObject.ObjectName}Metadata.cs"), content);
                }
            }

            MetadataBundleTemplate bundleTemplate = new MetadataBundleTemplate();

            bundleTemplate.Session = session;
            bundleTemplate.Initialize();
            content = bundleTemplate.TransformText();
            File.WriteAllText(Path.Combine(metadataFolder, $"{dataService.Name}MetadataBundle.cs"), content);
        }
Esempio n. 2
0
        public static void GenerateModel(GeneratorParameters.GeneratorParameters generatorParameters)
        {
            ModelTemplate template = new ModelTemplate
            {
                //Create our session.
                Session = new Dictionary <string, object>()
            };

            template.Session["ClassName"]     = generatorParameters.Model.Name;
            template.Session["Namespace"]     = generatorParameters.NamespaceName;
            template.Session["Extends"]       = generatorParameters.Model.Extends;
            template.Session["BaseNamespace"] = generatorParameters.Model.BaseNamespace;
            template.Session["Fields"]        = generatorParameters.Model.Fields;

            template.Initialize();

            string classDef = template.TransformText();

            File.WriteAllText($"{generatorParameters.OutputDir}/{generatorParameters.Model.Name}.cs", classDef);
        }