Sunteți pe pagina 1din 57

Overview on.

Net Framework

Contents
   

.Net Overview. .Net Platform .Net Framework Design Goals. .Net Framework

.Net Overview


It provides a mew programming interface to windows services and APIs & integrates number of technologies that emerged from Microsoft technologies from 90s. The .Net platform consists of 5 separate products groups: (A) development tools & libraries.(Set of languages) (B) web services.(Commercial web services) (C) specialized servers.(.Net enabled servers) (D) devices.(.Net enabled, non-pc devices) (E) Based on Object Oriented Programming.

What is the need for .Net in Present Condition


The main strategy of .Net is to enable software as a service, and it is more than that, it responds to the following trends within the software industry.  Distributed Computing.(simplifies the development of robust client/server and multi-tier(n-tier) applications)  Componentization.(simplifies the integration of software components developed by different vendors)  Enterprise services.(development of scalable enterprise applications without writing the code to manage transactions,security..)  Web Paradigm Shifts.(web application development(TCP/IP), presentations(HTML),programmability(XML & SOAP)

.Net Framework
Web Services Web Forms
Windows Forms

Data and XML Classes


(Ado.net, Sql, XSLT, XML, etc..)

Framework Base Classes


(Io string net, Security, threading, text, reflection, collections etc..)

Common Language Runtime


(debug, exception type checking, JIT compilers)

Windows Platform

Version of .Net Framework


Version 1.0 1.1 2.0 3.0 Version Number 1.0.3705.0 1.1.4322.573 2.0.50727.42 3.0.4506.30 Release Date 2002-02-13 2003-04-24 2005-11-07 2006-11-06 Visual Studio 2008 Visual Studio 2010 Visual Studio Visual Studio .NET Visual Studio .NET 2003 Visual Studio 2005 Default in Windows Windows Server 2003 Windows Server 2003 R2 Windows Vista, Windows Server 2008 Windows 7, Windows Server 2008 R2

3.5 4.0

3.5.21022.8 4.0.30319.1

2007-11-19 2010-04-12

Common Language Runtime


 

The Common Language Runtime (CLR) is the platform (or execution engine) on which managed code runs. The CLR shares much in common with a traditional operating system, and as such is a useful piece of the .NET Framework to be familiar with if you will be writing managed code. Managed Code is the term applied to any software running on the .NET Framework.

Common Language Runtime




Common Language Runtime is the underpinning of the .NET Framework. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging.

Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution. The Common Language Specification (CLS) is an agreement among language designers and class library designers to use a common subset of basic language features that all languages have to follow.

Common Language Runtime contd..




Highlights  Common type system  Mapping of data types. Programming language Framework  Just-in-time (JIT) compilers  JIT compiles intermediary language (MSIL) into native code  Highly optimized for platform or device  Garbage collector  Permission and policy-based security  Exceptions  Threading  Diagnostics and profiling

Purpose Of CLR


The CLR is the execution engine for this platform, and these are its requirements. Safe binary execution:- software to run software-components that originated across the network or Internet. Performance:- Internet development solutions opt for safety and flexibility, software to execute in the native machine language of the host system. Bug reduction :- software that targets the internet must be robust (If a client application crashes, it affects a single user. If a server application crashes it can affect thousands of users and cost a millions of dollars. ) Ease of integration :- software that targets the Internet must be able to integrate with all kinds of other software. This includes software that runs locally, software that runs remotely, and software written for a wide variety of platforms.

More .NET Framework




Namespaces and Classes  Hierarchical, unified class libraries  Unified and extensible provide system and base functionality and services  Object-oriented: everything is an object!  The systems uses the same classes offered to you Interfaces  The .NET (Service) contracts Types  Byte, Sbyte, Single, Double, String, Int16, etc.  These all map to the common type system

Understanding Managed Code




Managed code is a big piece of the .NET Framework. Managed code is what your C# or VB.NET code becomes once you compile it. The reason managed code is so important is that through code management it is possible for your software to run in vastly different environments safely, securely, and efficiently.

Intermediate Language


IL is a binary assembly language that is compiled at runtime down to whatever machine language is appropriate for the host CPU. JIT compilation always happens with managed code, so managed code always executes in native machine language.

Code Management


 

 

Memory management :-The CLR maintains a managed heap that is used for all memory allocations. The CLR also cleans up objects that are no longer used. Security:- The CLR makes sure that code can not undermine a system if it is not trusted. Thread management :- Although you can create your own thread objects with managed code, the CLR maintains a thread pool which can be used by your software. Type safety :- At runtime the CLR checks all typecasting operations to be sure that the cast is valid. Code verification :- The CLR also asserts that all methods must have a return instruction. It is impossible for one instruction to runover into the next. Code verification is another feature that makes code robust, and makes it safe to run un-trusted or semi-trusted components.

Basic Introduction to C#

Why C# ?
 

Builds on COM+ experience Native support for


  

Namespaces Versioning Attribute-driven development

    

Power of C with ease of Microsoft Visual Basic Minimal learning curve for everybody Much cleaner than C++ More structured than Visual Basic More powerful than Java

C# The Big Ideas


A component oriented language


The first component oriented language in the C/C++ family


  

In OOP a component is: A reusable program that can be combined with other components in the same system to form an application. Example: a single button in a graphical user interface, a small interest calculator They can be deployed on different servers and communicate with each other

Enables one-stop programming


 

No header files, IDL, etc. Can be embedded in web pages

C# Overview
  

Object oriented Everything belongs to a class




no global scope using System; namespace ConsoleTest { class Class1 { static void Main(string[] args) { } } }

Complete C# program:

C# Program Structure
 

Namespaces


Contain types and other namespaces Classes, structs, interfaces, enums, and delegates Constants, fields, methods, properties, indexers, events, operators, constructors, destructors No header files, code written in-line No declaration order dependence

Type declarations


Members


Organization
 

Simple Types


Integer Types
 

byte, sbyte (8bit), short, ushort (16bit) int, uint (32bit), long, ulong (64bit)

IEEE Floating Point Types


 

float (precision of 7 digits) double (precision of 1516 digits)

Exact Numeric Type




decimal (28 significant digits)

Character Types
 

char (single character) string (rich functionality, by-reference type)

Boolean Type


bool (distinct type, not interchangeable with int)

Arrays
  

Zero based, type bound Built on .NET System.Array class Declared with type and shape, but no bounds
  

int [ ] SingleDim; int [ , ] TwoDim; int [ ][ ] Jagged; SingleDim = new int[20]; TwoDim = new int[,]{{1,2,3},{4,5,6}}; Jagged = new int[1][ ]; Jagged[0] = new int[ ]{1,2,3};

Created using new with bounds or initializers


  

Statements and Comments


    

Case sensitive (myVar != MyVar) Statement delimiter is semicolon Block delimiter is curly brackets Single line comment is Block comment is


; { } // /* */

Save block comments for debugging!

Data
 

All data types derived from System.Object Declarations:


datatype varname; datatype varname = initvalue;

C# does not automatically initialize local variables (but will warn you)!

Value Data Types




Directly contain their data:


     

int (numbers) long (really big numbers) bool (true or false) char (unicode characters) float (7-digit floating point numbers) string (multiple characters together)

Data Manipulation
= assignment + addition subtraction * multiplication / division % modulus ++ increment by one -decrement by one

strings


Immutable sequence of Unicode characters (char) Creation:


 

string s = Bob; string s = new String(Bob);

Backslash is an escape:
 

Newline: \n Tab: \t

string/int conversions


string to numbers:
 

int i = int.Parse(12345); float f = float.Parse(123.45);

Numbers to strings:
 

string msg = Your number is + 123; string msg = It costs + string.Format({0:C}, 1.23);

String Example
using System; namespace ConsoleTest { class Class1 { static void Main(string[ ] args) { int myInt; string myStr = "2"; bool myCondition = true; Console.WriteLine("Before: myStr = " + myStr); myInt = int.Parse(myStr); myInt++; myStr = String.Format("{0}", myInt); Console.WriteLine("After: myStr = " + myStr); while(myCondition) ; } } }

Arrays
     

(page 21 of quickstart handout) Derived from System.Array Use square brackets [] Zero-based Static size Initialization:
  

int [ ] nums; int [ ] nums = new int[3]; // 3 items int [ ] nums = new int[ ] {10, 20, 30};

Arrays Continued
 

Use Length for # of items in array:




nums.Length

Static Array methods:


Sort System.Array.Sort(myArray);  Reverse System.Array.Reverse(myArray);  IndexOf  LastIndexOf Int myLength = myArray.Length; System.Array.IndexOf(myArray, K, 0, myLength)


Arrays Final


Multidimensional
// 3 rows, 2 columns int [ , ] myMultiIntArray = new int[3,2] for(int r=0; r<3; r++) { myMultiIntArray[r][0] = 0; myMultiIntArray[r][1] = 0; }

Conditional Operators
== equals != not equals < less than <= less than or equal > greater than >= greater than or equal && || and or

If, Case Statements


if (expression) { statements; } else if { statements; } else { statements; }
switch (i) { case 1: statements; break; case 2: statements; break; default: statements; break; }

Loops
for (initialize-statement; condition; increment-statement); { statements; }

while (condition) { statements; } Note: can include break and continue statements

Classes, Members and Methods


 

Everything is encapsulated in a class Can have:


 

member data member methods Class clsName { modifier dataType varName; modifier returnType methodName (params) { statements; return returnVal; } }

Class Constructors


Automatically called when an object is instantiated:


public className(parameters) { statements; }

Hello World
namespace Sample { using System; public class HelloWorld { public HelloWorld() { }

Construct or

public static int Main(string[] args) { Console.WriteLine("Hello World!"); return 0; } } }

Another Example
using System; namespace ConsoleTest { public class Class1 { public string FirstName = "Kay"; public string LastName = "Connelly"; public string GetWholeName() { return FirstName + " " + LastName; } static void Main(string[] args) { Class1 myClassInstance = new Class1(); Console.WriteLine("Name: " + myClassInstance.GetWholeName()); while(true) ; } } }

Hello World Anatomy


    

Contained in its own namespace References other namespaces with "using" Declares a publicly accessible application class Entry point is "static int Main( ... )" Writes "Hello World!" to the system console


Uses static method WriteLine on System.Console

Summary
 

C# builds on the .NET Framework component model New language with familiar structure


Easy to adopt for developers of C, C++, Java, and Visual Basic applications

 

Fully object oriented Optimized for the .NET Framework

ASP .Net and C#


   

Easily combined and ready to be used in WebPages. Powerful Fast Most of the works are done without getting stuck in low level programming and driver fixing and

What is ASP .Net ?




ASP.NET provides a programming model and infrastructure that offers the needed services for programmers to develop Web-based applications. ASP.NET is a part of the .NET Framework, the programmers can make use of the managed Common Language Runtime (CLR) environment, type safety, and inheritance etc to create Web-based applications. You can develop your ASP.NET Web-based applications in any .NET complaint languages such as Microsoft Visual Basic, Visual C#, and JScript.NET. Developers can effortlessly access the advantage of these technologies, which consist of a managed Common Language Runtime environment, type safety, inheritance, and so on. With the aid of Microsoft VisualStudio.NET Web development becomes easier.

Advantages of Asp. Net contd..


 

ASP.NET is Part of the .NET Framework The .NET Framework comprises over 3,400 classes that we can employ in our ASP.NET applications. We can use the classes in the .NET Framework to develop any type of applications. ASP.NET Pages are compiled When an ASP.NET page is first requested, it is compiled and cached on the server. This means that an ASP.NET page performs very rapidly. All ASP.NET code is compiled rather than interpreted, which permits early binding, strong typing, and just-in-time (JIT) compiling to native code. XML-Based ASP.NET configuration settings are stored in XML-based files, which are human readable and writable. Each one of our applications can have a different configuration file and we can extend the configuration scheme according to our necessities. Code-Behind logic The main problem with ASP Classic pages is that an *.asp page does not yield modularized code. Both HTML and Script are present in a single page. But Microsoft's ASP.NET implementation contains a new-fangled method to break up business logic code from presentation code. ASP.NET Pages are built with Server Controls We can easily build complex Web pages by bring together the pages out of ASP.NET server controls. For example, by adding validation controls to a page, we can easily validate form data.

Developers can build their works in these forms (a) Web Forms. (b) Web Services.

Web Forms


Web Forms permits us to build powerful forms-based Web pages. When building these pages, we can use Web Forms controls to create common UI elements and program them for common tasks. These controls permit us to rapidly build up a Web Form.

Web Services


Web services enable the exchange of data in client-server or server-server scenarios, using standards like HTTP, SOAP (Simple Object Access Protocol) and XML messaging to move data across firewalls. XML provides meaning to data, and SOAP is the protocol that allows web services to communicate easily with one another. Web services are not tied to a particular component technology or object-calling convention. As a result, programs written in any language, using any component model, and running on any operating system can access Web services.

Why We need ASP. Net ?


            

Compiled applications no more server script Multi-language support vb, c#, Language enhancements OOP, Event-driven controls respond to client events on the server. Code and content separation Configuration enhancements Easier deployment Debugging improvements Benefits of the CLR Benefits of the .NET Framework library Multi-Processor support Consistent object model Integrated dev environment with VS.NET

Web Project Files in VS.NET


Typical files:  WebForm1.aspx + WebForm1.cs (or .vb)  AssemblyInfo.cs (or .vb)  Web.config  Global.asax + Global.cs (or .vb)  Styles.css  MyProj.vsdisco  /bin:  .dll (compiled code in /bin folder)  .pdb (debug symbols)

Web Project Files in VS.NET contd..


Other files you may see:  .ascx User control  .asmx Web service file  .axd Trace file  .xsd Typed dataset + class file  .cs or .vb Class or VB Module file  .resx resource files  + other project-specific files

Features of ASP. Net


Intrinsic Objects overcomes from ASP ASP.Net  Request (HttpRequest)  Response (HttpResponse)  Application (HttpApplicationState)  Session (HttpSessionState)  Server (HttpServerUtility)  Context (HttpContext)  Trace (TraceContext)

Useful Page Objects


 

User of type IPrincipal and contains user and security information (IsInRole & Name) Cache for accessing the ASP.NET caching infrastructure programmatically

Directives <% @ directive attribute=value %> @Page for web pages  @Control for user controls  @Reference for registering a control on a page  @OutputCache for setting page caching options (Page) or fragment caching options (Control)  Not case-sensitive

Controls

 

Web Server Controls  Automatic Browser Customization  Datagrid, textbox, dropdown  Validation Controls HTML Server Controls (using runat=Server) Custom Controls  User Controls  Composite Custom Controls  Rendered Controls 3rd Party see http://asp.net

Configuration


 

A look at the Web.config File  <appSettings> - used for your own settings (connection strings,)  <authentication> - how you determine who the user is  <authorization> - what the user has access to  <customErrors> - to redirect users to nice error pages  <trace> - to control tracing in the application Custom configuration sections Elements & attributes are case-sensitive

Session State


Modes:  InProc similar to old ASP  StateServer a windows service  SqlServer state stored in SQL Server  Off Cookieless uses a URL identifier

Building and Deploying




 

Projects are compiled  Note: changes to aspx pages may not require recompilation Compared to ASP script interpretation At Runtime (after youve built your project file):  Step 1: the aspx page is compiled to a temporary dll and cached, if not already  Step 2: the page is run Building in Debug vs. Release (pdb files / performance)

Design Time System.Web.UI.Page Inherits from WebForm1.cs/.vb Compiles Into MyProject.dll WebForm1 class

Run Time Inherits from WebForm1.aspx Compiles Into temporary.dll

HTML

Thank You

S-ar putea să vă placă și