I as a beginner of Windows Foundation stuffs: Workflow, Communication, Presentation, have first read book about Windows Workflow Foundation: Pro WF Windows Workflow in .NET 3.5, author Bruce Bukivics.
The book easily gets me stuck in reading, so interesting. I finished reading 2 chapters and felt the eager to start on something the book says. The only ways to get things remember while reading is doing something practical: start programming in this case.
Can you guess what did happen when i create an WF project?? My VS2008 said: the syste failed to load this project type. It nearly killed me at a shoot. My normal process will be, ask my friend Google. However thing was not that easy. I spent many hours to look for the solution. Not much luck at that time. However i am lucky today.
The solution is quite simple 🙂 :
Open command line for VS, VS -> VS Tools -> Command promp.
Run: devenv /setup
Bravo it works, the source of solution can be reached here
As i mentioned in the previous post, i now start with my code base for stories of version 1.0. In general, it contains 3 layers as other software. Data access, Business, and Presentation. Let see what i have in my mind:
Data access: wow i can do all the stuffs with NHibernate. So just ignore it for now. I have tried NHibernate before, so it is not so difficult to get started.
Business layer: As you can see all user stories in this version. Simple, right? Yes, it is. So just build the objects i need first, however, no need to say them here.
Presentation: I want to keep it as simple as possible. However, it should be a rich web page which means that there is no real postback. Yeah THIS IS THING I TALK IN THIS POST.
AJAX! sure i should use AJAX to communication between client and server. The thing is which one? There are some options:
ADO with data service: implement as webserver when you want to ask something from server.
AjaxPro: Call method in the current page without posting back. I vote for this.
Basically, this technique was not new to me since in the company i have been working with a technique called ServerMethods, developed by our talent developers, except me. It has been there sine i went in. However, AjaxPro is much better which many types supported and it is constantly developed by the community, go in ajaxpro for more detail.
All you need to do to get it works is:
Add ajaxpro.dll into web reference.
Register type of class you are using ajaxpro.
And then call it from the client site.
Here what i did, simple:
Server side:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxPro;
using AnhDuc.BookStore.BusinessLayer;
namespace AnhDuc.BookStore
{
public partial class Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof (Default));
}
[AjaxMethod]
public Book GetResult(string searchKeyWord)
{
return new Book() {Name = searchKeyWord};
}
}
}
And from client side:
function startSearch() {
try {
var _book = AnhDuc.BookStore.Default.GetResult($("#_txtKeyname").val()).value;
alert(_book.Name);
}
catch (e) {
alert(e.message);
}
}
That’s enough! I am going to finish the user story 1 soon.
public static void CloseCurrentSession()
{
HttpContext context = HttpContext.Current;
ISession session = context.Items[CurrentSessionKey] as ISession;
if (session == null)
return;
session.Close();
context.Items.Remove(CurrentSessionKey);
}
public static void CloseSessionFactory()
{
if (_sessionFactory != null)
_sessionFactory.Close();
}
public static void CommitTransaction()
{
GetCurrentSession().Transaction.Commit();
}
public static void AbortTransaction()
{
GetCurrentSession().Transaction.Rollback();
}
}
It contains some methods to deal with transaction.
The configuration is done, and ready to use. Come to your business class.
Business classes:
They are all under AnhDuc.Blog,Business project. Each class has its own mapping file. All mapping files are put under hbm folder. I am not going to explain in detail about mapping here. However, it is the most important thing when you work with NHibernate.
Be aware of inheritance when designing your domain. In many cases, inheritance is not encouraged.
So far i have read many articles about web application development. So general speaking, i have tools in hand to build a website in no time with less effort. Just need to structure code and deal with business logic.
Here are some:
NHibernate: Deal with DataAccess layer and maybe more.
IoC, from Windsor, and Mock from Rhino deal with DI and Unit testing
jQuery to work with JavaScript
NUnit to test my code
That’s quite enough! However i have never interated them in one application at all. That’s why i am going to make a simple web application to demonstrate my understanding.
The web is about a blog site with:
List of categories on the left.
Click on one category, then list out all blogs in that category in short.
Click on one blog item, then the detail is displayed
Assuming that, all data will be added into DB directly. What i want to archive are:
Of course, the system works
Easy to extend, since i will add administrative functions later: Add, Edit, Delete,…
Easy to maintain code.
Apply all the things i have known so far, those i list above.
Along with the development process, i will update my blog. I am sure there will be more fun while doing it, yeah with difficulties as well.