示例#1
0
        public override GenerationArtifact RenderTemplate(DatabaseTable table, CodeGenSettings settings)
        {
            //retrieve the embedded template
            string contents = Core.ResourceFileHelper.ConvertStreamResourceToUTF8String(typeof(Model), "Chucksoft.Templates.Templates.StoredProcedure.template");

            _content = contents.Trim();

            //Check for expected content, if not found, badness has happen.
            if (string.IsNullOrEmpty(contents))
            {
                throw new ContentNotFound("Can't find embeddedResource \"Chucksoft.Templates.Templates.Enity.template\"");
            }

            List <string> prodecures     = GetProcedures(table, settings);
            StringBuilder contentBuilder = new StringBuilder();

            //append the procedures together and seperate them with a seperator
            foreach (string prodecure in prodecures)
            {
                contentBuilder.AppendLine(prodecure);
                contentBuilder.AppendLine(Environment.NewLine + "-----------------------------------------------------------" + Environment.NewLine);
            }

            //set the Generator object and return to calling method.
            GenerationArtifact artifact = new GenerationArtifact {
                FileName = string.Format("{0}.sql", table.Name), Content = contentBuilder.ToString()
            };

            return(artifact);
        }
        private static void GenerateDynamicSolutionAssets(CodeGenSettings settings, IEnumerable <DatabaseTable> tables)
        {
            List <IDynamicSolutionAsset> dynamicTemplates = RetrieveTemplates <IDynamicSolutionAsset>(settings, "IDynamicSolutionAsset");

            foreach (IDynamicSolutionAsset asset in dynamicTemplates)
            {
                foreach (DatabaseTable table in tables)
                {
                    GenerationArtifact content      = asset.RenderTemplate(table, settings);
                    string             dirPath      = string.Format("{0}\\{1}", settings.CodeGenerationDirectory, asset.FolderName);
                    string             fullFilePath = string.Format("{0}\\{1}", dirPath, content.FileName);

                    if (!File.Exists(dirPath))
                    {
                        Directory.CreateDirectory(dirPath);
                    }

                    File.WriteAllText(fullFilePath, content.Content.ToString());
                }
            }
        }