Sunday, May 25, 2008

Stack and Heap in .Net Framework

Stack and Heap
While a program is running, its data must be stored in a memory. How much memory is required for an item, and where and how it is stored, depends on it type
A running program uses two regions of memory to store data. They are usually known as stack and heap.

Stack
System takes cares of all stack manipulation. As a programmer you need to worry about stack explicitly
But understanding stack will give a better hand on the way of programming. So it will help you to understand C# literature.. ( oops what a name ‘C# literature’.. ;) )
Stack is an array of memory that acts as a last-in, first-out (LIFO) data structure. Usually we store several kinds of data
· The values of certain types of variables
· The program’s current execution environment
· Parameters passed to methods

  • Additional Facts
    · Data can be added to and deleted from the top of the stack
    · Placing a data item at the top of the stack is called pushing item to the stack
    · Deleting an item from the top of the stack is called popping the item from the stack

Data items pushed on the top of the stack and popped from the top of the stack.

Pushing an integer “333” on the top of the stack moves the top of the stack up.

Heap
Heap is an area where chunks of memory can be allocated to store certain kinds of data.
No it’s not similar to Stack…
Unlike Stack, memory can be allocated and deallocated from heap in any order.

Theoretically we can say like that. Although our program can allocate memory from the heap, it cannot deallocate it. Instead the CLR’s Garbage Collector (GC) automatically cleans up orphaned heap objects when it determines that your code will no longer access them. This frees us from what in other programming languages can be an error-prone task.

This program has three allocated memory objects in the heap.

Later, one of this memory object is no longer used by the program.

The Garbage Collector (in .NET framework) finds the orphaned memory object


After garbage collection, the object’s memory has been released back to the heap

well that gives an idea of what stack and heap is...

Sunday, May 4, 2008

Basics of C# programming

Hmmm... Nobody likes hearing theory for long time… just taking a break…

Lets overview some sample codes.

To start with let’s see the structure of a basic C# program. Even if don’t catch up the code, just understand the terms, so that I can use those terms in explaining codes in detail.

Note I use Visual Studio 2008, with a black theme for Coding. (I don’t like the normal white background for many reasons… )

See this code.



The Output of this program will be like this. (Note this is just a simple program with Console output.)


Ok I will explain each line.



Line 1: using System;


  • This tells the compiler that this program uses types from the System namespace. This is a default namespace in .Net. I used this for getting the function WriteLine()


Line 2 : namespace SampleCodeBlogspot

  • I declared a new namespace for my program called SampleCodeBlogspot. Note that after declaring namespace, I put curly braces { }.


Line 4: class testApp



  • Declared a new class type for my program as testApp. Any members declared after this class inside curly braces, will automatically becomes members of this class.


Line 6 : static void Main()


  • In my program, Main is the only member of the testApp class.

  • Main is a special function used by the compiler as the starting point of the program.


Line 8 : Console.WriteLine(" Hello, this is from Midhun's Blogspot.");


  • My programs have only a simple statement which uses the Class Console in the namespace System, to print out the message to a window on the screen.

Note:

  • A C# program consists of one or more type declaration . In my sample program I have only one type. class testApp set

  • A namespace is a set of type declarations associated with a name. This sample Program creates a new namespace called SampleCodeBlogspot and uses a predefined namespace called System

  • Every C# program must have one class with a method ( or known as Function ) called Main. The starting point of execution of every C# program is at the first instruction in Main.

  • A statement is a source code instruction describing a type or telling program to perform an action. A simple statement is always terminated by a semi colon.

    • Console.WriteLine(" Hello.");

Well.. We can start off like this. Let’s see more in the next blog..

Wednesday, April 30, 2008

Some basics of Microsoft .NET - Part 02

Features of .Net explained…

· Object Oriented Development Environment.
· Automatic Garbage collection
· Interoperability
· No COM Required
· Simplified Deployment
· Type Safety

Object Oriented Development Environment.


Basic Components of .Net ( CLR, BCL, and Programming Languages like C# or VB) all are perfectly designed to work in a well integrated Object oriented environment. One of the keen feature of .Net framework is its consistent Object oriented programming model.

What surprised me is that, it even provide a wide range of platform target. You can write a web application or windows application which can work from high end servers to a Cell phone.
Who else will give such a broad range ?? :)

