[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[CodeTemplateProperty(CodeTemplatePropertyOption.Optional)]
[Category("General")]
[Description("The directory to output the results to.")]
[DefaultValue("")]
public string OutputDirectory
{
get
{
if (_outputDirectory.Length == 0) return this.CodeTemplateInfo.DirectoryName + "output";
return _outputDirectory;
}
set
{
if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1);
_outputDirectory = value;
}
}
</script>
private System.Collections.Hashtable _CodeTemplates = new System.Collections.Hashtable();
public void Go()
{
#region Create all directory and copy common files
SafeCreateDirectory(OutputDirectory + "
\\Model");
SafeCreateDirectory(OutputDirectory + "
\\DataAccess");
SafeCreateDirectory(OutputDirectory + "
\\Biz");
#endregion
#region LoadTemplates
LoadTemplates();
#endregion
#region Go
for (int i=0; i < SourceDatabase.Tables.Count; i++)
{
//Response.WriteLine(SourceDatabase.Tables[i].Name);
}
for (int i=0; i < SourceDatabase.Tables.Count; i++)
{
if(SourceDatabase.Tables[i].Name.StartsWith("pbcat")) continue;
CodeSmith.Engine.CodeTemplate entity = this.GetTemplate(entityTemplatename);
if (entity != null)
{
//this.GetTemplate(entityTemplatename).SetProperty("SourceDatabase", SourceDatabase);
this.GetTemplate(entityTemplatename).SetProperty("SourceTable", SourceDatabase.Tables[i]);
this.GetTemplate(entityTemplatename).SetProperty("NameSpace", NameSpace);
this.GetTemplate(entityTemplatename).SetProperty("DevelopersName", DevelopersName);
this.GetTemplate(entityTemplatename).RenderToFile(OutputDirectory + "
\\Model\\" + GetClassName(SourceDatabase.Tables[i].Name) + "Info.cs", true);
//
}
if(IncludeCollection)
{
CodeSmith.Engine.CodeTemplate entities = this.GetTemplate("CollectionBase.cst");
if(entities != null)
{
this.GetTemplate("CollectionBase.cst").SetProperty("ClassName", GetClassName(SourceDatabase.Tables[i].Name) + "Info");
this.GetTemplate("CollectionBase.cst").SetProperty("CollectionClassName", GetClassName(SourceDatabase.Tables[i].Name) + "InfoCollection");
this.GetTemplate("CollectionBase.cst").SetProperty("NameSpace", NameSpace);
this.GetTemplate("CollectionBase.cst").SetProperty("DevelopersName", DevelopersName);
this.GetTemplate("CollectionBase.cst").RenderToFile(OutputDirectory + "
\\Model\\" + GetClassName(SourceDatabase.Tables[i].Name) + "InfoCollection.cs", true);
}
//
}
//
if(IncludeDataAccess)
{
CodeSmith.Engine.CodeTemplate dao = this.GetTemplate("Dao.cst");
if(dao != null)
{
//Response.WriteLine("dao is not null!");
this.GetTemplate("Dao.cst").SetProperty("SourceDatabase", SourceDatabase);
this.GetTemplate("Dao.cst").SetProperty("SourceTable", SourceDatabase.Tables[i]);
this.GetTemplate("Dao.cst").SetProperty("NameSpace", NameSpace);
this.GetTemplate("Dao.cst").SetProperty("DevelopersName", DevelopersName);
this.GetTemplate("Dao.cst").RenderToFile(OutputDirectory + "
\\DataAccess\\" + GetClassName(SourceDatabase.Tables[i].Name) + "Dao.cs", true);
}
else
{
Response.WriteLine("dao is null!");
}
}
//
if(IncludeBizObject)
{
CodeSmith.Engine.CodeTemplate biz = this.GetTemplate("BizObject.cst");
if(biz != null)
{
this.GetTemplate("BizObject.cst").SetProperty("SourceDatabase", SourceDatabase);
this.GetTemplate("BizObject.cst").SetProperty("SourceTable", SourceDatabase.Tables[i]);
this.GetTemplate("BizObject.cst").SetProperty("NameSpace", NameSpace);
this.GetTemplate("BizObject.cst").SetProperty("DevelopersName", DevelopersName);
this.GetTemplate("BizObject.cst").RenderToFile(OutputDirectory + "
\\Biz\\" + GetClassName(SourceDatabase.Tables[i].Name) + ".cs", true);
}
}
}
Response.WriteLine("Success!");
#endregion
}
</script>