Thursday 28 February 2008

Using subst to create virtual drives

If you wish to create virtual drives from the command line you can use subst. Have a look at the code below:

subst /d a:
subst /d b:
subst a: F:\Development\SVN\trunk\CompiledBinaries
subst b: a:\release

This will create 2 virtual drives one called 'a' the other 'b', which in turn point to 'F:\Development\SVN\trunk\CompiledBinaries' and 'a:\release' respectively.

Wednesday 27 February 2008

HTTP Refresh

This is the syntax used automatically refresh a current page:

meta equiv="refresh" content="600"

content="600" - Time to refresh in seconds.

If you want to redirect to another page try this:

meta equiv="refresh" content="600;url=http://webdesign.about.com"

Monday 25 February 2008

Regualr expression for alpha-numeric characters only

Below is the regular expression that will match only alphanumeric characters and restrict the length between 4-11 characters:

^\w{4,11}$

This will restrict the first three characters from being "bTv" (case sensitive):

^(?!bTv)[A-Za-z0-9]+$

Sunday 24 February 2008

Delegate in C#

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.


List members = new List();
members.Sort(delegate(IFolderExplorerHierarchyMember member1, IFolderExplorerHierarchyMember member2)
{
return member1.Name.CompareTo(member2.Name);
});


Brilliant article: http://www.c-sharpcorner.com/UploadFile/arulchinnappan/Delegate_109152005080029AM/Delegate_1.aspx?ArticleID=42f8981b-72d2-441f-a95f-48dcbb93dbf5

A delegate can hold reference/s to one more more functions and invoke them as and when needed.

A delegate needs the method's name and its parameters (input and output variables) when we create a delegate. But delegate is not a standalone construction. it's a class. Any delegate is inherited from base delegate class of .NET class library when it is declared. This can be from either of the two classes from System.Delegate or System.MulticastDelegate.

If the delegate contains a return type of void, then it is automatically aliased to the type of System.MulticastDelegate. This can support multiple functions with a += operator. If the delegate contains a non-void return type then it is aliased to System.Delegate class and it cannot support multiple methods.

Source: http://www.codersource.net/csharp_delegates_events.html

Wednesday 20 February 2008

Partial Classes

It is possible to split the definition of a class or a struct, or an interface over two or more source files. Each source file contains a section of the class definition, and all parts are combined when the application is compiled. There are several situations when splitting a class definition is desirable:

When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.
When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.
To split a class definition, use the partial keyword modifier, as shown below:

public partial class Employee
{
public void DoWork() { }
}
public partial class Employee
{
public void GoToLunch() { }
}

Source: http://msdn2.microsoft.com/en-us/library/wa80x488(VS.80).aspx

Tuesday 19 February 2008

MVC vs. MVP

Source: http://www.darronschall.com/weblog/archives/000113.cfm

By now you should've heard of the Model-View-Controller design pattern. If you've read OOP with ActionScript by Branden and Sam then you're also somewhat familiar with the Model-View-Presenter design pattern. So what's the difference?

MVC came first. With the MVC pattern it's possible to separate your presentation information from your behind the scenes business logic. Think along the lines of XHTML/CSS and separating your content from your presentation. A brilliant concept that works quite well, but is not without it's faults.

In MVC, the model stores the data, the view is a representation of that data, and the controller allows the user to change the data. When the data is changed, all views are notified of the change and they can update themselves as necessary (think EventDispatcher).
MVP is a derivative of MVC, mostly aimed at addressing the "Application Model" portion of MVC and focusing around the observer implementation in the MVC triad. Instead of a Controller, we now have a Presenter, but the basic idea remains the same - the model stores the data, the view is a representation of that data (not necessarily graphical), and the presenter coordinates the application.

In MVP the Presenter gets some extra power. It's purpose is to interpret events and perform any sort of logic necessary to map them to the proper commands to manipulate the model in the intended fashion. Most of the code dealing with how the user interface works is coded into the Presenter, making it much like the "Application Model" in the MVC approach. The Presenter is then directly linked to the View so the two can function together "mo' betta".

Basically, in MVP there is no Application Model middle-man since the Presenter assumes this functionality. Additionally, the View in MVP is responsible for handling the UI events (like mouseDown, keyDown, etc), which used to be the Controllers job, and the Model becomes strictly a Domain Model.

