Wednesday 28 November 2012

WHAT IS DOT NET


Microsoft .NET (pronounced “dot net”) is a software component that runs on the Windows operating system. .NET provides tools and libraries that enable developers to create Windows software much faster and easier.

         TO RUN IT .NET Framework must be installed on a user’s PC to run .NET applications.



.NET

The .NET Framework is Microsoft's application development platform that enables developers to easily create Windows applications, web applications, and web services using a myriad of different programming languages, and without having to worry about low-level details like memory management and processor-specific instructions.


Common Language Runtime Engine

The Common Language Runtime (CLR) is the execution engine of the .NET Framework. All .NET programs execute under the supervision of the CLR, guaranteeing certain properties and behaviors in the areas of memory management, security, and exception handling.

Language Independence

The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other conforming to the Common Language Infrastructure (CLI) specification. Because of this feature, the .NET Framework supports the exchange of types and object instances between libraries and applications written using any conforming .NET language.
Base Class Library

The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions, including file reading and writing, graphic rendering, database interaction, XML document manipulation and so on.


What is the .NET architecture?

Microsoft .NET consists of four major components:
·         Common Language Specification (CLS) – blue in the diagram below
·         Framework Class Library (FCL) – red
·         Common Language Runtime (CLR) – green
·         .NET Tools – yellow

At the base of the diagram in gray is the operating system, which technically can be any platform but typically is Microsoft Windows 2000 or greater, accessed through the Win32 API (Application Programming Interface).

 

Common Language Specification (CLS)

 

The CLS is a common platform that integrates code and components from multiple .NET programming languages. In other words, a .NET application can be written in multiple programming languages with no extra work by the developer (though converting code between languages can be tricky).
.NET includes new object-oriented programming languages such as C#, Visual Basic .NET, J# (a Java clone) and Managed C++. These languages, plus other experimental languages like F#, all compile to the intermediate language(msil) which fulfill  this Common Language Specification and can work together in the same application.

Framework Class Library (FCL)

The FCL is a collection of more than 12000  class libraries and data types that enable .NET applications to read and write files, access databases, process XML, display a graphical user interface, draw graphics, use Web services, etc. The FCL wraps much of the massive, complex Win32 API into more simple .NET objects that can be used by C# and other .NET programming languages.

 

 

.NET Tools

Visual Studio .NET is Microsoft’s flagship tool for developing Windows software. Visual Studio provides an integrated development environment (IDE) for developers to create standalone Windows applications, interactive Web sites, Web applications, and Web services running on any platform that supports .NET.
In addition, there are many .NET Framework tools designed to help developers create, configure, deploy, manage and secure .NET applications and components.

What are the benefits of .NET?


.NET provides the best platform available today for delivering Windows software. .NET helps make software better, faster, cheaper, and more secure..
For developers,
 .NET provides an integrated set of tools for building Web software and services and Windows desktop applications. .NET supports multiple programming languages and Service Oriented Architectures (SOA).
For companies,
 .NET provides a stable, scalable and secure environment for software development. .NET can lower costs by speeding development and connecting systems, increase sales by giving employees access to the tools and information they need, and connect your business to customers, suppliers and partners.
For end-users,
 .NET results in software that’s more reliable and secure and works on multiple devices including laptops, Smartphone’s and Pocket PCs.


CLR


Introduction


CLR is a Common Language Runtime. As the name suggests it's Common Runtime to all dotnet related languages like Vb, C#, VC++, J# etc.

When ever we compile any application in dotnet the corresponding langauge compiler will take care of it and convert into MSIL(Microsoft Intermediate Language) code , CLR will handle the code and convert into operating system native code with the help of JIT(Just In Time)compiler. There are many components in CLR which are used to do specific tasks or functions of CLR.



Functions of CLR



Loads and executes code

·         Converts intermediate language to native machine code
·         Separates processes and memory
·         Manages memory and objects
·         Enforces code and access security
·         Handles exceptions
·         Interfaces between managed code, COM objects, and DLLs
·         Provides type-checking
·         Provides code meta data (Reflection)
·         Provides debugging, etc.



Components in CLR



The above functionalities achieved by all these components. Each component is responsible for specific functionality.


1.        Class Loader:


It is used to load all the classes at runtime


2.        MSIL to native Compiler:


It is a JIT (Just In Time) compiler it will convert MSIL code to native code


3.        Code manager:


It manages the code during runtime


4.        Garbage Collector:


It manages memory .It collects all the unused objects in the memory and deallocate them


