Pages

Partial Classes

Partial Classes allow user to split the class file accross multiple source files. The benifit behind this approach is to hide the funtionality of the class. the same class can be created in may places and appropriate methods can be placed in the code file so that it derived classes can focus on significant part alone.

Interfaces

Interface are a type similar to class, where it cannot have the Method Content, rather it has the definition of Method. It will not have properties and members variables. The class which inherits the interface should implement all the methods of the interface. The interface forces the derived class to implement; otherwise it will not get compiled.

The below lists some of common interfaces of .Net
1. IComparable - Implemented by types whose value can be ordered, it is used for sorting.
2. Idisposable - Defines this method to dispose of an object manually, this is important most commonly used Interface when dealing with more big objects, and also to release the object which holds the resource like database.
3. IConvertible - Enables the class to base type such as string, int or bool.
4. IClonable - Supports object copying
5. IEquatable - Allows comparing to object instances.
6. IFormatable - Provides way to convert the value of object into a formatted string. This is similar to ToString() method, but provides greater flexibility than it.

Interfaces

Interface are a type similar to class, where it cannot have the Method Content, rather it has the definition of Method. it will not have properies and members variables. the class which inherits the interface should implement all the methods of the interface. the interface forces the derived class to implement, otherwise it will not get compiled. The below lists ome of common interfaces of .Net
1. IComparable - Implemented by ttypes whose value can be ordered, it is ued for sorting.
2. Idisposable - Defines this method to dispose of a object manually, this is important most commonly used Interface when dealing with more big objects, and also to release the object which holds the resource like database.
3. IConvertible - Enables the class to to base type such as string, int or bool.
4. IClonable - Supports object copying
5. IEquatable - Allows to compare to object instances.
6. IFormatable - Provides way to convert the value of object into an formatted string. This is similar to ToString() method, but provides greater flexibility than it.

Nullable type in .Net 2.0

Nullable type allows a varible to store null value, Infact this is the special about the type. The main purpose is it will add two members to the variable HasValue and Value Members. for example, if you store data for a yes/no question and if the user did not answer the question then null will be stored in that place. This means it stores True, False and third state nothing as null also. This will be represented as shown below.

In VB.Net,
Dim b as Nullable(Of Boolean) = Nothing
.....
If b.HasValue Then
Do if b has some value and not null
Else
Do if b is null
End If
In C#,
Nullable b = null;
Otherwise it can be used this way also, only applicable for C#,
bool? b = null;
.....
if (b.HasValue) {Do if it is not null} else {Do if it null}

Optimizing performance with built-in types .Net

The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables. For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.

ImageMap Control - ASP.Net 2.0

ImageMap is a New WebControl of ASP.Net 2.0. this is similar to the age old HTML control Map. This enables to set regions in a single image, and also sets a actions for that region. Means, if the region is clicked it will navigate to some other page or site, submits the page. A region can be created in Rectangle, polygan or in circle. The syntax is shown below with a Example.

<asp:ImageMap ID="ImageMap1" runat="server" HotSpotMode="PostBack" ImageUrl="~/Images/spaces.gif" OnClick="ImageMap1_Click" >
<asp:CircleHotSpot Radius="30" PostBackValue="Circle" AccessKey="c" AlternateText="some text" HotSpotMode="PostBack"
NavigateUrl="~/Trial.aspx" TabIndex="1" Target="_blank"/>
<asp:PolygonHotSpot Coordinates="0,0;0,30;30,30;30,0;" PostBackValue="Polygon" />
<asp:RectangleHotSpot Bottom="20" Right="20" PostBackValue="Rectangle" />
</asp:ImageMap>

protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
{
Response.Write(e.PostBackValue.ToString());
}


The Properties used in the controls are listed:

PostBackValue - this value can be retrived by the EventArgs of ImageMap Click Event(e.PostBackValue).
AccessKey - combination alt + Specified Key makes the event triggered.
AlternateText - text in the region specified if image is not available.
HotSpotMode - decides the behavior of the event, listed below are the description of this Mode
> NotSet - No HotSpot set
> Inactive - Region set and restricted to stop firing the event.
> Navigate - Navigates to the url set by the NavigateUrl property.
> PostBack - Submits the page with PostBackValue set, triggers the Click Event.
NavigateUrl - set to get navigated to the specified URL Value, when triggered.
Target - Open the redirected url in specified target(Like same window or new window).

Image Map supports three types of region specification. Apart from the properties, the HotSpot region specifies will have a shape oriented property like Circle has radius, x and y; Rectangle has top, left, bottom and right; polygan has coordinates. a single Image map can have any no. of HotSpot's in any combinations. if same region is mention twice then the priority goes for the first specified one. the HotSpot is basically a collection, all these propeties can be set by design mode also using Property Window.

The HotSpotMode can be set in Imagemap Tag, so that the same will be applicable for all, if required it can be specified in each individual HotSpot. The PostBackValue can be set for each HotSpot, that enable to identify the region get triggered, when HotSpotMode is PostBack. the EventArgs gives the PostBackValue.

ForEach File Enumerator

It is a Container element in control flow group in the SSIS. The container iterats through the object collection it belongs to. The ForEach File Enumerator iterates all files and directories in a specifies directory. Let us wal through that with an example.

.Create a new package.
.Drag and Drop the Foreach Loop Container from the Toolbar.
.Right Click, Edit the Container Properties.
.In General tab, set the name of the container

.In Collection Tab, set the Enumerator to Foreach File Enumerator. Set the Folder path to the required path. the Files field can be used to filter the type of files. the file name retrieval format can be set. suppose if the specified contains sub folders and if we want to check inside those folders also then check the "Traverse subfolders" Check Box.
.In Variable Mappings tab, Create a new variable, for example "Var" with datatype as string.

also set the index to 0, as the collection manipulates with one object in a loop cycle.

.The Container is set and ready to use, let us check the container using script task.
.Place a Script Task inside the Foreach Loop Container.
.Right Click, Edit the task.
.Goto to Script tab, and set the ReadOnly Variable Field with the variable used in the Foreach Loop. here set to "Var".

.Click Design Script from the Script tab, a new VS window environment opens with pre set already.
.Type the content, as given below in the existing function
Public Sub Main()
MsgBox(Dts.Variables("User::Var").Value.ToString())
Dts.TaskResult = Dts.Results.Success
End Sub

.Save it, close the environment and click OK in the container Property box.
.The sript task will be evaluvated on every loop cycle. the loop object is passed as a read only parameter for script task. the main functioin in the task displays the value stored in the variable. In this way we can do file or manipulation kind of task through the SSIS. when the package is runed, the files in the specfied folder are displayed as message box to the end user.