Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

, 16 Aug 2005
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
	 
#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Diagnostics;
using SmartInstitute;

#endregion

namespace SmartInstitute.DataAccessLayer.Factories
{

///<summary>
/// This class is an helper Repository that exposes CRUD methods for Student objects as static methods.
/// It forward the process to the concrete IStudentRepository that is defined in the configuration file.
///</summary>
public class StudentRepository : IStudentRepository
{
	private static volatile StudentRepository current;
   	private static object syncRoot = new Object();
   	private IStudentRepository repository;
	
	#region "Constructors"
		
	///<summary>
	/// Creates a new <see cref="StudentRepository"/> instance.
	///</summary>
	private StudentRepository()
	{
		this.repository = new DataAccessLayer.SqlClient.StudentRepository(string.Empty);
	}
	
	///<summary>
	/// The current <see href="StudentRepository"/> instance.
	///</summary>
	///<value></value>
	public static StudentRepository Current
	{
	  get 
	  {
	     if (current == null) 
	     {
	        lock (syncRoot) 
	        {
	           if (current == null)
	           {
			   		current = new StudentRepository();
			   }
	        }
	     }
	     return current;
	  }
	}
		
	#endregion "Constructors"
	
	#region Public Properties
	///<summary>
	/// The current IStudentRepository instance, as configured in the DataAccessLayer/ClientType configuration section.
	///</summary>
	private IStudentRepository Repository
	{
		get
		{
			return this.repository;
		}
	} 
	#endregion
	
	#region "Get from  Many To Many Relationship Functions"
	#endregion	
	
	
	#region "Delete Functions"
		
	/// <summary>
	/// 	Deletes rows from the DataSource.
	/// </summary>
	/// <param name="entityCollection">StudentCollection containing data.</param>
	/// <remarks>Deletes Students only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(StudentCollection entityCollection)
	{
		int number = 0;
		foreach (Student entity in entityCollection)
		{
			if( Delete(entity) )
			{
				number++;
			}
		}
		return number;
	}
		
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">Student object containing data.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(Student entity)
	{
		return Delete(entity.ID, entity.ChangeStamp);	
	}
					
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(System.Int32 ID, DateTime ChangeStamp)
	{
		return Repository.Delete(ID, ChangeStamp);
	}//end Delete
	
	
	/// <summary>
	/// Throws the delete concurrency exception.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	protected static void ThrowDeleteConcurrencyException(System.Int32 ID, DateTime ChangeStamp)
	{
		DBConcurrencyException conflict = new DBConcurrencyException("Concurrency exception: Cannot delete entity as it does not exist.");
		//conflict.ModifiedRecord = entity;
		throw conflict;
	}	
	
	#endregion
	
		
	#region "GetList Functions"
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetAll()
	{
		return GetAll(0, int.MaxValue);
	}
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pageLength">Number of rows to return.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetAll(int start, int pageLength)
	{
		return Repository.GetAll(start, pageLength);
	}
	
	#endregion
	
	#region Paged Recordset
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pageLength">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetPaged(int start, int pageLength, out int count)
	{
		return Repository.GetPaged(null, null, start, pageLength, out count);
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pageLength">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetPaged(string whereClause, string orderBy, int start, int pageLength, out int count)
	{
		return Repository.GetPaged(whereClause, orderBy, start, pageLength, out count);
	}
	
	#endregion
		
		
	#region "Get By Foreign Key Functions"
	#endregion
	
	
	#region "Get By Index Functions"

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Student index.
	/// </summary>
	/// <param name="ID"></param>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetByID(System.Int32 ID)
	{
		return GetByID(ID, 0, int.MaxValue);
	}	
	

	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Student index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pageLength">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <returns>Returns a typed collection of Student objects.</returns>
	public StudentCollection GetByID(System.Int32 ID, int start, int pageLength)
	{		
		return Repository.GetByID(ID, start, pageLength);
	}	

	#endregion "Get By Index Functions"


	#region "Insert Functions"
		
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Student</c> objects in a <c>StudentCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>Student</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(StudentCollection entityCollection)
	{
		int number = 0;
		//Extract only dirty objects to save time and bandwidth
		foreach (Student entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if ( Insert(entity) )
				{
					number++;
				}
			}
		}
		return number;
	}