5.        Security Engine:


It has all the security restrictions.


6.        Type checker:


It enforces strict type checking.


7.        Exception manager:


It provides mechanism to handle exceptions at runtime.


8.        Debug Engine:


Which allows you to debug applications?

9.        Com Marshaler:


Which allows interoperability to our applications


10.  Base class library support:


Which provides all types that application need at runtime


Advantages of CLR and MSIL Code


·  Platform Independency
·  Architecture Independency
·  Language Independency
·  Managing the memory using Garbage Collector

Note: CLS and CTS are the specifications not components of CLR




Boxing and unboxing

 

 

 

IT Compilers in .NET Environment

JIT (Just in time) compiler is a part of the .NET runtime execution environment. Unlike traditional compilers JIT doesn’t
compile the full class file in one shot. Compilation is done on function basis or file basis. JIT compilation has advantage
over traditional compilation that heavy parsing of original source code is avoided. Compilation in .NET is done on the basis
and it’s in steps most of the time.

In .NET environment there are three types of JIT compilers:
Pre-JIT : Per-JIT compiler compiles source code into native code in a single compilation cycle. Pre-JIT sits at the stage of
deployment of the application.

Econo- JIT:
Econo-JIT compiles methods that are called at runtime. However, these compiled methods are discarded when they’re not required.

JIT (Normal JIT) – They’re called “JIT” or “Normal JIT”. Normal JIT only compiles the methods which are called at runtime.
These methods are compiled the first time they’re called and then they’re stored in cache. When the same methods are called again, the compilation code from cache is used for execution.

 

 

 

In computing, just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance of computer programs. Historically, computer programs had two modes of runtime operation, either interpreted or static (ahead-of-time) compilation. Interpreted code is translated from a high-level language to a machine code continuously during every execution, whereas statically compiled code is translated into machine code before execution, and only requires this translation once.

Remoting in C#



REMOTING IS AN TECHNIQUE THROUGH WE CAN CREATE DISTRIBUTED APPLICATION AND TO COMMUNICATION BETWEEN THOSE APPLICATION

REMOTING IS AN TECHNIQUE TO DO INTERPROCESSOR COMMUNICATION BETWEEN TWO PROCESS
  


IN JAVA RMI (Remote Method Invocation)

IN .NET REMOTING


THESE PROCESS MAY BE RUN AT ANY WHERE AT SEVER MACHINE OR AT DIFFERENT MACHINE
EACH APPLICATION BY DEFAULT CREATE IT’S OWN APPLICATION DOMAIN.

REMOTING IS AN SERVER CLIENT ARCHITECTURE





                                                                                 SERVER APPLICATION

                                                                                  CLIENT APPLICATION

                                                                 SERVICE


SERVER APPLICATION MUST BE ACTIVE TO MAKE THE CONNECTION BETWEEN SERVER AND CLIENT.


TWO MODES

SINGLETON  :    OBJECECT IS REMOVED AND FIXED ON SERVER SIDE

 SINGLE CALL  :    OBJECT IS NOT FIXED WE DESTROY THIS OBJECT AFTER WORK.



NON REMOTABLE OBJECT     NON REMOTABLE OBJECT ARE THOSE OBJECT WHICH NEVER CROSS THEIR BOUNDRY

 REMOTABLE OBJECT      REMOTABLE OJECT ARE THOSE OBJECT WHICH CAN BE ACCESS OUT OF THE BOUNDRY TO MAKE A REMOTABLE OBJECT  USE THIS CLASS.

                MARSHALBYREFOBJECT  IS AN CLASS


REMOTING   TERMS WHICH COME IN REMOTING ENVIRONMENT



                                                   PROXY

                                         CHANNELS
                                                                                 
                                         MESSAGE

                                       FORMATTERS


PROXY
                    PROXY IS AN FAKE COPY AT CLIENT HAND SIDE TO ACCESS THE ACTUAL OBJECT AS THOSE ARE CREATED ON SERVER SIDE. AND THE CREATION OF FAKE COPY IS DONE BY CLR.
                TO GENERATE OR CREATE PROXY USE THIS

    ACTIVATOR.GETOBJECT( );


   IDENTIFICATION OF THE PROCESS BY PORT NUMBER

   SMTP PORT NO. IS 25;



IP ADDRESS + PORT NO.     TO ACCESS AN PROCESS OR TO IDENTIFY AN PROCESS



