.NET and Architecture

download .NET and Architecture

of 33

Transcript of .NET and Architecture

  • 8/10/2019 .NET and Architecture

    1/33

    .NET Framework 4.0and CLR

    -by Sujit BaniyaLecturer,

    La Grandee International College,

    Simalchaur, Pokhara-4

  • 8/10/2019 .NET and Architecture

    2/33

    .NET Framework Overview

    Platform for application developers. Framework that supports Multiple Language and

    Cross language integration.

    IT has IDE (Integrated Development

    Environment). Provides GUI in a GUI manner.

    Platform independent .

    Provides interoperability between languages .

    Includes the .NET Common Language Runtime(CLR).

    Consists primarily of a gigantic library of code.

  • 8/10/2019 .NET and Architecture

    3/33

    Objectives of .NET Framework A consistent OOP environment, to store and execute object

    code locally, executed locally but Internet-distributed, orexecuted remotely.

    An environment to minimize software deployment and

    versioning conflicts.

    An environment to guarantee safe execution of code, including

    code created by an unknown or semi-trusted third party.

    An environment to eliminate the performance problems of

    scripted or interpreted environments.

    Experience consistency across varying types of applications,

    such as Windows-based and Web-based applications. Build all communication on industry standards to ensure code

    based on the .NET Framework can integrate with any other

    code.

  • 8/10/2019 .NET and Architecture

    4/33

    Architecture of .NET Framework

  • 8/10/2019 .NET and Architecture

    5/33

  • 8/10/2019 .NET and Architecture

    6/33

    Step 1-Application code is written using a .NET -

    compatible language C#.

    Step 2 -

    Code is compiled into MSIL, which is storedin an assembly (see Figure 1 - 2).

  • 8/10/2019 .NET and Architecture

    7/33

    Step 3 -When this code is executed (either in its own

    right if it is an executable or when it is used from othercode), it must first be compiled into native code using a

    JIT compiler.

    Step 4 -The native code is executed in the context

    of the managed CLR, along with any other runningapplications or processes.

  • 8/10/2019 .NET and Architecture

    8/33

    Components in .NET Framework

    .NET Framework class library consists of object-oriented collection of reusable classes.

    facilitates Common Type System (CTS) that are common

    to all .NET languages.

    Common Language Runtime

    foundation of the .NET Framework.,

    act as an agent that manages code at execution time,

    providing core services such as memory management,

    thread management, and remoting, while also enforcingstrict type safety and facilitates with code accuracy that

    ensure security and robustness,

    code management is a fundamental principle.

  • 8/10/2019 .NET and Architecture

    9/33

    Key Terms in .NET Framework

    Common Language Specification (CLS); this enforcesthat software development languages should be

    interoperable between them like Microsoft Visual Basic .NET,

    Microsoft Visual C#, Microsoft Visual C++ .NET, and

    Microsoft Visual J# .NET.

    The language compilers generate an Intermediate Language

    code, called Microsoft Intermediate Language (MSIL),

    which makes programs written in the .NET languages

    interoperable across languages.

    Common Language Infrastructure (CLI), defines the

    specifications for the infrastructure that the IL code needs

    for execution that includes services such as type safety,

    managed code execution and side by side execution.

  • 8/10/2019 .NET and Architecture

    10/33

    Common Language Runtime includes the CLI andprovides the execution environment for .NET Applications.

    Common Type System provides the data types, values,object types to developers to develop applications in differentlanguages that shares the same types defined under CLI.

    Type safety: .NET Framework performs operations on thevalues or objects for which it requires each value or object hasa type and which reference to the value or object type.

    Managed code execution: It manages the state of the objectwhile executing the .NET Applications. It automatically allocates

    memory and provides garbage collation mechanism to de-allocate memory. Side-by-side execution:It allows different version of the

    same application to run on the same machine by usingassemblies of different versions.

    Key Terms in .NET Framework (contd)

  • 8/10/2019 .NET and Architecture

    11/33

    Understanding .NET Framework CLR

    foundation of the .NET Framework,

    act as an agent that manages code at

    execution time,

    providing core services such as memorymanagement, thread management, and

    remoting, while also enforcing strict type

    safety and facilitates with code accuracy

    that ensure security and robustness,

    code management is a fundamental

    principle.

  • 8/10/2019 .NET and Architecture

    12/33

    Common Language Runtime as Facilitator

    Run-time environment and CLR Compiles application into the

    runtime, compile the IL code into native

    code, execute the code

    Run-time services. Memory management, Type safety,

    Enforces Security, Exception Management.

    Thread support

    Debugging support

  • 8/10/2019 .NET and Architecture

    13/33

    Architecture of .NET Framework CLR

  • 8/10/2019 .NET and Architecture

    14/33

    Architecture of .NET Framework CLR (contd)

    Class loader, which loads classes into CLR.

    MSILto native code compiles, this converts MSIL code into native code. Code manager, this manages the code during execution. Memory allocation and Garbage collector, this performs automatic

    memory management. Security engine, this enforces security restrictions as code level security

    folder level and machine level security using tools provided by Microsoft

    .NET and using .NET Framework setting under control panel. Type checker,which enforces strict type checking. Thread support, which provides multithreading support to applications. Exception manager, which provides a mechanism to handle the run-time

    exceptions handling. Debug engine, which allows developer to debug different types of

    applications. COM marshaler, which allows .NET applications to exchange data with

    COM applications. Base class library support, which provides the classes (types) that the

    applications need at run time.

  • 8/10/2019 .NET and Architecture

    15/33

    Features of the Common Language Runtime

    Manages memory,o Allocation of Memoryo De-Allocation of Memory (garbage collation)

    Thread execution support,

    Code execution, Code safety verification,

    Compilation.o MSIL to Native Code.

    Code Security based on Trust (granted

    permission to execute code. Code level, Folderlevel, Machine level)

  • 8/10/2019 .NET and Architecture

    16/33

    Understanding JIT compiler

    JIT compiler compiles is the integral part of CLR. The MSIL code toNative code and executes the batch of code Just in time which will becached and next time when the code gets executed from cache in studof compiling again.

    JIT Execution Process

  • 8/10/2019 .NET and Architecture

    17/33

    JIT Execution Process

    CLR class loader loads MSIL code and metadata areloaded into memory; the code manager calls the entrypoint method which is WinMain or DLLMain method.

    The JIT compiler compiles the method to before itsexecution of the entry point method.

    The code manager places the objects in memory andcontrols the execution of the code.

    The garbage collector performs periodic checks on the

    managed heap to identify the objects which is not in usefor the application.

  • 8/10/2019 .NET and Architecture

    18/33

    JIT Execution Process (contd)

    At the time of program execution the type checkerensures that all objects and values, and thereferences of objects and values has its valid type.

    The type checker also makes sure that only valid

    operations are performed on the code other wisethe exception will be thrown.

    The code is controlled by CLR at run time. CLRenforces security in following manner.

    To control and access the system recourses likehard disk

    To control and access the network connections To control and access the other hard ware

    resources.

  • 8/10/2019 .NET and Architecture

    19/33

    For Example:

    1

    2

    3

    4

    5

    6

    7

    ModuleHello

    PublicClassTestClass

    PublicSharedSubMain()Console.WriteLine("Hello World")

    EndSub

    EndClassEndModule

    VB.NET Code

    MSIL Code

  • 8/10/2019 .NET and Architecture

    20/33

    New Features of .NET Framework 4.0

    Programming Languages Common Language Runtime (CLR) Base Class Libraries

    Client

    Data Communications

    Workflow

  • 8/10/2019 .NET and Architecture

    21/33

    New Features of .NET Framework 4.0 (contd)

    Common Language Runtime (CLR) Security: provides simplifications, improvements, and

    expanded capabilities in the security model.

    Parallel Computing: a new programming model for

    writing multithreaded and asynchronous code that

    greatly simplifies the work of application and librarydevelopers. The new model enables developers to write

    efficient, fine-grained, and scalable parallel code in a

    natural idiom without having to work directly with

    threads or the thread pool.

    Performance and Diagnostics: providesimprovements in startup time, working set sizes, and

    faster performance for multithreaded applications.

    Lazy Initialiation: With lazy initialization, the

    memory for an object is not allocated until it is needed.

  • 8/10/2019 .NET and Architecture

    22/33

    New Features of .NET Framework 4.0 (contd)

    Common Language Runtime (CLR) Dynamic Language Runtime: (DLR) is a new

    runtime environment that adds a set of services for

    dynamic languages to the CLR. The DLR makes it easier

    to develop dynamic languages to run on the .NET

    Framework and to add dynamic features to staticallytyped languages.

    Garbage Collection: provides background garbage

    collection

  • 8/10/2019 .NET and Architecture

    23/33

    New Features of .NET Framework 4.0 (contd)

    Base Class Libraries BigInteger: an arbitrary-precision integer data type

    that supports all the standard integer operations,

    including bit manipulation.

    Exceptions Handling: adds the ability to handle

    corrupted state exceptions.

    I/O: The key new features in I/O are efficient file

    enumerations, memory-mapped files, and improvements

    in isolated storage and compression.

  • 8/10/2019 .NET and Architecture

    24/33

    New Features of .NET Framework 4.0 (contd)

    Client Windows Presentation Foundation: (WPF)

    contains changes and improvements in many areas. This

    includes controls, graphics, and XAML.

    Managed Extensibility Framework: (MEF) enables

    you to build extensible and composable applications.

    I/O: The key new features in I/O are efficient file

    enumerations, memory-mapped files, and improvements

    in isolated storage and compression.

  • 8/10/2019 .NET and Architecture

    25/33

    .NET Framework Class Library

    A collection of reusable types that tightly integrate with thecommon language runtime.

    Object oriented, providing types from which your own

    managed code can derive functionality.

    Makes the .NET Framework types easy to use and reduces

    the time associated with learning new features of the .NETFramework.

    Easy third-party components integration with classes.

    the .NET Framework types enable to accomplish a range of

    common programming tasks, including tasks such as string

    management, data collection, database connectivity, and fileaccess.

    To develop applications and services like Console Application,

    Windows Form Application, WPF, ASP.NET Application,

    Windows Services, Windows Communication Foundation

  • 8/10/2019 .NET and Architecture

    26/33

    LINQ (Language-Integrated Query)

    LINQ introduces standard, easily-learned patterns for queryingand updating data, and the technology can be extended tosupport potentially any kind of data store.

    Simplifies query by offering a consistent model for workingwith data across various kinds of data sources and formats.

  • 8/10/2019 .NET and Architecture

    27/33

    Stages of a Query Operation

    Obtain the data source or sources. Create the query. Execute the query.

    Dim numbers() As Integer = {0, 1, 2, 3, 4, 5, 6} ' Data source.

    Dim evensQuery = From num In numbers ' Query creation.Where num Mod 2 = 0Select num

    For Each number In evensQuery ' Query execution.Console.Write(number & " ")

    Next

    Output:0 2 4 6

  • 8/10/2019 .NET and Architecture

    28/33

    Basic Query Operation (LINQ)

    Specifying the Data Source (From)Query operatorsselect and shape the result based on the type of the

    source.Dim query = From cust In customers

    The Fromclause specifies the data source, customers,

    and a range variable, cust. The range variable is like a loop

    iteration variable, except that in a query expression, no

    actual iteration occurs. When the query is executed,

    often by using a For Eachloop, the range variable servesas a reference to each successive element in customers.

  • 8/10/2019 .NET and Architecture

    29/33

    Basic Query Operation (LINQ) (contd)

    Filtering Data (Where):AWhereclause is used to performthe filtering. The filter specifies which elements in the datasource to include in the resulting sequence.

    Dim londonCusts = From cust In customersWhere cust.City = "London"

    logical operators such as Andand Orto combine filterexpressions in aWhereclause can be used.

    Ordering Data (Order By): Order By is used to sort the fields insequence

    Dim londonCusts = From cust In customersWhere cust.City = "London"Order By cust.Name Ascending

  • 8/10/2019 .NET and Architecture

    30/33

    Basic Query Operation (LINQ) (contd)

    Selecting Data (Select):The Selectclause specifies the formand content of returned elements. When the Selectclauseproduces something other than a copy of the source element,the operation is called a projection.

    Dim londonCusts2 = From cust In customers

    Where cust.City = "London"Order By cust.Name AscendingSelect cust

    Dim londonCusts3 = From cust In customers

    Where cust.City = "London"Order By cust.Name AscendingSelect cust.Name

  • 8/10/2019 .NET and Architecture

    31/33

    Basic Query Operation (LINQ) (contd)

    Joining Data (Join and Group Join):can combine more thanone data source in the Fromclause in several ways.

    Dim vowels() As String = {"A", "E", "I", "O", "U"}Dim vowelNames = From student In students, vowel In vowels

    Where student.Last.IndexOf(vowel) = 0Select Name = student.First & " " &student.Last, Initial = vowelOrder By Initial

    For Each vName In vowelNames

    Console.WriteLine(vName.Initial & ": " & vName.Name)Next

  • 8/10/2019 .NET and Architecture

    32/33

    Basic Query Operation (LINQ) (contd)

    TheJoinkeyword is equivalent to an INNER JOINin SQL. Itcombines two collections based on matching key valuesbetween elements in the two collections. The query returns allor part of the collection elements that have matching key values.

    Dim vowelNames2 = From student In studentsJoin vowel In vowelsOn student.Last(0) Equals vowelSelect Name = student.First & " " &student.Last, Initial = vowel

    Order By Initial

  • 8/10/2019 .NET and Architecture

    33/33

    Basic Query Operation (LINQ) (contd)

    Grouping Data (Group By):can add a Group Byclause togroup the elements in a query result according to one or morefields of the elements.

    Dim studentsByYear = From student In studentsSelect studentGroup By year = student.YearInto Classes = Group

    For Each yearGroup In studentsByYearConsole.WriteLine(vbCrLf & "Year: " & yearGroup.year)For Each student In yearGroup.Classes

    Console.WriteLine(" " & student.Last & ", " & student.First)NextNext