	/// <summary>
	/// 	Inserts a Student object into the datasource using a transaction.
	/// </summary>
	/// <param name="entity">Student object to insert.</param>
	/// <remarks>After inserting into the datasource, the Student object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(Student entity)
	{
		return Repository.Insert(entity);
	}	
	#endregion


	#region "Update Functions"
		
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>Student</c> objects in a <c>StudentCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>Student</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update.</returns>
	public int Update(StudentCollection entityCollection)
	{	
		int number = 0;
		foreach (Student entity in entityCollection)
		{
			if ((entity.IsDirty) && !(entity.IsNew))
			{
				if ( Update(entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="entity">Student object to update.</param>
	/// <remarks>After updating the datasource, the Student object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(Student entity)
	{
		return Repository.Update(entity);
	}
	#endregion


	#region "Save Functions"
	
	/// <summary>
	/// 	Save rows changes in the datasource (insert, update ,delete).
	/// </summary>
	/// <param name="entity">Student object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Student</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(Student entity)
	{		
		if (entity.IsDeleted)
			Delete(entity);
			
		else if ((entity.IsDirty) && !(entity.IsNew))
			Update(entity);
			
		else if (entity.IsNew)
			Insert(entity);
	}
		
	/// <summary>
	/// 	Save rows changes in the datasource (insert, update ,delete).
	/// </summary>
	/// <param name="entityCollection"><c>Student</c> objects in a <c>StudentCollection</c> object to save.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>Student</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(StudentCollection entityCollection)
	{
		foreach (Student entity in entityCollection)
		{			
			Save(entity);
		}
	}
	#endregion


	#region "Helper Functions"	
	
	///<summary>
	/// Fill an StudentCollection From a DataSet
	///</summary>
	/// <param name="dataSet">the DataSet</param>
	/// <param name="rows">The collection to fill</param>
	/// <param name="start">Start row</param>
	/// <param name="pageLength">number of row.</param>
	///<returns><see chref="StudentCollection"/></returns>
	protected static StudentCollection Fill(DataSet dataSet, StudentCollection rows, int start, int pageLength)
	{
		int recordnum = 0;
		
		System.Collections.IEnumerator dataRows =  dataSet.Tables[0].Rows.GetEnumerator();
		
		while (dataRows.MoveNext() && (pageLength != 0))
		{
			if(recordnum >= start)
			{
				DataRow row = (DataRow)dataRows.Current;
			
				Student c = new Student();
				c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
				c.FirstName = (Convert.IsDBNull(row["FirstName"]))?string.Empty:(System.String)row["FirstName"];
				c.MiddleName = (Convert.IsDBNull(row["MiddleName"]))?string.Empty:(System.String)row["MiddleName"];
				c.LastName = (Convert.IsDBNull(row["LastName"]))?string.Empty:(System.String)row["LastName"];
				c.PresentAddress1 = (Convert.IsDBNull(row["PresentAddress1"]))?string.Empty:(System.String)row["PresentAddress1"];
				c.PresentAddress2 = (Convert.IsDBNull(row["PresentAddress2"]))?string.Empty:(System.String)row["PresentAddress2"];
				c.PermanentAddress1 = (Convert.IsDBNull(row["PermanentAddress1"]))?string.Empty:(System.String)row["PermanentAddress1"];
				c.PermanentAddress2 = (Convert.IsDBNull(row["PermanentAddress2"]))?string.Empty:(System.String)row["PermanentAddress2"];
				c.StudentID = (Convert.IsDBNull(row["StudentID"]))?string.Empty:(System.String)row["StudentID"];
				c.Status = (Convert.IsDBNull(row["Status"]))?(int)0:(System.Int32)row["Status"];
				c.CGPA = (Convert.IsDBNull(row["CGPA"]))?0.0F:(System.Single)row["CGPA"];
				c.CreditCompleted = (Convert.IsDBNull(row["CreditCompleted"]))?(int)0:(System.Int32)row["CreditCompleted"];
				c.DateAdmitted = (Convert.IsDBNull(row["DateAdmitted"]))?DateTime.MinValue:(System.DateTime)row["DateAdmitted"];
				c.DateGraduated = (Convert.IsDBNull(row["DateGraduated"]))?DateTime.MinValue:(System.DateTime)row["DateGraduated"];
				c.ChangeStamp = (Convert.IsDBNull(row["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)row["ChangeStamp"];
				c.AcceptChanges();
				rows.Add(c);
				pageLength -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}
			
	
	
	/// <summary>
	/// Refreshes the <see cref="Student"/> object from the <see cref="DataSet"/>.
	/// </summary>
	/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
	/// <param name="entity">The <see cref="Student"/> object.</param>
	protected static void RefreshEntity(DataSet dataSet, Student entity)
	{
		DataRow dataRow = dataSet.Tables[0].Rows[0];
		
		entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
		entity.FirstName = (Convert.IsDBNull(dataRow["FirstName"]))?string.Empty:(System.String)dataRow["FirstName"];
		entity.MiddleName = (Convert.IsDBNull(dataRow["MiddleName"]))?string.Empty:(System.String)dataRow["MiddleName"];
		entity.LastName = (Convert.IsDBNull(dataRow["LastName"]))?string.Empty:(System.String)dataRow["LastName"];
		entity.PresentAddress1 = (Convert.IsDBNull(dataRow["PresentAddress1"]))?string.Empty:(System.String)dataRow["PresentAddress1"];
		entity.PresentAddress2 = (Convert.IsDBNull(dataRow["PresentAddress2"]))?string.Empty:(System.String)dataRow["PresentAddress2"];
		entity.PermanentAddress1 = (Convert.IsDBNull(dataRow["PermanentAddress1"]))?string.Empty:(System.String)dataRow["PermanentAddress1"];
		entity.PermanentAddress2 = (Convert.IsDBNull(dataRow["PermanentAddress2"]))?string.Empty:(System.String)dataRow["PermanentAddress2"];
		entity.StudentID = (Convert.IsDBNull(dataRow["StudentID"]))?string.Empty:(System.String)dataRow["StudentID"];
		entity.Status = (Convert.IsDBNull(dataRow["Status"]))?(int)0:(System.Int32)dataRow["Status"];
		entity.CGPA = (Convert.IsDBNull(dataRow["CGPA"]))?0.0F:(System.Single)dataRow["CGPA"];
		entity.CreditCompleted = (Convert.IsDBNull(dataRow["CreditCompleted"]))?(int)0:(System.Int32)dataRow["CreditCompleted"];
		entity.DateAdmitted = (Convert.IsDBNull(dataRow["DateAdmitted"]))?DateTime.MinValue:(System.DateTime)dataRow["DateAdmitted"];
		entity.DateGraduated = (Convert.IsDBNull(dataRow["DateGraduated"]))?DateTime.MinValue:(System.DateTime)dataRow["DateGraduated"];
		entity.ChangeStamp = (Convert.IsDBNull(dataRow["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)dataRow["ChangeStamp"];
		entity.AcceptChanges();
	}
		
	#region DeepLoad
	#region Deep Load By Entity
	/// <summary>
	/// Deep Load the IEntity object with all of the child 
	/// property collections only 1 Level Deep.
	/// </summary>
	/// <remarks>
	/// <seealso cref="DeepLoad"/> overloaded methods for a recursive N Level deep loading method.
	/// </remarks>
	/// <param name="entity">Student Object</param>
	public void DeepLoad(Student entity)
	{
	 	DeepLoad(entity, false, DeepLoadType.ExcludeChildren, new Type[] {});
	}
	
	/// <summary>
	/// Deep Load the IEntity object with all of the child 
	/// property collections only 1 Level Deep.
	/// </summary>
	/// <remarks>
	/// <seealso cref="DeepLoad"/> overloaded methods for a recursive N Level deep loading method.
	/// </remarks>
	/// <param name="entity">Student Object</param>
	/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
	public void DeepLoad(Student entity, bool deep)
	{
	 	DeepLoad(entity, deep, DeepLoadType.ExcludeChildren, new Type[] {});
	}
	
	/// <summary>
	/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
	/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
	/// </summary>
	/// <remarks>
	/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
	/// </remarks>
	/// <param name="entity">The <see cref="Student"/> object to load.</param>
	/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
	/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
	/// <param name="childTypes">Student Property Collection Type Array To Include or Exclude from Load</param>
	public void DeepLoad(Student entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes)
	{
		#region Argument Validation
		//Argument checks
		if (entity ==  null)
		{
			throw new ArgumentNullException("The argument Student, can not be null.");
		}
		if (!Enum.IsDefined(typeof(DeepLoadType), deepLoadType))
		{
			throw new ArgumentNullException("A valid DeepLoadType option is not present.");
		}
		if (childTypes == null)
		{
			throw new ArgumentNullException("A valid Type[] array is not present.");
		}
		#endregion
		
		//In case an event can trigger the disabling of the deep load
		if (deepLoadType == DeepLoadType.Ignore)
		{
			return;
		}
		
		//Create a HashTable list of types for easy access
		Hashtable innerList = new Hashtable(childTypes.Length);
		for(int i=0; i < childTypes.Length; i++)
		{
			innerList.Add(childTypes[i], childTypes[i].ToString()); 
		}
		
		Debug.Indent();
		Debug.WriteLine("DeepLoad object 'Student'");
		Debug.Indent();
		
		// Load Entity through Provider
			//deep load child collections  - Call GetByID methods when available
		if ((deepLoadType == DeepLoadType.IncludeChildren && innerList[typeof(CourseTakenByStudentCollection)] != null)
			|| (deepLoadType == DeepLoadType.ExcludeChildren && innerList[typeof(CourseTakenByStudentCollection)] == null))
		{
			Debug.WriteLine("- property 'CourseTakenByStudentCollection' loaded.");
			entity.CourseTakenByStudentCollection = CourseTakenByStudentRepository.Current.GetByStudentID(entity.ID);
			if (deep)
			{
				CourseTakenByStudentRepository.Current.DeepLoad(entity.CourseTakenByStudentCollection, deep, deepLoadType, childTypes);
			}
		}		
		if ((deepLoadType == DeepLoadType.IncludeChildren && innerList[typeof(AssessmentCollection)] != null)
			|| (deepLoadType == DeepLoadType.ExcludeChildren && innerList[typeof(AssessmentCollection)] == null))
		{
			Debug.WriteLine("- property 'AssessmentCollection' loaded.");
			entity.AssessmentCollection = AssessmentRepository.Current.GetByStudentID(entity.ID);
			if (deep)
			{
				AssessmentRepository.Current.DeepLoad(entity.AssessmentCollection, deep, deepLoadType, childTypes);
			}
		}		
		if ((deepLoadType == DeepLoadType.IncludeChildren && innerList[typeof(AccountCollection)] != null)
			|| (deepLoadType == DeepLoadType.ExcludeChildren && innerList[typeof(AccountCollection)] == null))
		{
			Debug.WriteLine("- property 'AccountCollection' loaded.");
			entity.AccountCollection = AccountRepository.Current.GetByStudentID(entity.ID);
			if (deep)
			{
				AccountRepository.Current.DeepLoad(entity.AccountCollection, deep, deepLoadType, childTypes);
			}
		}		
		Debug.Unindent();
		Debug.Unindent();
		Debug.WriteLine("");
		return;
	}
	
	#endregion
	
	#region Deep Load By Entity Collection
	/// <summary>
	/// Deep Loads the <see cref="StudentCollection"/> object with all of the child 
	/// property collections only 1 Level Deep.
	/// </summary>
	/// <remarks>
	/// <seealso cref="DeepLoad"/> overloaded methods for a recursive N Level deep loading method.
	/// </remarks>
	/// <param name="entityCollection">the <see cref="StudentCollection"/> Object to deep loads.</param>
	public void DeepLoad(StudentCollection entityCollection)
	{
		 DeepLoad(entityCollection, false, DeepLoadType.ExcludeChildren, new Type[] {});
	}
	
	/// <summary>
	/// Deep Loads the <see cref="StudentCollection"/> object.
	/// </summary>
	/// <remarks>
	/// <seealso cref="DeepLoad"/> overloaded methods for a recursive N Level deep loading method.
	/// </remarks>
	/// <param name="entityCollection">the <see cref="StudentCollection"/> Object to deep loads.</param>
	/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
	public void DeepLoad(StudentCollection entityCollection, bool deep)
	{
		 DeepLoad(entityCollection, deep, DeepLoadType.ExcludeChildren, new Type[] {});
	}	

	/// <summary>
	/// Deep Loads the entire <see cref="StudentCollection"/> object with criteria based of the child 
	/// property collections only N Levels Deep based on the DeepLoadType.
	/// </summary>
	/// <remarks>
	/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire collection's object graph.
	/// </remarks>
	/// <param name="entityCollection">The <see cref="StudentCollection"/> instance to load.</param>
	/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
	/// <param name="deepLoadType"><see cref="DeepLoadType"/> Enumeration to Include/Exclude object property collections from Load.
	///		Use DeepLoadType.[IncludeChildren/ExcludeChildren]WithRecursion to traverse the entire object graph.
	///	</param>
	/// <param name="childTypes"><see cref="Student"/> Property Collection Type Array To Include or Exclude from Load</param>
	public void DeepLoad(StudentCollection entityCollection, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes)
	{
		#region Argument Validation
		//Argument checks
		if (entityCollection ==  null)
		{
			throw new ArgumentNullException("A valid non-null, StudentCollection object is not present.");
		}
		if (!Enum.IsDefined(typeof(DeepLoadType), deepLoadType))
		{
			throw new ArgumentNullException("A valid DeepLoadType option is not present.");
		}
		if (childTypes == null)
		{
			throw new ArgumentNullException("A valid Type[] array is not present.");
		}
		#endregion
				
		//In case an event can trigger the disabling of the deepload
		if (deepLoadType == DeepLoadType.Ignore)
		{
			return;
		}
		
		foreach (Student entity in entityCollection)
		{
			DeepLoad(entity, deep, deepLoadType, childTypes);
		}		
		return;
	}
	#endregion
	#endregion 
	
	#region DeepSave
	
	#region Deep Save By Entity
	
	/// <summary>
	/// Deep Save the <see cref="Student"/> object with all of the child
	/// property collections N Levels Deep.
	/// </summary>
	/// <param name="entity">Student Object</param>
	public bool DeepSave(Student entity)
	{
		return DeepSave(entity, DeepSaveType.ExcludeChildren, new Type[] {} );
	}
				
	/// <summary>
	/// Deep Save the entire object graph of the Student object with criteria based of the child 
	/// Type property array and DeepSaveType.
	/// </summary>
	/// <param name="entity">Student Object</param>
	/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.
	///	</param>
	/// <param name="childTypes">Student Property Collection Type Array To Include or Exclude from Save</param>
	public bool DeepSave(Student entity, DeepSaveType deepSaveType, System.Type[] childTypes)
	{
		#region Argument Validation
		//Argument checks
		if (entity ==  null)
		{
			throw new ArgumentNullException("The argument Student, can not be null.");
		}
		if (!Enum.IsDefined(typeof(DeepSaveType), deepSaveType))
		{
			throw new ArgumentNullException("A valid DeepSaveType option is not present.");
		}
		if (childTypes == null)
		{
			throw new ArgumentNullException("A valid Type[] array is not present.");
		}
		#endregion
		
		//In case an event can trigger the disabling of the deepsave
		if (deepSaveType == DeepSaveType.Ignore)
		{
			return true;
		}
		
		//Create a HashTable list of types for easy access
		Hashtable innerList = new Hashtable(childTypes.Length);
		for(int i=0; i < childTypes.Length; i++)
		{
			innerList.Add(childTypes[i], childTypes[i].ToString()); 
		}

		// Save Root Entity through Provider
		StudentRepository rep = new StudentRepository();
		rep.Save(entity);
		//deep save child collections  - Call DeepSave() Methods on Children

		if ((deepSaveType == DeepSaveType.IncludeChildren && innerList[typeof(CourseTakenByStudentCollection)] != null)
			|| (deepSaveType == DeepSaveType.ExcludeChildren && innerList[typeof(CourseTakenByStudentCollection)] == null))
		{
			CourseTakenByStudentRepository.Current.DeepSave(entity.CourseTakenByStudentCollection);
		} 

		if ((deepSaveType == DeepSaveType.IncludeChildren && innerList[typeof(AssessmentCollection)] != null)
			|| (deepSaveType == DeepSaveType.ExcludeChildren && innerList[typeof(AssessmentCollection)] == null))
		{
			AssessmentRepository.Current.DeepSave(entity.AssessmentCollection);
		} 

		if ((deepSaveType == DeepSaveType.IncludeChildren && innerList[typeof(AccountCollection)] != null)
			|| (deepSaveType == DeepSaveType.ExcludeChildren && innerList[typeof(AccountCollection)] == null))
		{
			AccountRepository.Current.DeepSave(entity.AccountCollection);
		} 
		
		return true;
	}
	#endregion
	
	#region Deep Save By Entity Collection
	/// <summary>
	/// Deep Save the entire StudentCollection object with all of the child 
	/// property collections.
	/// </summary>
	/// <param name="entityCollection">StudentCollection Object</param>
	public bool DeepSave(StudentCollection entityCollection)
	{
		return DeepSave(entityCollection, DeepSaveType.ExcludeChildren, new Type[] {});
	}
	
	
	/// <summary>
	/// Deep Save the entire object graph of the StudentCollection object with criteria based of the child 
	/// property collections.
	/// </summary>
	/// <param name="entityCollection">StudentCollection Object</param>
	/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
	/// <param name="childTypes">Student Property Collection Type Array To Include or Exclude from Save</param>
	public bool DeepSave(StudentCollection entityCollection, DeepSaveType deepSaveType, System.Type[] childTypes)
	{
		#region Argument Validation
		//Argument checks
		if (entityCollection ==  null)
		{
			throw new ArgumentNullException("A valid non-null, StudentCollection object is not present.");
		}
		if (!Enum.IsDefined(typeof(DeepSaveType), deepSaveType))
		{
			throw new ArgumentNullException("A valid DeepSaveType option is not present.");
		}
		if (childTypes == null)
		{
			throw new ArgumentNullException("A valid Type[] array is not present.");
		}
		#endregion
				
		//In case an event can trigger the disabling of the deepsave
		if (deepSaveType == DeepSaveType.Ignore)
		{
			return true;
		}
		
		bool deepSaveResult = true;
		bool result;
		
		foreach (Student entity in entityCollection)
		{
			result = DeepSave(entity, deepSaveType, childTypes);
			if (!result){
				 deepSaveResult = false;
			}
		}
		
		return deepSaveResult;
	}
	#endregion
	
	#endregion
		
	#endregion "Helper Functions"
	
}//end class
} // end namespace

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Omar Al Zabir
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid