Thursday, June 29, 2006

Hello!

Long time no posted new post to the blog regarding the hard work on Tigers project at work, but while programming and programming, I encoutered with new asp.net 2.0 Page property that called Previous Page.
This property holds all the web controls with its data and infromation of the previous page of the current page that you are in.

I found this property very useful and it can do you 'Easy Life' while getting data from the previous page that you came from (or the user that uses your application).

For example: suppose you want to use specific information from the page that you are just have been redirected from, like search term text. In the 'old fasioned' way, you needed to save this data in the Session variable or to send it by the query string of the url address and it will be expose to everyone, but PreviousPage property comes to avoid this ways by saving all the previous page data by looking for the specific control that holds the data, For example:

if (Page.PreviousPage != null)
{
   if (Page.PreviousPage.FindControl("txtSearchTerm") != null)
   {
      string term = ((TextBox)Page.PreviousPage.FindControl("txtSearchTerm")).Text;

      //do your thing with this data...
   }
}

Here I checked if there is a previous page and if it contains the txtSearchTerm Textbox controls, grab its data and use it.

Is it nice or not?

Posted by: Eran Nachum (c)
Post Date: 6/29/2006 7:38:26 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [2] | Trackback   #
 Tuesday, June 20, 2006

This post refers to all of you that holds a personal site or administrates sites and wants to know some analytics and statitctics about site fraffic.