Automatic Garbage collection

If you are C++ or C programmer you will feel relief now… CLR has a tool called Garbage Collector which automatically manages memory. Well its like a memory watcher but does more.

Garbage collector deletes all objects from memory which is no longer accessed in the program. ( means less effort in memory management of your application)

As I told earlier, if you are traditional programmer, you will be hunting for all kinds of memory leaks and will be reallocating those memories. Well this is not a small feature, believe me it’s a time taking task to find out the memory leak issues… In these cases Garbage collector is a great pain reliever .. :D


Interoperability


Interoperability, I guess this will be one among the most good feature that attracted many programmers. .Net Framework is designed to work with different .Net languages , different OS and different COM components.

Recently I read a whitepaper from Microsoft, it says .Net framework will soon support programming languages like Python and Ruby. Means it will become DLR ( dynamic Language Runtime environment).

.Net even allows to inherit from a class written in another . Net language ( as long as certain rules are followed ).

Platform invoke feature ( managed code) allows code written in .Net to call and use code which were not written for .Net , such as win32 system calls.

Are you a MFC coder ? or does your current programs uses lot of COM components ?
No worries… .Net framework allows interoperability with COM. Means .Net components can call a COM component and COM component can call .NET components.


No COM Required
.Net framework will free you from the bondage of COM legacy. Since you will not need any of the following as in COM programming ( following are familiar for COM programmers… others just pass on J )

o IUnknown interface :
§ In COM all objects must implement the interface IUnknown.
§ All .Net objects are derived from a single class known as Object. Interface programming is never a central theme any more.
o Reference Counting :
§ Programmer no longer has to keep count of references to objects. Garbage collector keeps track of all references and it removes the inappropriate objects.

o HRESULT :
§ Atleast some of you might have seen this word. It shows up when errors occur in COM. HRESULT data type is used for returning runtime error codes.
§ In .Net its no longer used, instead all runtime errors produces exceptions. And of course, we can handle all these exceptions in the code.

o Registry settings:
§ If you have developed any application and deployed using any other .Net languages, you knows the headache that comes with registry.
§ .Net simplifies the deployment ( both installation and removal) of programs , not using operating system configurations or application configurations in the registry.
Simplified Deployment


Oops.. I have to tell the same thing here.. “.Net simplifies deployment because it seldom uses registry settings. ”
One good advantage is the side-by-side execution of different versions of a DLL. Earlier DLLs were used based on their names. But .Net applications uses only that DLL for which it was built.
Type Safety


Its CLR again.. CLR checks for type safety of parameters and data objects used in .NET


An overview:
Well, I will give you an overview of Compilation and Execution process in .Net.



Compilation and Execution process is same regardless of the Language of the original Source file.

Hmmm… two type of compilations.. CIL and Native code compilations… will explain more later…

Monday, April 28, 2008

Some basics of Microsoft .NET - Part 1

Some basics of Microsoft .NET
Microsoft.net is out since 2002… may be too late to mention basics now… but still it interesting to have an overview of what we learned.

.Net Framework is a much more consistent and object-oriented environment than either the MFC or COM programming technologies. In short we can say it has three basic features..
· Multiple platform: .Net Framework runs on a broad range of computers, from servers and desktop machines to PDAs and cell phones.
· Industry standards: The system uses industry standard communication protocols, such as XML, HTTP, SOAP, and WSDL.
· Security: The system can provide a much safer execution environment, even in the presence of code obtained from suspect sources.

.Net Framework mainly have three main components.


Main execution environment is known as CLR ( common Runtime Environment). CLR manages program execution at run time, and also it includes the following.
1. Memory management
2. Code safety verification
3. Garbage Collection
4. And Finally code execution

Programming tools is nothing but the tool used for making programs. It will be Visual Studio IDE for most cases. These tools also include debuggers, compliers etc.

The Base Class Library ( BCL) is a large class of Library used by .NET framework and which is used in .Net programming.

What are the benefits of using .NET Framework ?
Yes , since you have lot of platforms available that question is natural. .Net Framework is definitely an improved Programming environment.

Following are its features:
Object Oriented Development Environment.
Automatic Garbage collection
Interoperability
No COM Required
Simplified Deployment
Type Safety


Hmmm..
That’s for now… time is limiting to write more.. will update this blog next day..