XSD Null values Problem

Source: http://www.socalmp.com/blog/template_permalink.asp?id=91

For columns not defined as System.String, the only valid value is (Throw exception)

For handeling NULLS in a typed DataSet there are several solutions which are all combersome if the datatype is anything other than a string.
In Visual Studio once you define the typed dataset you can adjust the properties of the column values by clicking on the column in the .xsd GUI.

This allows you to set the datatype and how to handle NullValue. If the datatype is System.String then you can change the NullValue to empty(""), null(DBNull) or throw exception. The exception displays an ugly error message in the browser and provides little information on how to correct the issue. (The value for column '*' in table '*' is DBNull) or (System.InvalidCastException: Specified cast is not valid.)

If your datatype is INT, Decimal, etc.. you have to use error handeling in the script to workaround this issue. Ideally you would expect MS VS2005 to allow you to set the null value to (0), (0m), etc... but that bug is still not fixed.
Some blogs suggest to change the .cs file to set the value using an if statement. That will work but it will also get overwritten wehn you uspdate the file with another dataset.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=174108&SiteID=1

Fortunately when the Typed Dataset was created it generated a method to return a boolean value if the column data was Null.


foreach (BedroomTvRecord.SelectBedroomTvRecordRow row in table)
{
BedroomTv record = new BedroomTv();
record.Biography = row.AboutMe;
record.Country = row.Country;
record.DateOfBirth = row.IsDOBNull() ? (DateTime?)null : row.DOB;
record.Email = row.Email;
record.FirstName = row.FirstName;
record.LastName = row.LastName;
record.MemberId = row.MemberID;
record.PhoneNumber = row.MobileNumber;
record.Thumbnail = row.ThumbnailImage;
record.Username = row.Username;
list.Add(record);
}

Model View Presenter (MVP)

A must read about the MVP pattern: http://www.codeproject.com/KB/aspnet/MVP_in_ASPNET.aspx

Monday 18 February 2008

Anonymous Functions

Source: http://en.csharp-online.net/FSharp_Functional_Programming%E2%80%94Anonymous_Functions
and
http://novemberborn.net/sifr/explained/terminology

Anonymous Functions are used when it is not necessary to give a name to a function, so these are referred to as anonymous functions and sometimes called lambda functions or even just lambdas.

function(msg){ alert(msg); }("hello world");

Thursday 14 February 2008

Firefox XSL transform not rendering

Source: http://ajaxandxml.blogspot.com/2007/01/firefox-html-dom-fails-if-local-xsl.html

Firefox: HTML DOM fails if a local XSL transformation does not specify xsl:output

This nasty beast took me a while to figure out: if you do local XSL transforms in Firefox 1.5 and don't have the xsl:output directive in your main XSL stylesheet, HTML-specific DOM calls might not work.

The results are weird: for example, whatever is produced with the XSL transformation behaves like a HTML DOM object, but if you create a new element, it lacks HTML-specific DOM calls.And the obvious solution: make sure you're always including ...


... in your XSL stylesheet.

What is Boxing and UnBoxing?

Source: http://aspalliance.com/986_Boxing_and_Unboxing_in_NET.all

Boxing and Unboxing are two important portions of .NET technology. Many of the developers are not really aware of it, but it is really needed if somebody is interested in enhancing the performance of the application developed.

In a very brief way, one can say that Boxing is nothing but converting a value type object to a reference type object. Unboxing is completely explicit. The idea will be clearer after discussing the example given below. This example shows how an integer type is converted to a reference type using the boxing and then unboxed from the object type to the integer type.

class Test
{
static void Main()
{
int i = 1; // i is an integer. It is a value type variable.
object o = i;
// boxing is happening. The integer type is parsed to //object type
int j = (int)o;
// unboxing is happening. The object type is unboxed to //the value type
}
}

In the above example, it is shown how an int value can be converted to an object and back again to an int. This example shows both boxing and unboxing. When a variable of a value type needs to be converted to a reference type, an object box is allocated to hold the value and the value is copied into the box.

Unboxing is just the opposite. When an object box is cast back to its original value type, the value is copied out of the box and into the appropriate storage location.

