コード例 #1
0
 private void RenderToFile(string directory, string currclassName, CodeTemplate template)
 {
     if (!Directory.Exists(directory))
     {
         Directory.CreateDirectory(directory);
     }
     if (currclassName.IndexOf(".") > 0)
     {
         template.RenderToFile(Path.Combine(directory, currclassName), true);
     }
     else
     {
         template.RenderToFile(Path.Combine(directory, currclassName) + ".cs", true);
     }
 }
コード例 #2
0
        /// <summary>
        /// 通用根据模板生成文件方法
        /// </summary>
        /// <param name="isRender"></param>
        /// <param name="templatePath"></param>
        /// <param name="directory"></param>
        /// <param name="Tables"></param>
        /// <param name="fileName"></param>
        public void RenderToFileByTablesFixFileName(bool isRender, string templatePath, string directory, TableSchemaCollection Tables, string fileName = null)
        {
            if (isRender)
            {
                if (directory.IndexOf("{dbname}") >= 0)
                {
                    directory = directory.Replace("{dbname}", Tables[0].Database.Name);
                }
                if (string.IsNullOrWhiteSpace(fileName))
                {
                    fileName = Tables[0].Database.Name;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(fileName) && fileName.IndexOf("{dbname}") >= 0)
                    {
                        fileName = fileName.Replace("{dbname}", Tables[0].Database.Name);
                    }
                }
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                //载入子模板
                CodeTemplate template = GetCodeTemplate(templatePath);

                //CopyPropertiesTo(template);

                template.SetProperty("Tables", Tables);

                template.RenderToFile(directory + fileName, true);

                Response.WriteLine(templatePath + "代码生成完毕!");
            }
        }