Sunday, April 20, 2008

ASP.NET 3.5 - Anatomy ( for beginners)

ASP.Net 3.5
ASP.NET 3.5 is the next milestone in the evolution of Microsoft's ASP.NEt Platform. This time, this verison features AJAX, integration with the windows communication Foundation ( WCF ) service platform, Language INtegrated Query ( LINQ ) support and a few new server controls to fill existing functional gaps...

For Beginners:
What is ASP.NET?
Before asp.net, there were three main technologies and platforms for web development.
  1. ASP
  2. JSP
  3. LAMP ( open source web platform : Linux plus Apache plus MySQL plus either Perl, Python or PHP as the programming language)

Although each has a language-specific or platform specific features, all these were web development platforms designed to create interactive web pages rather than the lifeless simple HTML pages.

Like other web development environment ASP.NET also works on the top of HTTP protocol. But what differentiate it from other web development technologies is its abstract programming models.... ( the web forms model )

In addition the whole ASP.NET platform comes as part of Microsoft .NET Framework.
In short ASP.NET applications are compiled pieces of code, which can be written in first class languages ( like C#.NET, VB.NET, Jscript.NET, J# ) and which can access the entire classes in the .NET framework.


what is latest to come in future... ????
  • I have seen some whitepapers says ASP.NET will become a DLR ( dynamic Language runtime environment) when it supports programming languages like Python and Ruby. So ASP.NET is having a bright future... :)

Well as a programmer you need to know, more about the File extensions of ASP.NET applications.
  • .aspx => Files that represent ASP.NET Pages
  • .asmx => Files that implement .NET web services
  • .ascx => ASP.NET user control files.
  • .axd => file extension used for application level tracing ( trace.axd) or script level injection ( webresource.axd)
  • .ashx => HTTP handlers ( managed modules ) that interact with low level request and response services of IIS
  • .asax => ASP.NET application file such as Global.asax. This file cannot be requested directly.

In addition to this, .cs , .csproj, .vb, .vbproj, .config and .resx ( the typical Microsoft Visual Studio files) are also handled by ASP.NET.


Next time we will see how this files are requested and who handles those requests....

Post your comments and suggestions too... ;)

Tuesday, June 12, 2007

How to modify the appearance and the functionality of Outlook Web Access by using the segmentation feature in Exchange 2003

How to modify the appearance and the functionality of Outlook

SUMMARY


To modify the features that are available in Microsoft Outlook Web Access, you can use the Microsoft Exchange Server 2003 segmentation feature. Segmentation can be performed on a per-server basis to change the functionality of Outlook Web Access for all the users who are hosted on that server. Segmentation can also be performed on a per-user basis to change the functionality of Outlook Web Access for a particular user. Per-server segmentation requires that you modify the Windows registry on the Exchange computer. Per-user segmentation requires that you modify an Active Directory attribute. This article contains a list of values that you can use to enable certain Outlook Web Access features. This article also contains some sample values that you can use. This article also explains how to troubleshoot an issue with Outlook Web Access features that occurs when you upgrade to Exchange Server 2003 from Microsoft Exchange 2000 Server.

INTRODUCTION


This article describes how to customize Microsoft Outlook Web Access (OWA) by using segmentation. The segmentation feature in Microsoft Exchange Server 2003 permits you to modify the appearance and the functionality of Microsoft Outlook Web Access.

Per-server segmentation


Per-server segmentation in Outlook Web Access determines the features that are available for all Outlook Web Access users who are hosted on a particular server that is running Microsoft Exchange Server 2003. To enable per-server segmentation, you must create and then configure the DefaultMailboxFolderSet registry value in the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeWeb\OWA
To enable Outlook Web Access features, modify the value of the DefaultMailboxFolderSet registry entry on the Exchange server. This registry entry must be set on the back-end Exchange server if you use a front-end/back-end configuration. To modify the value of the DefaultMailboxFolderSet registry entry, follow these steps.

Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.
1.Click Start, click Run, type regedit in the Open box, and then click OK.
2.Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeWeb\OWA
3.On the Edit menu, point to New, and then click DWORD Value.
4.In the New Value #1 box, type DefaultMailboxFolderSet, and then press ENTER.
5.Right-click DefaultMailboxFolderSet, and then click Modify.
6.Click Decimal, and then type the decimal value that corresponds to the Outlook Web Access feature or features that you want to enable.