CHANNELS         CHANNELS ARE PROGRAMS IN WHICH THE TRANSPORTATION IS OCCUR BETWEEN CLIENT AND SERVER AND SERVER TO CLIENT SIDE OF A FILE. AT DATA NETWORK DATA CAN BE IN BINARY FORM


                                      HTTP CHANNEL
                                      
                                      IPC CHANNEL
                                          
TCP CHANNEL  ( SO FAST AND BINARY FORM)

IPC CHANNEL

Inter-Process Communication IPC is a set of techniques for the exchange of data among two or more threads in one or more processes. Processes may be running on one or more computers connected by a
IPC CHANNELS NOT SUPPORT ANY NETWORK LAYER, SO IT IS USED WHEN THE CLIENT AND SERVER BOTH ARE AT SAME MACHINE.

SAOP
(SIMPLE  ACCESS OBJECT PROTOCOL)
SAOP MESSEGE CAN BE UNDERSTAND BY ANY TECHNOLOGY IT IS STANDARD FORMAT BY W3C

 TO SEND TO HETEROGENEOUS SYSTEM USE SAOP


FORMATTER

 IS PLAY AN IMPORTANT ROLE  TO FORMAT AND TO CONVERT THE DATA

     TWO TYPES OF FORMATTER ARE


                                         BINARY FORMATTER
                                                 
                                          SAOP FORMATTER

                                                 
                                     CHANNEL IS FOR TRANSPORTER

                                      FORMATTER IS FOR ENCODER


                                                     PRACTICAL



1.      CLIENT APPLICATION
2.      SERVER APPLICATION
3.      SERVICE APPLICATION


         PRACTICAL EXAMPLE OF PRIVATE CHAT

             FIRSTLY CREATE SERVICE APPLICATIONS



1.      ADD AN CLASS LIBRARY FOR INTERFACE NAMING OF FUNCTIONS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Ichat
{
    public interface Ichatting
    {
        void setmessage(string to, string from, string mess);
        string getmessage(string user);
        ICollection Getusers();
        void adduser(string nm);
    }
}
2.      THEN CREATE ANOTHER CLASS LIBRARY FOR IMPLEMENTATION OF THESE FUNCTIONS


· AND ADD A REFRENCE THIS ICHAT CLASS LIBRARY

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary10
{
    public class Chat:MarshalByRefObject,Ichat.Ichatting
    {
        Dictionary<string, string> dc = new Dictionary<string, string>();
        #region Ichatting Members

        public System.Collections.ICollection Getusers()
        {
            return dc.Keys;
        }

        public void adduser(string nm)
        {
            dc.Add(nm,"");
        }

        public string getmessage(string user)
        {
            if (dc.ContainsKey(user))
            {
                return dc[user];
            }
            return null;
        }

        public void setmessage(string to, string from, string mess)
        {
            dc[to] = from + ":" + mess + Environment.NewLine;
            dc[from] =from + ":" + mess + Environment.NewLine;
        }
        #endregion
    }
}

3.  THEN CREATE SERVER APPLICATION

·         ADD A REFRENCE YOUR BOTH CLASS LIBRARY OF SERVICES
·         ADD A REFRENCE  USING SYSTEM.RUNTIME.REMOTING NAMESPACE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;


namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            TcpChannel tc = new TcpChannel(8086);
            ChannelServices.RegisterChannel(tc);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClassLibrary10.Chat), "chat", WellKnownObjectMode.Singleton);
            Console.WriteLine("server is running");
            Console.ReadLine();
        }
    }
}
           
4.      THEN CREATE CLIENT APPLICATION

            CREATE TWO FORMS

       FOR FORM 1


      CODING

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication39
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static string user;
        private void button1_Click(object sender, EventArgs e)
        {
            user = textBox1.Text;
            Form2 obj = new Form2();
            obj.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

   IN FORM2


  CODING

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication39
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            obj.setmessage(comboBox1.SelectedItem.ToString(), Form1.user, textBox2.Text);
        }
        Ichat.Ichatting obj;
        private void Form2_Load(object sender, EventArgs e)
        {  
            obj = (Ichat.Ichatting)Activator.GetObject(typeof(Ichat.Ichatting), "tcp://localhost:8086/chat");

            obj.adduser(Form1.user);
            label1.Text = Form1.user;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (string s in obj.Getusers())
            {
                if (!comboBox1.Items.Contains(s))
                {
                    comboBox1.Items.Add(s);
                }
            }
            string str = obj.getmessage(Form1.user);
           textBox1.Text = str;
        }
    }
}