Google (the amazing...) came out with very sophisticated site analytics tool that can tell you "everything you want to know about how your visitors found you and how they interact with your site. You'll be able to focus your marketing resources on campaigns and initiatives, and improve your site to convert more visitors" (Google's qoute).

I had very impressed, initially, of the user's interface graphic design and the diverse statistic summaries, and the most valuable thing here is that, this is very easy to implement - you need to add small script to your site and that's it!!!

For more info you can try it here. I already inserted the script code on my differents sites.

Bye for now...

Posted by: Eran Nachum (c)
Post Date: 6/20/2006 7:51:25 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [2] | Trackback   #
 Monday, June 19, 2006

Hey all!

While developing the Data Access Layer (DAL) in my "home developing" project - Haverut.co.il I deliberated wheather to use the old fashioned way - the Application Blocks of Microsoft, which I need to implement all the database contact by hand and use the 'jacket' of the Application Blocks adapters OR to use Typed datasets...
I decided to use the second choice, because (as knows) this module knows to generate code of database tables and to create by default the main CRUD (Create, Read, Update and Delete) methods and also custom SQL queries.

But this is not the main issue of this post...

While working, I needed to do several connected commands against the database, therefore I needed to use the Transaction term to knot these commands and to avoid database's commands failure or 'half-way actions'.

Now, the biggest deliberation: To use SQLTransction module or TransactionScope module (which is new module that cane out in .NET 2.0)?

In the first thought I decided to use TransactionScope, because it's very easy to use and it doesn't make "pain in the neck". The usage it easy: you need to wrap the wanted scope with this module and all the job will be done safely under this transaction.
further documentation you can find here:

But this module holds not much of disadvantages like:

  • Low performence of this action in the application, in large amount of users and actions the performance of this actions will be very bad and slow.
  • By default, when using this module, the system tries to look for a transaction that is otherwise current, or a TransactionScope object that dictates that Current (a static property of this namespace) is null. If it cannot find either one of these, System.Transactions queries the COM+ context for a transaction. Note that even though System.Transactions may find a transaction from the COM+ context, it still favors transactions that are native to System.Transactions. This thing is not recommended because we need to handle the COM+ context in addition to our application context. More info you can find here.

Because of that, I decided to use SQLTransactions over my Typed Datasets' actions.

To do this in appropriate way, I used a partial class (very nice innovation in .NET 2.0) with the same name of the Typed DS class, to 'continue' its code and overload some of the members like the main member that does the connection with the database: _adapter.
This member is private and is not accessible to outside requests.

Instead of a BeginTransaction method, I have implemented a Transaction property on my TableAdapters, like this:

partial class CitiesTableAdapter
{
   public SqlTransaction Transaction
   {
      get { return _adapter.SelectCommand.Transaction; }
      set
      {
         if (_adapter == null)
         {
            InitAdapter();
         }

         _adapter.InsertCommand.Transaction = value;
         _adapter.UpdateCommand.Transaction = value;
         _adapter.DeleteCommand.Transaction = value;
      }
   }
}

This property assigns the given transaction to the Transaction property on all its commands. Now I can do CRUD method as I like with knowing that is under SQLTransaction control:

CitiesTableAdapter citiesAdapter = new CitiesTableAdapter();

citiesAdapter.Connection.Open();
try
{
   SqlTransaction trans = citiesAdapter.Connection.BeginTransaction();
   try
   {
      citiesAdapter.Transaction = trans;

      // CRUD the table, commit transaction or rollback if there's a problem

 

Nice way of implementing, hope it helped someone...

See you

Posted by: Eran Nachum (c)
Post Date: 6/19/2006 8:46:54 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [1] | Trackback   #
 Thursday, June 15, 2006

Hello!

Today my blog has ranked on google for the first time, everything is a result of good SEO (Search Engines Optimization) actions on my web site..

Try to find me :)

Posted by: Eran Nachum (c)
Post Date: 6/15/2006 2:35:13 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [3] | Trackback   #
 Wednesday, June 14, 2006

While searching for new features and products from Microsoft's breeding ground, I discussed with my team leader Egozi, about nice advanced graphical editor that will be easy to use (not like professional editors and studios like: Photo Shop or FreeHand etc...) to design simple and well graphically designed web controls, like buttons, tabs, tables, grids and more... I wanted a nice graphical editor to create the above controls to be well designed and interactive for my private 'developing at home' application - Haverut.co.il.

He introduced me the Microsoft Expression tool (or product, call it whatever you like...). This product is still in BETA version but it works fine (for the most features I've tried).
The Product contains 3 tools:

  • Graphic Designer
  • Interactive Designer
  • Web Designer

I will focus on the Web Designer CTP1 (Community Technologhy Tool)!
This tool is very easy to use and supplies you greater flexibility to create sophisticated applications and contents. It contains nice code editor, that enables you to write code easily (with extended and comprehensive intellisense), sophisticaed CSS-based layouts, rich data presentation and more.

I played a little bit with that and created nice designed interactive button, that on hover and on click changes its color and design.

The regular design of the button:
The on mouse over design of the button:
The on mouse click design of the button:

And the coolest thing with this button creation is that you don't need to upload images or to create the javascript methods and CSS layouts, you design the button only with the graphical designer and saves the content - the tool generates the code automaticlly and creates the GIF or JPEG files and CSS code.

So go and download this, just play with it from: http://www.microsoft.com/products/expression/en/default.mspx

Bye for now...

Posted by: Eran Nachum (c)
Post Date: 6/14/2006 8:45:41 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [0] | Trackback   #
 Monday, June 12, 2006

Hi!

Yeasterday, while working on a big web application project, I wanted to copy System.Collections.Generic.Dictionary<TKey, TValue>'s values to a System.Collections.Generic.List<TValue>.

Instead running a loop over the Dictionary<T, K> and copy its values to the List<T>, I used the AddRange(TValues) method.
For example:

Dictionary<int, Job> myDictioanry = new Dictionary<int, Job>();

//Fill the Dictionary...

List<Job> listJobs = new List<Job>();
listJobs.AddRange(myDictioanry.Values);

Hope it will help someone...
see you later

Posted by: Eran Nachum (c)
Post Date: 6/12/2006 8:01:28 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [3] | Trackback   #
 Thursday, June 08, 2006

I am developing from this month a new web application project, and I think this will be one of the best *** sites on the web (*** means that the plan is still secret). The site will be called Haverut and it will be hosted on: www.haverut.co.il or www.haverut.com.

Now, as you know (or not), Microsoft has a nice Custom Membership and Roles Providers that generates very comfortable SQL Server database to work with and very comprehensive API to communicate with that enable you to manage all the membership and roles issue.

In my first thought, I was planing to build the pilot of my application to work with MS Access database, and ofcourse I wanted to use the Custom Membership and Roles Providers that Microsot supplies. After long searches on the web I found a msi file (you can dowload it here) that after you install it on your machine, it opens you a new template possibility in VS 2005 that called 'ASP.NET Access Providers'. This template generates you automaticly the Access database with all its tables and queries.

But, on the second thought I decided to build the database on SQL Server from the begining (much more secure and efficient).  

A very good acticle and tutorials references you can find at Scott Guthrie's blog at: http://weblogs.asp.net/scottgu/archive/2006/02/24/438953.aspx

See you...

(P.S. - If I didn't mentioned, the Custom Membership and Roles Providers is exist in the first place for SQL Server and you can activate with the aspnet_reqsql  command from the Visual Studio 2005 Command Prompt).

Posted by: Eran Nachum (c)
Post Date: 6/8/2006 8:13:15 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [1] | Trackback   #
 Tuesday, June 06, 2006

Yesterday noon, in a middle of our department's technical conversation, I raised the issue of the difference between IHttpHandler and IHttpModule models, because I'm using an IHttpHandler logic model in a part of the application I working on.

Also I want to clarify OrenEllenbogen's (one of our team leaderes) findings. He claims, correctly, that the clothing of an application (Global.asax) is the IHttpModule that "hosts" several IHttpHandlers. Now, by the specific request that goes through the IHttpModule firstly, it knows to navigate it to the specific handler (IHttpHandler) to handle it.

Here, I want to go into details about those two nice and essential models.

HttpHandler - Every typical page (that derives from System.Web.UI.Page) implements the IHttpHandler interface. Writing an IHttpHandler is no different that writing typical page or control. It includes server application objects like: Session, Request and Response. An HttpHandler is created for each request to the server and its lifetime exists on the request ProcessRequest step. (It important to mention that this action happens before the page events are raised (like Page_Init, Page_Load etc...)

Another thing to know about HttpHandler behavior is the IsReusable property that defined in the interface. If this retured as true, the HttpHandler won't be destroyed when a control exits ProcessRequest - it will be released to the pool for future requestor. This means that request specific data must be de-initialized at the end of the request, or re-initialized at the begining of a request.

Nice example of use is Url Rewriting. We used a handler in previous a web application development that handles multi-lingual states (supports English and Hebrew languages). We wrote an HttpHandler that in every request to the server, checks the browser url, and by a specific address symbols "guides" the page what language adn direction to display.

HttpModule - The HttpModule is the filter for all requests. It receives notification at various processing points during the lifespan of the request. We can map HttpModule to all application requets.

The main difference between HttpModule to HttpHandler is that HttpModule provides class intance for all application's requests and HttpHandler provides single instance for each request. Also, HttpModule doesn't store any data about any request because it handles all the application requests, opposite to HttpHandler that can store data about a specific request (IsReuseable property, remember...?)

An important adventage of HttpModule over HttpHandler is by the initializing and maintain an application state option, since there is alive class intance all along the application lifespan. For example, you can load a data structure (like XML string for example) in the Init method and use it safely accross the apllication lifespan.

Hope I answered some questions (if you had some...)

A nice implementation example you can find in MSDN or here.

 

Posted by: Eran Nachum (c)
Post Date: 6/6/2006 9:29:29 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | Comments [5] | Trackback   #