ldj/codeSmith/OneDatabaseScript.cst

241 lines
11 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ Template Language="C#" TargetLanguage="Text" %>
<%-- 注册要生成的模板 --%>
<%@ Register Name="basicImplements" Template="basicImplements.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="basicObject" Template="basicObject.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="extModelClass" Template="extModelClass.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="extModelImpl" Template="extModelImpl.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="logic" Template="logic.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="wcfData" Template="WCFdata.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="WcfInterface" Template="WcfInterface.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="wcfSvr" Template="WcfService.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="wcfSvc" Template="WcfServiceSvc.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%@ Register Name="wcfList" Template="WcfDataList.cst" MergeProperties="Flase" ExcludeProperties=""%>
<%--声明数据库的参数在左下角的Database属性中选择要操作的数据库名称--%>
<%@ Property Category="Database" Name="SourceDatabase" Type="SchemaExplorer.DatabaseSchema" Optional="False" Description="Database the table enums will come from." %>
<%--Type数据类型为TableSchema表明参数Table是一个表对象。--%>
<%-- 执行输出文件的函数 --%>
<%--this.OutPutFile();--%>
<% eachTable(); %>
<script runat="template">
TableSchema SourceTable;
public string getClassName()
{
string tablename = this.SourceTable.Name.Substring(2);
string firstChar = tablename.Substring(0,1);
string className = firstChar.ToUpper() + tablename.Substring(1);
return className ;
//return this.SourceTable.Name.Substring(2);
}
private void eachTable(){
foreach(TableSchema table in SourceDatabase.Tables){
this.SourceTable = table;
OutPutFile();
Response.WriteLine("Hello, processed table " + this.SourceTable.Name + "!");
}
Response.WriteLine(" !!---- e n d --------------!! " );
}
private void OutPutFile()
{
//生成列举表名的模板
CodeTemplate basicImplements =new basicImplements();
//指定输出路径
string filePath = OutputDirectory +"\\data\\basic\\"+ getClassName() + "_base_Imp" +".cs";
//给子模板参数赋值
basicImplements.SetProperty("SourceDatabase",this.SourceDatabase);
basicImplements.SetProperty("SourceTable",this.SourceTable);
basicImplements.RenderToFile(filePath,true);
//生成列表表字段的模板
CodeTemplate basicObject =new basicObject();
//指定输出路径
filePath = OutputDirectory +"\\data\\basic\\"+ getClassName() + "_base" +".cs";
//给子模板参数赋值
basicObject.SetProperty("SourceDatabase",this.SourceDatabase);
basicObject.SetProperty("SourceTable",this.SourceTable);
basicObject.RenderToFile(filePath,true);
CodeTemplate extModelImpl =new extModelImpl();
//指定输出路径
filePath = OutputDirectory +"\\data\\"+ getClassName() + "_Imp" +".cs";
//给子模板参数赋值
extModelImpl.SetProperty("SourceTable",this.SourceTable);
extModelImpl.RenderToFile(filePath,true);//not overwrite
CodeTemplate extModelClass =new extModelClass();
//指定输出路径
filePath = OutputDirectory +"\\tables\\"+ getClassName() +".cs";
//给子模板参数赋值
extModelClass.SetProperty("SourceTable",this.SourceTable);
extModelClass.RenderToFile(filePath,true);//not overwrite
CodeTemplate logic =new logic();
//指定输出路径
filePath = OutputDirectory +"\\logic\\l"+ getClassName() +".cs";
//给子模板参数赋值
logic.SetProperty("SourceTable",this.SourceTable);
logic.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfData =new wcfData();
//指定输出路径
filePath = OutputDirectory +"\\wcfData\\wcf"+ getClassName() +".cs";
//给子模板参数赋值
wcfData.SetProperty("SourceDatabase",this.SourceDatabase);
wcfData.SetProperty("SourceTable",this.SourceTable);
wcfData.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfInterface =new WcfInterface();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\I"+ getClassName() +".cs";
//给子模板参数赋值
wcfInterface.SetProperty("SourceDatabase",this.SourceDatabase);
wcfInterface.SetProperty("SourceTable",this.SourceTable);
wcfInterface.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfSvr =new wcfSvr();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\"+ this.SourceTable.Name.ToUpper() +".svc.cs";
//给子模板参数赋值
wcfSvr.SetProperty("SourceDatabase",this.SourceDatabase);
wcfSvr.SetProperty("SourceTable",this.SourceTable);
wcfSvr.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfSvc =new wcfSvc();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\"+ this.SourceTable.Name.ToUpper() +".svc";
//给子模板参数赋值
wcfSvc.SetProperty("SourceDatabase",this.SourceDatabase);
wcfSvc.SetProperty("SourceTable",this.SourceTable);
wcfSvc.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfList =new wcfList();
//指定输出路径
filePath = OutputDirectory +"\\wcfData\\wcf"+ getClassName() +"List.cs";
//给子模板参数赋值
wcfList.SetProperty("SourceDatabase",this.SourceDatabase);
wcfList.SetProperty("SourceTable",this.SourceTable);
wcfList.RenderToFile(filePath,true);//not overwrite
}
//输出文件
private void OutPutFile2()
{
//生成列举表名的模板
CodeTemplate basicImplements =new basicImplements();
//指定输出路径
string filePath = OutputDirectory +"\\model\\data\\basic\\"+ getClassName() + "_base_Imp" +".cs";
//给子模板参数赋值
basicImplements.SetProperty("SourceDatabase",this.SourceDatabase);
basicImplements.SetProperty("SourceTable",this.SourceTable);
basicImplements.RenderToFile(filePath,true);
//生成列表表字段的模板
CodeTemplate basicObject =new basicObject();
//指定输出路径
filePath = OutputDirectory +"\\model\\data\\basic\\"+ getClassName() + "_base" +".cs";
//给子模板参数赋值
basicObject.SetProperty("SourceDatabase",this.SourceDatabase);
basicObject.SetProperty("SourceTable",this.SourceTable);
basicObject.RenderToFile(filePath,true);
CodeTemplate extModelImpl =new extModelImpl();
//指定输出路径
filePath = OutputDirectory +"\\model\\data\\"+ getClassName() + "_Imp" +".cs";
//给子模板参数赋值
extModelImpl.SetProperty("SourceTable",this.SourceTable);
extModelImpl.RenderToFile(filePath,true);//not overwrite
CodeTemplate extModelClass =new extModelClass();
//指定输出路径
filePath = OutputDirectory +"\\model\\tables\\"+ getClassName() +".cs";
//给子模板参数赋值
extModelClass.SetProperty("SourceTable",this.SourceTable);
extModelClass.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfData =new wcfData();
//指定输出路径
filePath = OutputDirectory +"\\model\\wcfData\\wcf"+ getClassName() +".cs";
//给子模板参数赋值
wcfData.SetProperty("SourceDatabase",this.SourceDatabase);
wcfData.SetProperty("SourceTable",this.SourceTable);
wcfData.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfList =new wcfList();
//指定输出路径
filePath = OutputDirectory +"\\model\\wcfData\\list\\wcf"+ getClassName() +"List.cs";
//给子模板参数赋值
wcfList.SetProperty("SourceDatabase",this.SourceDatabase);
wcfList.SetProperty("SourceTable",this.SourceTable);
wcfList.RenderToFile(filePath,true);//not overwrite
CodeTemplate logic =new logic();
//指定输出路径
filePath = OutputDirectory +"\\logic\\l"+ getClassName() +".cs";
//给子模板参数赋值
logic.SetProperty("SourceTable",this.SourceTable);
logic.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfInterface =new WcfInterface();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\I"+ getClassName() +".cs";
//给子模板参数赋值
wcfInterface.SetProperty("SourceDatabase",this.SourceDatabase);
wcfInterface.SetProperty("SourceTable",this.SourceTable);
wcfInterface.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfSvr =new wcfSvr();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\"+ this.SourceTable.Name.ToUpper() +".svc.cs";
//给子模板参数赋值
wcfSvr.SetProperty("SourceDatabase",this.SourceDatabase);
wcfSvr.SetProperty("SourceTable",this.SourceTable);
wcfSvr.RenderToFile(filePath,true);//not overwrite
CodeTemplate wcfSvc =new wcfSvc();
//指定输出路径
filePath = OutputDirectory +"\\wcfService\\"+ this.SourceTable.Name.ToUpper() +".svc";
//给子模板参数赋值
wcfSvc.SetProperty("SourceDatabase",this.SourceDatabase);
wcfSvc.SetProperty("SourceTable",this.SourceTable);
wcfSvc.RenderToFile(filePath,true);//not overwrite
}
//解决方案输出路径
private string Directory = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Optional, NotChecked]
[DefaultValue("")]
public string OutputDirectory
{
get
{
return Directory;
}
set
{
if (value.EndsWith("\\")) value = value.Substring(0, value.Length -1);
Directory = value;
}
}
</script>