我们的分析思路是从顶层到底层来进行。
先看web服务,这个web服务是采用SOAP头进行验证的。
1.这里是web服务,web服务很简单。采用的是调用一个函数
Code
public class CourseService : SecurityWebService
{
[WebMethod]
[SoapHeader("Credentials")]
public Course GetCourseDetails( int courseID )
{
base.VerifyCredentials();
return base.ForSubSysTem.GetCourseDetail( courseID );
}
}
public class CourseService : SecurityWebService
{
[WebMethod]
[SoapHeader("Credentials")]
public Course GetCourseDetails( int courseID )
{
base.VerifyCredentials();
return base.ForSubSysTem.GetCourseDetail( courseID );
}
}
其中。
2.我们引用了ForSubSysTem这个层的内容,所以我们需要建立一个项目或者类来进行该处的完成。其的定义如下:
Code
public class forSubSystem
{
public Course GetCourseDetail( int courseID )
{
Course course = CourseRepository.Current.GetByID( courseID )[0]; //CourseRepository 是Course的集合类用于响应、订阅各个Course
CourseRepository.Current.DeepLoad( course, true, DataAccessLayer.DeepLoadType.IncludeChildren,
new Type [] { typeof( CourseSectionCollection ), typeof( SectionRoutineCollection ) } ); //这里的一些函数采用codeSmith进行生成
return course;
}
}
public class forSubSystem
{
public Course GetCourseDetail( int courseID )
{
Course course = CourseRepository.Current.GetByID( courseID )[0]; //CourseRepository 是Course的集合类用于响应、订阅各个Course
CourseRepository.Current.DeepLoad( course, true, DataAccessLayer.DeepLoadType.IncludeChildren,
new Type [] { typeof( CourseSectionCollection ), typeof( SectionRoutineCollection ) } ); //这里的一些函数采用codeSmith进行生成
return course;
}
}
3.这里调用了 CurrseRepository 来进行。而 CurrseRepository 是利用CodeSmith 及其社区的cst来进行生成的。虽然貌似很复杂,确是很容易的操作就可以完成
Code
public class CourseRepository : ICourseRepository
{
private static volatile CourseRepository current;
private static object syncRoot = new Object();
private ICourseRepository repository;
#region "Constructors"
///<summary>
/// Creates a new <see cref="CourseRepository"/> instance.
///</summary>
private CourseRepository()
{
this.repository = new DataAccessLayer.SqlClient.CourseRepository(string.Empty);
}
///<summary>
/// The current <see href="CourseRepository"/> instance.
///</summary>
///<value></value>
public static CourseRepository Current
{
get
{
if (current == null)
{
lock (syncRoot)
{
if (current == null)
{
current = new CourseRepository();
}
}
}
return current;
}
}
#endregion "Constructors"
#region Public Properties
///<summary>
/// The current ICourseRepository instance, as configured in the DataAccessLayer/ClientType configuration section.
///</summary>
private ICourseRepository Repository
{
get
{
return this.repository;
}
}
#region "Get By Foreign Key Functions"
#endregion
#region "Get By Index Functions"
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 index.
/// </summary>
/// <param name="ID"></param>
/// <returns>Returns a typed collection of Course objects.</returns>
public CourseCollection GetByID(System.Int32 ID)
{
return GetByID(ID, 0, int.MaxValue);
}
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 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 Course objects.</returns>
public CourseCollection GetByID(System.Int32 ID, int start, int pageLength)
{
return Repository.GetByID(ID, start, pageLength);
}
}
public class CourseRepository : ICourseRepository
{
private static volatile CourseRepository current;
private static object syncRoot = new Object();
private ICourseRepository repository;
#region "Constructors"
///<summary>
/// Creates a new <see cref="CourseRepository"/> instance.
///</summary>
private CourseRepository()
{
this.repository = new DataAccessLayer.SqlClient.CourseRepository(string.Empty);
}
///<summary>
/// The current <see href="CourseRepository"/> instance.
///</summary>
///<value></value>
public static CourseRepository Current
{
get
{
if (current == null)
{
lock (syncRoot)
{
if (current == null)
{
current = new CourseRepository();
}
}
}
return current;
}
}
#endregion "Constructors"
#region Public Properties
///<summary>
/// The current ICourseRepository instance, as configured in the DataAccessLayer/ClientType configuration section.
///</summary>
private ICourseRepository Repository
{
get
{
return this.repository;
}
}
#region "Get By Foreign Key Functions"
#endregion
#region "Get By Index Functions"
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 index.
/// </summary>
/// <param name="ID"></param>
/// <returns>Returns a typed collection of Course objects.</returns>
public CourseCollection GetByID(System.Int32 ID)
{
return GetByID(ID, 0, int.MaxValue);
}
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 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 Course objects.</returns>
public CourseCollection GetByID(System.Int32 ID, int start, int pageLength)
{
return Repository.GetByID(ID, start, pageLength);
}
}
4. 我们这里 利用到了 private ICourseRepository repository; 其中 ICourseRepository 是一个接口,题目提供函数的声明
Code
public interface ICourseRepository
{
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 index.
/// </summary>
/// <param name="start">Row number at which to start reading.</param>
/// <param name="pagelen">Number of rows to return.</param>
/// <param name="ID"></param>
/// <remarks></remarks>
/// <returns>Returns a typed collection of Course objects.</returns>
CourseCollection GetByID(System.Int32 ID, int start, int pagelen);
}
public interface ICourseRepository
{
/// <summary>
/// Gets rows from the datasource based on the PK_Course_1 index.
/// </summary>
/// <param name="start">Row number at which to start reading.</param>
/// <param name="pagelen">Number of rows to return.</param>
/// <param name="ID"></param>
/// <remarks></remarks>
/// <returns>Returns a typed collection of Course objects.</returns>
CourseCollection GetByID(System.Int32 ID, int start, int pagelen);
}
5.这里用到了 CourseCollection 这是Course
Code
///<summary>
/// This class is a strong typed collection of <see cref="Course"/> objects that inherits from the <see cref="CourseCollectionBase"/> class.
///</summary>
/// <remark>
/// This class contains specfic implementations that are not part of the CsTemplates framework.
/// </remark>
[Serializable]
public class CourseCollection : CourseCollectionBase
{
///<summary>
/// Initializes a new instance of the <see cref="CourseCollection"/> class.
///</summary>
public CourseCollection()
{
}
}
///<summary>
/// This class is a strong typed collection of <see cref="Course"/> objects that inherits from the <see cref="CourseCollectionBase"/> class.
///</summary>
/// <remark>
/// This class contains specfic implementations that are not part of the CsTemplates framework.
/// </remark>
[Serializable]
public class CourseCollection : CourseCollectionBase
{
///<summary>
/// Initializes a new instance of the <see cref="CourseCollection"/> class.
///</summary>
public CourseCollection()
{
}
}
6.CourseCollectionBase的定义如下:已经很底层的。。。不再深究。。