コード例 #3
0
        public static void RunTableTemplate(CodeTemplate Parent, TableSchema SourceTable, string Path, string Template, string Output, bool debug)
        {
            // admin datamodel
            try
            {
                PreserveRegionsMergeStrategy strategy = new PreserveRegionsMergeStrategy("^[ \t]*(?i:Custom)", "C#");
                CodeTemplate template = null;
                if (!debug)
                {
                    template = Parent.GetCodeTemplateInstance(Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
                }
                else
                {
                    template = CompileTemplate(Parent, Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
                }

                if (template != null)
                {
                    template.SetProperty("SourceTable", SourceTable);
                    template.RenderToFile(Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Output, strategy);
                    Parent.Response.WriteLine("File: " + Output + " Created Successfully");
                }
                else
                {
                    Parent.Response.WriteLine("Template is null: " + Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
                }
            }
            catch (Exception ex)
            {
                Parent.Response.WriteLine("Template: " + Parent.CodeTemplateInfo.DirectoryName + Path + "\\" + Template);
                Parent.Response.WriteLine("Error: " + ex.Message);
                Parent.Response.WriteLine("StackTrace: " + ex.StackTrace);
            }
        }
コード例 #4
0
    /// <summary>
    /// 生成数据仓库代码
    /// </summary>
    /// <param name="tables"></param>
    /// <returns></returns>
    public int GenerateBusinessRepositoryClasses(ViewSchemaCollection views)
    {
        if (views == null || views.Count <= 0)
        {
            return(0);
        }
        int          tempIntTableNum            = 0;
        CodeTemplate BusinessRepositoryTemplate = GetCodeTemplate("ViewBusinessRepository.cst");

        foreach (ViewSchema view in views)
        {
            BusinessRepositoryTemplate.SetProperty("TargetView", view);
            BusinessRepositoryTemplate.SetProperty("CommonNamespace", CommonNamespace);
            BusinessRepositoryTemplate.SetProperty("BusinessRepositoryNamespace", BusinessRepositoryNamespace);
            BusinessRepositoryTemplate.SetProperty("EntityNamespace", EntityNamespace);
            BusinessRepositoryTemplate.SetProperty("DBUtilityNamespace", DBUtilityNamespace);
            BusinessRepositoryTemplate.SetProperty("CreatePerson", CreatePerson);
            BusinessRepositoryTemplate.SetProperty("CompanyName", CompanyName);
            BusinessRepositoryTemplate.SetProperty("BusinessRepositorySuffix", BusinessRepositorySuffix);
            BusinessRepositoryTemplate.SetProperty("FileDesc", "表[" + view.Name + "]的 数据仓库代码");
            string tempFilePath = string.Format(@"{0}{1}\{2}", this.OutputDirectory, BusinessRepositoryNamespace, BusinessRepositoryTemplate.GetFileName());
            BusinessRepositoryTemplate.RenderToFile(tempFilePath, true);
            WriteInfo("成功在路径[" + this.OutputDirectory + BusinessRepositoryNamespace + "] 生成 BusinessReposity 层代码文件:" + BusinessRepositoryTemplate.GetFileName() + "");
            tempIntTableNum++;
        }
        WriteInfo("-----成功在路径[" + this.OutputDirectory + BusinessRepositoryNamespace + "] 生成:" + tempIntTableNum + " 个 BusinessReposity 层代码文件-----");
        return(tempIntTableNum);
    }
コード例 #5
0
        public void ExecuteTemplate(CodeTemplate template, string formatPath)
        {
            this.CopyPropertiesTo(template);
            var masterTemplate = template as MasterTemplate;

            if (masterTemplate != null)
            {
                masterTemplate.RenderBody = formatPath.Contains(".gen.");
            }

            if (formatPath.Contains("{0}"))
            {
                template.RenderToFile(string.Format(formatPath, this.GetClassName(this.CurrentTable)), true);
            }
            else
            {
                template.RenderToFile(formatPath, true);
            }
        }
コード例 #6
0
        private void RenderToFile(string directory, Func <TableSchema, string> className, CodeTemplate template, TableSchema tab)
        {
            if (directory.IndexOf("{tablename}") >= 0)
            {
                directory = directory.Replace("{tablename}", tab.Name);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
            }
            string currclassName = null;

            if (className == null)
            {
                currclassName = tab.Name;
            }
            else
            {
                currclassName = className(tab);
            }
            //if (!string.IsNullOrWhiteSpace(splitTableName) && currclassName.IndexOf("{tablename_split_last}") >= 0)
            //{
            //    var temps = tab.Name.Split(splitTableName.ToArray());
            //    if (temps != null && temps.Length > 1)
            //    {
            //        currclassName = currclassName.Replace("{tablename_split_last}", ToSingular(temps.LastOrDefault()));
            //    }
            //}
            if (currclassName.IndexOf(".") > 0)
            {
                template.RenderToFile(directory + currclassName, true);
            }
            else
            {
                template.RenderToFile(directory + currclassName + ".cs", true);
            }
        }
コード例 #7
0
    /// <summary>
    /// 生成数据实体代码
    /// </summary>
    /// <param name="tables"></param>
    /// <returns></returns>
    public int GenerateEntityClasses(ViewSchemaCollection views)
    {
        if (views == null || views.Count <= 0)
        {
            return(0);
        }
        int          tempIntTableNum = 0;
        CodeTemplate EntityTemplate  = GetCodeTemplate("ViewEntity.cst");

        foreach (ViewSchema view in views)
        {
            EntityTemplate.SetProperty("TargetView", view);
            EntityTemplate.SetProperty("EntityNamespace", EntityNamespace);
            EntityTemplate.SetProperty("CreatePerson", CreatePerson);
            EntityTemplate.SetProperty("CompanyName", CompanyName);
            EntityTemplate.SetProperty("FileDesc", "表[" + view.Name + "] 数据库实体代码");
            string tempFilePath = string.Format(@"{0}{1}\{2}", this.OutputDirectory, EntityNamespace, EntityTemplate.GetFileName());
            EntityTemplate.RenderToFile(tempFilePath, true);
            WriteInfo("成功在路径[" + this.OutputDirectory + EntityNamespace + "] 生成 Entity 层代码文件:" + EntityTemplate.GetFileName() + "");
            tempIntTableNum++;
        }
        WriteInfo("-----成功在路径[" + this.OutputDirectory + EntityNamespace + "] 生成 " + tempIntTableNum + " 个 Entity 层代码文件-----");
        return(tempIntTableNum);
    }
コード例 #8
0
        public void ExecuteTemplate(CodeTemplate template, string formatPath)
        {
            this.CopyPropertiesTo(template);
            var masterTemplate = template as MasterTemplate;
            if (masterTemplate != null)
            {
                masterTemplate.RenderBody = formatPath.Contains(".gen.");
            }

            if (formatPath.Contains("{0}"))
            {
                template.RenderToFile(string.Format(formatPath, this.GetClassName(this.CurrentTable)), true);
            }
            else
            {
                template.RenderToFile(formatPath, true);
            }
        }
コード例 #9
0
 public void RenderToFile(CodeTemplate codeTemplate, String filename)
 {
     codeTemplate.RenderToFile(filename, true);
 }
コード例 #10
0
ファイル: ProjectHelper.cs プロジェクト: adeewu/huobi3j
        public static void BuildSubTemplate(CodeTemplate parent, CodeTemplate template, IMergeStrategy strategy, string pathAndFile, string outputDir)
        {
            // instantiate the sub-template

                parent.Response.WriteLine(string.Format("Begin Build SubTemplate for file {0}...",Path.GetFileName(pathAndFile)));
                // Set up the DL project
                parent.CopyPropertiesTo(template);

                //Render the file
                if(strategy == null)
                    template.RenderToFile(Path.Combine(outputDir,pathAndFile), true);
                else
                    template.RenderToFile(Path.Combine(outputDir,pathAndFile), strategy);

                parent.Response.WriteLine(string.Format("Build of {0} Complete.",Path.GetFileName(pathAndFile)));
        }