Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Implementing Model-View-Presenter in ASP.NET

, 17 Nov 2007 CPOL
Three implementations of Model-View-Presenter in ASP.NET 2.0.
MVPSampleApp.zip
MVP.SampleApp
Lib
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
MySql.Data.dll
nunit.framework.dll
Rhino.Mocks.dll
Model
Data
Interfaces
Properties
Presentation
Presentation.Tests
Properties
Interfaces
Properties
SubSonic
ActiveRecord
Builder
CodeGeneration
Templates
CodeLanguage
Configuration
Controls
Calendar
lang
skin
active-bg.gif
calendar.gif
dark-bg.gif
hover-bg.gif
menuarrow.gif
normal-bg.gif
rowhover-bg.gif
status-bg.gif
title-bg.gif
today-bg.gif
Resources
DataProviders
Properties
Sql Tools
SubSonic.snk
Sugar
WebApp
App_Data
Views
SQL2000SampleDb.zip
SQL2000SampleDb.msi
/***************************************************************************
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alex Mueller
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 17 Nov 2007
Article Copyright 2007 by Alex Mueller
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid