Friday, March 23, 2007

Creating And Using Satellite Assembly!!!!

As a professional developer, your clients might ask you to develop a website in which users can choose the language they want the site to be in. Somehow, this scenario can be done by developing several pages with several languages. Finally, you can satisfy the clients' requirements. However, it takes you a very long time, and it also wastes your money. There is a faster way to accomplish the requirement. Let's enjoy!
Satellite Assemblies are the answer to this problem!!!!!
I'll tell you what i've experienced while creating a satellite assem
bly...let's try one windows application
1)now create one project naming windowsapplication1

2)now in the windows form add one lable and one dropdown
3)add item and there values in the drop down (english,en-GB) (Swiss German,de-CH) etc.
4)now go to add new resource files with names (any name you like) eg resource1.resx ,string.resx
5) now the way you have to create these resource file is very important here,for example you are choosing a file name as resource1.resx then the files youo will create will be as follows: resource1.resx,resource1.en-GB.resx,resource1.de-CH,resou
rce1.de-AT (I'm using resources for three languages here).
6)open each resource file and set some strings for each file.like the below one for each language and the default language also.













7)Now that you have specified all the resource now you have to build the code to generate all the dll's.
8)Now write the code to use these resource file in your windows form...I've give just a simple funtionality that whenever you change the selection from the dropdown then it will change the text of the lable according to the language selected.

so here is the code in C# for the windows form:
using System;
using System.Collections.Generic;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;
using System.Threading;


namespace WindowsApplication1
{
public partial class Form1 : Form
{

private ResourceManager rm;
public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{

rm = new ResourceManager("WindowsApplication1.Resource1",typeof(Resource1).Assembly);
//string resource = rm.GetString("String1");


//MessageBox.Show(resource);


}

private void ultraComboEditor1_ValueChanged(object sender, EventArgs e)
{
string slang = ultraComboEditor1.Value.ToString();

Thread.CurrentThread.CurrentUICulture = new CultureInfo(slang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(slang);

label1.Text = rm.GetString("String1");

}
}

}
Now try changing the selection and you will see that the lable text will also change.
see the below scenario and you will get why these satellite assemblies are really important:



Thursday, March 15, 2007

Beginning .NET................

The .NET Framework 2.0................

The .NET Framework consists of two parts
1)Common Language Runtime(CLR).
2)Framework Class Library(FCL).

CLR provides the programming model That all application Types will use and FCL provides an object oriented API that all application model will use.CLR includes its own file loader ,memory manager etc. FCL includes type definitions for I/O,drawing shapes,comparing strings etc.



















What above figure shows is how CLR manages the integration of different programming language. By integration i mean that how that class written in C++ can be derivered or can reference a class written in C#.CLR manages this because it defines the Common Type System(CTS) that all the languages that target CLR must use.In order for other languages (any new one or the exsiting one ) to integrate with CLR these languages must use common language specification(CLS) so that they can be integrated with other languages that target CLR.















What above figure is specifying in lay man terms is that let's say you are creating one language and you want that your language can be integrated with CLR i.e. your programme written in your own language can be compiled by JIT('ll come to it later) than it should be using common language specifications in order to be understand by CLR and to be integrated with other CLR supported languages(If I'm wrong please correct me because this is the most common example i can find).You can refer this link to know more about CLS :http://blogs.msdn.com/brada/archive/2004/03/20/93341.aspx



















NOw the above figure is the real funda behind the .NET.Although unmanaged code('ll come to it later) is allowed but CLR is famous for creating managed modules or assembly. The main funda which one can get from the figure that what ever language you C#,visual basics ,your own language(if you can create one),java,perl etc. you should have a compiler(The work of the compiler if to check the syntax and analyze the source code) that can check the syntax and analyze the code and your end result will be a managed module(IL code and metadata[data of data]). managed module can be a portable executable file or a dynamic link library.
IL code is sometimes reffered to as managed code.Every compiler targeting the CLR is required to emit full metadata into every managed module.Metadata is a set of datatable that describe what is defined in the module,such as types and there members.In addition metadata also describe what this managed module references such as imported types and their members.

These assemblies can bemultifile assembly or single file assembly('ll come to it later).While creating a multifile assembly(Including many managed modules into one assembly) or a single file assembly CLR includes a Manifest which indicates the set of files in the assembly.If the manifest indicates that an assembly contains only one file this assembly will be a managed module in itself els if it indicates that group of files are there in an assembly than during build some extra work has to be done('ll come to it later).