Using Transformations to Restructure XML Data

Good article on transforming XML with XSL and how to display it within an ASPX page.

http://msdn2.microsoft.com/en-us/library/13ftcwy9.aspx

Wednesday 13 February 2008

Brushing up on interview questions

What is the difference between clustered and nonclustered indexes?

There are clustered and nonclustered indexes. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Abstract and Sealed keywords
The abstract keyword enables you to create classes and class members solely for the purpose of inheritance. The classes, which we can't initialize, are known as abstract classes. They provide only partial implementations. But another class can inherit from an abstract class and can create their instances.

The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.

Virtual keyword
The virtual keyword is used to modify a method, property, indexer, or event declaration and allow for it to be overridden in a derived class

Structs vs Classes
Structs are value types, unlike classes they do not require heap allocation. Also, as value types they cannot be derived from. Structs can implement an interface.

Early vs Late Binding
Early binding is when your client app can detect at compile time what object a property or method belongs to. Since it "knows", it resolves the references and the compiled executable contains only the code to invoke the object's properties, methods, events, etc.

This is a good thing if you want to speed because the call overhead is greatly reduced.

Late binding is the slowest way to invoke the properties and methods of an object. You use late binding when you write a function that uses an object variable that acts on any of several different class objects. Since the compiler doesn't "know" what class object will be assigned to the variable, it doesn't resolve the references into the compiled executable. In this case they are resolved at runtime... when you actually have an assigned object to reference the properties and methods to.

No Page_PreInit event in MasterPage

There is not PreInit event in the MasterPage.MasterPage actualy is a UserControl which dosen't has PreInit.

Adding method Page_PreInit doesn't also mean that there is an event named PreInit on masterpage. to prove that, try to add:protected override OnPreInit(...), the compiler will not accept it.

To solve your issue, I suggest to create class Named BasePage or what ever which inherits from System.Web.UI.Page. Make all your Pages Inherits from it. and add your Page_PreInit on it, then set your MaterPage in this event.

Thanks to Muhammad Mosa: http://www.velocityreviews.com/forums/t362567-pagepreinit-no-execute-in-masterpage.html

HTTPModules and the HTTP Pipeline

Great article: http://msdn.microsoft.com/msdnmag/issues/02/05/asp/

Subversion OpenSource Tool like TFS

This is a very cool tool that integrates into Visual Studio solution explorer and provides TFS-like integration. Its called AnkhSVN.

Info: http://ankhsvn.tigris.org/
Download: http://ankhsvn.tigris.org/files/documents/764/39523/AnkhSetup-1.0.2.2778-Final.msi

Tuesday 12 February 2008

Windows Workflow Foundation

Windows Workflow Foundation is a part of the .NET Framework 3.0 (and 3.5) that enables developers to create workflow enabled applications. It consists of the following parts:

Activity Model: Activities are the building blocks of workflow, think of them as a unit of work that needs to be executed. Activities are easy to create, either from writing code or by composing them from other activities. Out of the box, there are a set of activities provided that mainly provide structure, such as parallel execution, if/else, call web service.

Workflow Designer: This is the design surface that you see within Visual Studio, and it allows for the graphical composition of workflows, by placing activities within the workflow model. You can find a screenshot of designing a sequential workflow here. One interesting feature of the designer is that it can be re-hosted within any Windows Forms application. Check out this article on MSDN to see how you can do this. http://wf.netfx3.com/files/folders/design_time/entry1923.aspx

Workflow Runtime: Our runtime is a light-weight and extensible engine that executes the activites which make up a workflow. The runtime is hosted within any .NET process, enabling developers to bring workflow to anything from a Windows Forms application to an ASP.NET web site or a Windows Service.

Rules Engine: Windows Workflow Foundation has a rules engine which enables declarative, rule-based development for workflows and any .NET application to use.

Here is an article which outlines the capabilities of the rules engine. http://msdn2.microsoft.com/en-us/library/aa480193.aspx

Windows Workflow Foundation will be released as part of the .NET Framework 3.0 which is part of the Windows Vista release. The .NET Framework 3.0 will be available for Windows XP as well as Windows Server 2003. In the .NET Framework 3.5, WF receives an additive update in the form of integration with Windows Communication Foundation