To enable all Outlook Web Access features, type 4294967295. The numeral 4294967295 is the same as the hexadecimal value FFFFFFFF. For a list of the values that are available, see the "Segmentation attributes" section of this article.
7.Click OK, and then quit Registry Editor.

Per-user segmentation


Per-user segmentation in Outlook Web Access determines the features that are available for a particular Outlook Web Access user. Per-user segmentation settings override the per-server value that you configure on the Exchange 2003 server. To enable per-user segmentation, you must set the msExchMailboxFolderSet attribute for that user in the Active Directory directory service.

Microsoft Windows 2000 Server


To enable per-user segmentation on a Windows 2000-based domain controller, follow these steps.

Warning If you use the ADSI Edit snap-in, the LDP utility, or any other LDAP version 3 client, and you incorrectly modify the attributes of Active Directory objects, you can cause serious problems. These problems may require you to reinstall Microsoft Windows 2000 Server, Microsoft Windows Server 2003, Microsoft Exchange 2000 Server, Microsoft Exchange Server 2003, or both Windows and Exchange. Microsoft cannot guarantee that problems that occur if you incorrectly modify Active Directory object attributes can be solved. Modify these attributes at your own risk.
1.Start the ADSI Edit tool.

To do this, click Start, click Run, type adsiedit.msc in the Open box, and then click OK.

Note ADSI Edit is included in Microsoft Windows Support Tools. To install Microsoft Windows Support Tools, double-click Setup.exe in the Support\Tools folder on the Windows 2000 CD.
2.Connect to a domain controller if you are not already connected.
3.Under the domain container, expand DC=example,DC=com, and then expand the container that contains the user account that you want to configure.

For example, expand CN=Users.
4.Right-click the container that corresponds to the user that you want to configure, and then click Properties.
5.In the Select which properties to view list, click Both.
6.In the Select a property to view list, click msExchMailboxFolderSet.
7.In the Edit Attribute box, type the decimal value that corresponds to the Outlook Web Access features that you want to enable for this user.

To enable all Outlook Web Access features, type 4294967295. For a list of the attribute values that are available, see the "Segmentation attributes" section of this article.
8.Click Set, click OK, and then quit ADSI Edit.

Microsoft Windows Server 2003


To enable per-user segmentation on a Windows 2003-based domain controller, follow these steps.

Warning If you use the ADSI Edit snap-in, the LDP utility, or any other LDAP version 3 client, and you incorrectly modify the attributes of Active Directory objects, you can cause serious problems. These problems may require you to reinstall Microsoft Windows 2000 Server, Microsoft Windows Server 2003, Microsoft Exchange 2000 Server, Microsoft Exchange Server 2003, or both Windows and Exchange. Microsoft cannot guarantee that problems that occur if you incorrectly modify Active Directory object attributes can be solved. Modify these attributes at your own risk.
1.Start the ADSI Edit tool.

To do this, click Start, click Run, type adsiedit.msc in the Open box, and then click OK.

Note ADSI Edit is included in Microsoft Windows Support Tools. To install Microsoft Windows Support Tools, double-click Suptools.msi in the Support\Tools folder on the Windows Server 2003 CD.
2.Connect to a domain controller if you are not already connected.
3.Under the domain container, expand DC=example,DC=com, and then expand the container that contains the user account that you want to configure.

For example, expand CN=Users.
4.Right-click the container that corresponds to the user that you want to configure, and then click Properties.
5.In the Attributes list, click msExchMailboxFolderSet, and then click Edit.
6.In the Value box, type the decimal value that corresponds to the Outlook Web Access features that you want to enable for this user.

To enable all Outlook Web Access features, type 4294967295. For a list of the available attribute values, see the "Segmentation attributes" section of this article.
7.Click OK, click OK, and then quit ADSI Edit.

Segmentation attributes


