Пример #1
0
		public string GetPartialClassesFromDatabase()
		{
			List<Table> tables = this.database.Tables;
			StringBuilder Code = new StringBuilder();
			#region File top
			Code.Append(@"using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Runtime.Serialization;
using Bobs.CachedDataAccess;
namespace Bobs
{

");

			#endregion

			//String.Format("0x{0:x4}", ColumnIndex)

			Code.AppendLine(CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.Tables.vm", new Dictionary<string, object>() { { "tables", tables } }));
			Code.Append(@"
	#region TablesEnum
	public enum TablesEnum
	{");
			foreach (Table table in tables)
			{
				Code.Append(@"
		/// <summary>
		/// " + table.Description + @"
		/// </summary>
		" + table.Name + @" = " + String.Format("0x{0:x4}", tables.IndexOf(table) + 1) + @",");
				if (this.Progress != null) this.Progress();
			}
			Code.Append(@"
	}
	#endregion
");

			foreach (Table table in tables)
			{
				#region Bob Generation

				#region Bob top
				Code.Append(@"
	#region " + table.Name + @"
	/// <summary>
	/// " + table.Description + @"
	/// </summary>
	public partial class " + table.Name + @" : Model.Entities." + table.Name + @", IBob, ISerializable
	{
		public Bob Bob {get; private set;}
		public object this[object columnEnum]
		{
			get	{ return Bob[columnEnum]; }
			set	{ Bob[columnEnum] = value; }
		}
		#region IsDirty
		public bool IsDirty(object columnEnum)
		{
			return this.Bob.IsDirty(columnEnum);
		}
		public bool IsDirty()
		{
			return this.Bob.IsDirty();
		}
		#endregion
		#region Update methods
		public int Update(){
			return Update(null);
		}
		public int Update(Transaction t)
		{
			BeforeUpdate(t);
			var result = this.Bob.Update(t);
			AfterUpdate(t);
			return result;
		}
		partial void BeforeUpdate(Transaction t);
		partial void AfterUpdate(Transaction t);
		#endregion

		#region Delete methods
		public void Delete(){
			Delete(null);
		}
		public void Delete(Transaction t)
		{
			BeforeDelete(t);
			this.Bob.Delete(t);
			AfterDelete(t);
		}
		partial void BeforeDelete(Transaction t);
		partial void AfterDelete(Transaction t);
		#endregion


		#region Initialise methods 
		internal void Initialise(BobSet bs, DataRow row)
		{
			this.Bob.Initialise(bs, row);
		}
		internal void Initialise(DataRow row)
		{
			this.Bob.Initialise(row);
			
		}
		#endregion
		#region ExtraSelectElementHolder 
		public Bobs.Bob.ExtraSelectElementHolder ExtraSelectElements
		{
			get { return this.Bob.ExtraSelectElements; }
			set	{ this.Bob.ExtraSelectElements = value; }
		}
		#endregion
		public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			Bob.GetObjectData(info, context);
		}

		");
	#endregion

				Code.AppendLine(CodeWriter.GenerateColumnsEnum(table.Name, table.Columns, tables.IndexOf(table) + 1));

				Code.AppendLine(CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.Bob.GetColumnName.vm", new Dictionary<string, object>() { { "table", table } }));
				Code.AppendLine(CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.Bob.DoesColumnCauseInvalidation.vm", new Dictionary<string, object>() { { "table", table } }));

				Code.AppendLine(table.HasSinglePrimaryKey ? CodeWriter.GenerateCommonCodeForPrimaryKey(table) : CodeWriter.GenerateCommonCodeForMultiKey(table));

				#region Bob end
				Code.Append(@"
	}
	#endregion");
				#endregion
				#endregion

				Code.AppendLine(CodeWriter.GenerateTemplate(table));
				Code.AppendLine(CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.ChildrenDefinitions.vm", new Dictionary<string, object>() { { "table", table } }));
				Code.AppendLine(CodeWriter.RunNVelocityTemplate("Templates.Bobs.Common.DataHolder.vm", new Dictionary<string, object>() { { "table", table } }));
				Code.AppendLine(CodeWriter.GenerateBobSet(table));


				#region TableDef Generation

				#region TableDef top

				Code.Append(@"	#region " + table.Name + @"TableDef
	public class " + table.Name + @"TableDef : TableDef
	{");
				#endregion

				Code.Append(CodeWriter.GenerateTableDef(table));

				Code.Append(CodeWriter.GenerateInitColumn(table.Name, table.Columns));

				Code.Append(CodeWriter.GenerateColumnData(table.Name, table.Columns));
				#region TableDef end
				Code.Append(@"
	}
	#endregion");
				#endregion

				#endregion


				Code.Append(Environment.NewLine);

				if (this.Progress != null) this.Progress();
			}
			#region generate stored procedure code
			Code.Append(Environment.NewLine);
			CodeSections.CodeSection cs = new CodeSections.CodeSection();
			CodeSections.Region storedProcRegion = new BobsCommonFileGenerator.CodeSections.Region("stored procedures");
			cs.Add(storedProcRegion);

			CodeSections.Class storedProcedures = new BobsCommonFileGenerator.CodeSections.Class("StoredProcedures");
			AddStoredProcedureDefinitionsFromDatabase(database, storedProcedures);
			storedProcRegion.Add(storedProcedures);
			foreach (string s in cs.GetCSharpSourceCode())
			{
				Code.Append("\t" + s + Environment.NewLine);
			}

			#endregion

			#region File bottom
			Code.Append(@"
}");
			#endregion


			return Code.ToString();
		}
Пример #2
0
		internal void Add(CodeSection codeSection){
			this.codeSections.Add(codeSection);
		}
Пример #3
0
		static bool IsClassAndMatchesName(string name, CodeSection cs)
		{
			return IsClass(cs) && ((Class)cs).name == name;
		}
Пример #4
0
		private static bool IsClass(CodeSection cs)
		{
			return cs.GetType() == typeof(Class);
		}
Пример #5
0
		internal void Add(CodeSection section)
		{
			base.Add(section);
		}