Source: http://netfx3.com/content/WFHome.aspx

Great code example: http://community.bartdesmet.net/blogs/bart/archive/2006/08/27/4278.aspx

WCF Simple Example

Nice simple WCF example to get started with.

Please view: http://bloggingabout.net/blogs/dennis/archive/2007/04/21/wcf-simple-example.aspx

XSL Summary

XSL = XML Style Sheets

XML does not use predefined tags (we can use any tag-names we like), and the meaning of these tags are not well understood.

A table element could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.

XSL describes how the XML document should be displayed!

XSL - More Than a Style Sheet Language

XSL consists of three parts:
  • XSLT - a language for transforming XML documents
  • XPath - a language for navigating in XML documents
  • XSL-FO - a language for formatting XML documents

Source: http://www.w3schools.com/xsl/xsl_languages.asp

Monday 11 February 2008

KoolWire

This is a nice utility to convert files into common formats: http://www.webware.com/8301-1_109-9867524-2.html

Friday 8 February 2008

What is NHibernate?

This article explains everything: http://www.developer.com/net/asp/article.php/10917_3709346_1

Extending the DropDownList to Support Enums

This is a great article on how to bind enums to a dropdownlist. Here is the link: http://aspalliance.com/1514_Extending_the_DropDownList_to_Support_Enums.1

Assembly version and file version

Here is an extract from http://support.microsoft.com/kb/556041 regarding file vs assembly versions.

How to use Assembly Version and Assembly File Version
.NET framework provides opportunity to set two different types of version numbers to each assembly.

Assembly Version :
This is the version number used by framework during build and at runtime to locate, link and load the assemblies. When you add reference to any assembly in your project, it is this version number which gets embedded. At runtime, CLR looks for assembly with this version number to load. But remember this version is used along with name, public key token and culture information only if the assemblies are strong-named signed. If assemblies are not strong-named signed, only file names are used for loading.

Assembly File Version :
This is the version number given to file as in file system. It is displayed by Windows Explorer. Its never used by .NET framework or runtime for referencing.

Attributes in AssemblyInfo.cs
// Version information for an assembly consists of the following four values:
// Major Version
// Minor Version
// Build Number
// Revision
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Providing a (*) in place of absolute number makes compiler increase the number by one every time you build.

Suppose you are building a framework assembly for your project which is used by lot of developers while building the application assemblies. If you release new version of assembly very frequently, say once every day, and if assemblies are strong named, Developers will have to change the reference every time you release new assembly. This can be quite cumbersome and may lead to wrong references also. A better option in such closed group and volatile scenarios would be to fix he 'Assembly Version' and change only the 'Assembly File Version'. Use the assembly file version number to communicate the latest release of assembly. In this case, developers will not have to change the references and they can simply overwrite the assembly in reference path. In central/final release builds it makes more sense to change the 'Assembly Version' and most keep the 'Assembly File Version' same as assembly version.

Wednesday 6 February 2008

What is a Greenfield Project?

In software engineering jargon , a greenfield is a project which lacks any constraints imposed by prior work. The image is that of construction on greenfield land, where there is no need to remodel or demolish an existing structure. Such projects are often coveted by software engineers for this reason, but in practice, they can be quite rare.

See link: http://amolsledge.blogspot.com/2007/08/greenfield-project.html

ASP.NET Design Patterns

This article gives a great overview of the many design patterns available: http://www.devx.com/dotnet/Article/33695

Tuesday 5 February 2008

Nice run through of TDD (Test Driven Development)

This is from the MSDN magazine showing extreme programming and TDD. Interesting.

Please use this link: http://msdn.microsoft.com/msdnmag/issues/04/04/ExtremeProgramming/

Another good article can be found here:

http://aspnet.4guysfromrolla.com/articles/011905-1.aspx

MVC Example

Great example for implementing a MVC. Have a look at this link: http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx

10 ASP.NET Performance Tweaks

Interesting article to improve performance on ASP.NET applications.

Please follow this link: http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx

Monday 4 February 2008

ASP.NET Membership and Roles

This is an interesting article outlining the membership and role management provided in .NET 2.0.

Please click on this link: http://www.asp.net/learn/moving-to-asp.net-2.0/module-08.aspx