The following table lists the value that you must use to enable each Outlook Web Access feature. To enable many features, you must total the values. You must then enter the total in the msExchMailboxFolderSet attribute for per-user segmentation or in the DefaultMailboxFolderSet registry entry for per-server segmentation.
Outlook Web Access featureDecimal valueHexadecimal value
Messaging11
Calendar22
Contacts44
Tasks88
Journal1610
Sticky notes3220
Public folders6440
Reminders12880
New mail notification256100
Rich client512200
Spelling checker1024400
S/MIME2048800
Search folders40961000
Signature81922000
Rules163844000
Themes327688000
Junk e-mail6553610000
All features4294967295FFFFFFFF
The following table illustrates several sample entries that you can use to enable certain Outlook Web Access features. The nine settings that are listed in this table do not represent the total number of feature combinations that you can create. In this table, Example 1 and Example 2 enable the same features in Outlook Web Access.

Per-server segmentation or per-user segmentation sample values


Outlook Web Access featureDecimal value to enable featureExample 1Example 2Example 3Example 4Example 5Example 6Example 7Example 8Example 9Hexadecimal value to enable feature
Messaging1onononononononon1
Calendar2ononononononon2
Contacts4ononononononon4
Tasks8ononononononon8
Journal16ononononononon10
Sticky notes32ononononononon20
Public folders64ononononononon40
Reminders128ononononononon80
New mail notification256onononononononon100
Rich client512ononononononon200
Spelling checker1024ononononon400
S/MIME2048ononononon800
Search folders4096ononononon1000
Signature8192ononononon2000
Rules16384ononononon4000
Themes32768onononon8000
Junk e-mail65536onononon10000
All Features 4294967295onFFFFFFFF
Totals13107142949672951023130937660471310079676553532767
Notes
The values in the Totals row are the values that you must enter in the DefaultMailboxFolderSet registry entry or in the msExchMailboxFolderSet user attribute to enable that particular set of Outlook Web Access features.
The messaging feature is always enabled even if you do not explicitly enable it.
Some Outlook Web Access features such as the reminder functionality and the new mail notification functionality are dependant on other features. Additionally, some features require that the Outlook Web Access rich-user interface be enabled.

Troubleshooting


Some Outlook Web Access features may not be available after you upgrade to Exchange Server 2003 from Microsoft Exchange 2000 Server. This issue occurs after you configure per-user segmentation and then upgrade to Exchange Server 2003. In Exchange 2000 Server, the decimal value that enables all Outlook Web Access features is 1023, or hexadecimal value 0x3FF. In Exchange Server 2003, the decimal value that enables all Outlook Web Access features is 4294967295. The hexadecimal value that enables all features is FFFFFFFF. Therefore, if you assigned the decimal value 1023 to the msExchMailboxFolderSet in Active Directory, you must modify that value when you install Exchange Server 2003.


APPLIES TO
Microsoft Exchange Server 2003 Enterprise Edition
Microsoft Exchange Server 2003 Standard Edition

Saturday, June 9, 2007

Atlas and error handling

As you may already know, you must place an <atlas:ScriptManager> control within your Atlas enabled page. To handle an error situation, you can add an error template to the script manager control as shown in the following example:

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" >
<ErrorTemplate>
Woops!
<br />
Error is:
<asp:Label ID="errorMessageLabel" runat="server" Text="Label"></asp:Label>
<asp:Button ID="okButton" runat="server" Text="Clear Error" />
</ErrorTemplate>
</atlas:ScriptManager>

Now, when an exception is generated on the server through one of the async methods, the error template you have defined will display. You'll notice a label and button with an id of 'errorMessageLabel' and 'okButton' respectively. These id names are specific names and Atlas will hook up special behaviour to these controls. For the 'errorMessageLabel' control, the text of the exception will be placed here for you. For the 'okButton', clicking this will cause the error/exception display to be cleared from your browser screen.

The id names are effectively special names that Atlas recognises and attributes special behaviour to. You can see this in the generated page output. Doing a view source on a page that contains the ScriptManager control above yields the following XML script:

<button targetElement="okButton">
<click>
<invokeMethod target="_PageRequestManager" method="clearError" />
</click>
</button>
<label targetElement="errorMessageLabel">
<bindings>
<binding dataContext="_PageRequestManager" dataPath="pageErrorMessage" property="text" />
</bindings>
</label>

Here you can see the 'okButton' calling the 'clearError ' method of the _PageRequestManager object, and also binding the 'errorMessageLabel' control to the 'pageErrorMessage' property of the _PageRequestManager object.

Now I dont know if this is new to the January CTP or not, but I thought it was interesting none the less.