|
/***************************************************************************
Note to Dev Team, Contributors, all people of the Earth...
* PLEASE DO NOT CHANGE THIS FILE. ever.
* It's just the way we want it.
* If there is an issue please contact me (Rob) and let me know before any checkins
*
* Love and Kisses
* Rob
****************************************************************************/
using System;
using System.CodeDom;
using System.Text;
using System.Web.Compilation;
using SubSonic.Utilities;
using SubSonic.CodeGenerator;
namespace SubSonic
{
/// <summary>
/// The Magic...
/// </summary>
public class BuildProvider : System.Web.Compilation.BuildProvider
{
/// <summary>
/// This is the main method used by the build provider
/// </summary>
/// <param name="assemblyBuilder"></param>
public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
// retrieve input file
Utility.WriteTrace("Invoking BuildProvider");
//using (Stream inFile = VirtualPathProvider.OpenFile(VirtualPath))
//{
//StreamReader rdr = new StreamReader(inFile);
//string tableList = rdr.ReadToEnd();
//rdr.Close();
ICodeLanguage language;
try
{
language = CodeLanguageFactory.GetByCodeProviderName(GetDefaultCompilerType().CodeDomProviderType.Name);
}
catch
{
language = new CSharpCodeLanguage();
}
Utility.WriteTrace("Setting language to " + language.Identifier);
BuildCode(assemblyBuilder, language);
//}
}
private void BuildCode(AssemblyBuilder ab, ICodeLanguage language)
{
//make sure the providers are loaded
Utility.WriteTrace("Initializing Providers....");
DataService.LoadProviders();
string usings = ParseUtility.GetUsings(language);
StringBuilder code = new StringBuilder();
code.Append(usings);
//loop over the providers, and generate code for each
foreach (DataProvider provider in DataService.Providers)
{
Utility.WriteTrace("Creating code for " + provider.Name);
string[] tableList = DataService.GetTableNames(provider.Name);
string[] viewList = DataService.GetViewNames(provider.Name);
//generate the classes
foreach (string tbl in tableList)
{
code.Append(CodeService.RunClass(tbl, provider.Name, language));
Utility.WriteTrace("Generating Class " + tbl);
}
//generate the ODS Controllers
foreach (string tbl in tableList)
{
code.Append(CodeService.RunODS(tbl, provider.Name, language));
Utility.WriteTrace("Generating ODS Controller for: " + tbl);
}
//generate the read-only
Utility.WriteTrace("Generating View List");
foreach (string view in viewList)
{
code.Append(CodeService.RunReadOnly(view, provider.Name, language));
Utility.WriteTrace("Generating ReadOnly " + view);
}
//sps
Utility.WriteTrace("Generating SPs");
code.Append(CodeService.RunSPs(provider.Name, language));
}
//structs are built for all providers
Utility.WriteTrace("Generating Structs");
code.Append(CodeService.RunStructs(language));
ab.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(code.ToString()));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.