.Net Framework - SBLP 2004

basiliskcanoeDéveloppement de logiciels

2 nov. 2013 (il y a 4 années et 8 jours)

95 vue(s)

.Net Framework

Joel Pereira (joelcdp@microsoft.com)

Software Design Engineer

WinFS API Team

Microsoft Corporation

Agenda

Part I
-

Fundamentals

Programming Models

Design Goals and Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




Unify Programming Models

Windows API

.NET Framework

Consistent API availability regardless of

language and programming model

ASP

Stateless,

Code embedded

in HTML pages

MFC/ATL

Subclassing,

Power,

Expressiveness

VB Forms

RAD,

Composition,

Delegation

Make It Simple To Use

Organization

Code organized in hierarchical
namespaces and classes

Unified type system

Everything is an object, no variants, one
string type, all character data is Unicode

Component Oriented

Properties, methods, events, and attributes
are first class constructs

Design
-
time functionality

How Much Simpler?

HWND hwndMain = CreateWindowEx(


0, "MainWClass", "Main Window",


WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,


CW_USEDEFAULT, CW_USEDEFAULT,


CW_USEDEFAULT, CW_USEDEFAULT,


(HWND)NULL, (HMENU)NULL, hInstance, NULL);

ShowWindow(hwndMain, SW_SHOWDEFAULT);

UpdateWindow(hwndMain);

Form form = new Form();

form.Text = "Main Window";

form.Show();

Windows API

.NET Framework

Hello World Demo

What you need

Agenda

Part I
-

Fundamentals

Programming Models

Design Goals and Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




Common Language Runtime

Design Goals

Dramatically simplifies development
and deployment

Unifies programming models

Provides robust and secure execution
environment

Supports multiple programming
languages

Architectural Overview

Common Language Runtime

Framework

Class loader and layout

GC, stack walk, code manager

IL to

native code

compilers

Security

Execution

Support

Base Classes

Assembly

Compilation And Execution

Source
Code

Language
Compiler

Compilation

At installation or the
first time each
method is called

Execution

JIT
Compiler

Native

Code

Code (IL)

Metadata

Languages

The CLR is Language Neutral

All languages are first class players

You can leverage your existing skills

Common Language Specification

Set of features guaranteed to be in all
languages

We are providing

VB, C++, C#, J#, JScript

Third
-
parties are building

APL, COBOL, Pascal, Eiffel, Haskell, ML,
Oberon, Perl, Python, Scheme, Smalltalk…

Hello World Demo

What you need

MSIL

Agenda

Part I
-

Fundamentals

Programming Models

Design Goals and Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




Component
-
Based Programming

3 core technologies make building and

using components easy

Type safety

Automatic memory management

Metadata

This greatly simplifies application
development

Type Safety

Type safety ensures that objects are used
the way they were intended to be used

Prevents an object’s state from being corrupted

The CLR enforces type safety

Attempting to coerce an object to an
incompatible type causes the CLR to throw an
exception

Type safety means code confidence

Common programmer errors will be found
immediately

Rectangle(hwnd, 0, 0, 10, 10);

//hwnd should be an hdc

MessageBox(hwnd, “”, “”, IDOK);

//IDOK should be MB_OK

Automatic Memory Management

The CLR tracks the code’s use of objects and
ensures

Objects are not freed while still in use (no memory
corruption)

Objects are freed when no longer in use (no memory leaks)

Code is easier to write because there is no question
as to which component is responsible to free an
object

When passed a buffer, who frees it: caller or callee?

Each process has 1 heap used by all components

Objects can’t be allocated from different heaps

You don’t have to know which heap memory was allocated
in or which API to call to free the memory

In fact, there is no API to free memory, the GC does it

Metadata

Set of data tables embedded in an EXE/DLL

The tables describe what is defined in the file (Type, fields,
methods, etc.)

Every component’s interface is described by metadata tables

A component’s implementation is described by Intermediate
Language

The existence of metadata tables enables many features

No header files

Visual Studio’s IntelliSense

Components don’t have to be registered in the registry

Components don’t need separate IDL or TLB files

The GC knows when an object’s fields refer to other objects

An object’s fields can be automatically serialized/deserialized

At runtime, an application can determine what types are in a file
and what members the type defines (also known as late binding)

Components can be written/used by different languages

Metadata: Creation And Use

Metadata

(and code)

Debugger

Schema

Generator

Profiler

Compilers

Proxy Generator

Type Browser

Compiler

Source

Code

XML encoding

(SDL or SUDS)

Serialization

Designers

Reflection

TLB Exporter

Runtime Execution Model

Class

Loader

CPU

Managed

Native Code

Assembly

First call

to method

First reference

to
type

Assembly

Resolver

First reference

to Assembly

IL to native

conversion

JIT Compiler
-

Inline

Standardization

A subset of the .NET Framework and C#
submitted to ECMA

ECMA and ISO International Standards

Co
-
sponsored with Intel, Hewlett
-
Packard

Common Language Infrastructure

Based on Common Language Runtime and
Base Framework

Layered into increasing levels of
functionality

Rotor (SSCLI)

Shared
-
Source version of the
CLR+BCL+C# compiler

Ports available: Windows, FreeBSD,
OSX, etc

Real product code offers real world
learning

http://sscli.org



Developer Roadmap



“Orcas” release


Windows “Longhorn”
integration


New UI tools and
designers


Extensive managed
interfaces


Visual Studio Orcas
“Longhorn”

Visual Studio

.NET 2003



“Everett Release”


Windows Server 2003
integration


Support for .NET Compact
Framework and device
development


Improved performance

Visual Studio 2005
“Yukon”



“Whidbey” release


SQL Server integration


Improved IDE productivity
and community support


Extended support for

XML Web services


Office programmability


Agenda

Part I
-

Fundamentals

Design Goals

Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




SQL Server Integration

Design
Goal

Bring framework programming model
into the database tier

Allow business logic to easily migrate
to the most appropriate tier

Enable
safe
database extensions


Result: Stored Procedures, Triggers,
data types defined in managed code


VS .NET
Project

Assembly:
geom.dll

VB, C#, …

Build

SQL Server

SQL Data Definition:
create assembly …
create function …
create procedure …
create trigger …
create type …

SQL Queries:

SELECT name FROM Supplier


WHERE Location.Distance ( @point ) < 3

CLR hosted by
SQL (in
-
proc)

SQL CLR Functionality

Define Location.Distance()

Sql Programming Model

Splitting a string

The old way….

declare @str varchar(200)

select @Str = 'Microsoft Corporation|SQL
Server|2003|SQL
-
CLR|2002
-
08
-
20|11:32:00|Document|3.b.3'

SELECT

substring(@Str + '|', 0 + 1,


charindex('|', @Str + '|', 0 + 1)
-

0
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|') + 1,


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1)
-



charindex('|', @Str + '|')
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1,


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1)
-


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1)
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1,


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1)
-


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1)
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1,


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1)
-


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1)
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1,


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
-


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1)
-

1
),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
+ 1,


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
+ 1)
-



charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
-

1 ),

substring(@Str + '|', charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
+ 1) + 1,


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
+ 1) + 1)
-



charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|',


charindex('|', @Str + '|', charindex('|', @Str +
'|',


charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1)
+ 1)
-

1 )

declare @ str va rchar( 200)

select @S tr = 'Micros oft Co rporat ion|SQ L Serv er|200 3|SQL
-
CLR|20 02
-
08
-
20|11:32:00| Docume nt|3.b.3'

SELECT

substring (@Str + '|', 0 + 1,


charin dex('|', @St r + '|', 0 + 1)
-

0
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|') + 1,


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 )
-



charin dex('|', @St r + '|')
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1,


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1)
-


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 )
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1,


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1)
-


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1)
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1,


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1)
-


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1)
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1,


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1)
-


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1)
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1) + 1,


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1) + 1)
-



charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1)
-

1 ),

substring (@Str + '|', char index('|', @ Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', cha rindex ('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1) + 1) + 1,


charin dex('|', @St r + '|', cha rindex ('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|', ch arinde x('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1) + 1) + 1 )
-



charin dex('|', @St r + '|',


charin dex('|', @St r + '|', cha rindex ('|', @Str + '|',


charin dex('|', @St r + '|',


charin dex('|', @St r + '|', cha rindex ('|', @Str + '|',


charin dex('|', @St r + '|') + 1 ) + 1) + 1) + 1) + 1) + 1)
-

1 )

Sql Programming Model


Splitting a string

Public Shared Sub SplitString()


Dim s As String


s = "Microsoft Corporation|SQL

Server|2003|SQL
-
CLR|2002
-
08
-

20|11:32:00|Document|3.b.3"


Dim myArray() As String = Split(s, "|")

End Sub

The new way….

Moving to 64 bit

64 bit for Servers and workstations

X64 and IA64 bit support

Enable Yukon and ASP.NET

Verifiable managed binaries just run!

VS: Runs as a 32bit application

You can develop, deploy, and debug 32
and 64bit applications

Agenda

Part I
-

Fundamentals

Design Goals

Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




Performance

Objectives: make .NET an even greater programming
platform

Long
-
Term: make the performance characteristics of
the CLR similar to native code

Reduce marginal cost of additional managed processes

Reduce startup time and working set

NGen

Compiles IL code to native code, saving results to disk

Advantages: no need to recompile IL to native code,
and class layout already set so better startup time

Whidbey: Significant reductions in the amount of
private, non
-
shareable working set

OS: ‘no
-
Jit’ plan, all managed code will be NGened

Performance everywhere

New, Performant APIs

APIs for faster resource lookup

Lightweight CodeGen: only generates
essential code (contrast to Reflect Emit)

Existing APIs Improved

Cross AppDomain Remoting


Between 1.1 and 200x faster. Biggest gains for simpler items
(strings, integers, serializable objects)

Delegate invoke performance has more than
doubled

AppDomain Footprints: significantly reduced

UTF8Encoding: translation is 2.5x faster

TryParse

RAD Debugging

Edit and Continue: Edit Code at runtime

Allowed Edits: Examples

Add private fields to a class

Add private non
-
virtual methods to a class

Change a function body, even while stepping

Disallowed Edits: Examples

Removing fields/methods

Edits to generic classes

Serialization will not recognize new fields

Display Attributes for a better debugging
experience

CLR Security

New cryptography support

PKI and PKCS7 support

XML encryption support

Enhanced support for X509 certificates

Enhanced Application Security

Permission Calculator

Integration with ClickOnce

Better SecurityException

Debug
-
In
-
Zone

Managed ACL Support

Agenda

Part I
-

Fundamentals

Design Goals

Architecture

CLR Services

Part II


Visual Studio 2005

Extending the Platform

Improving the Platform

Innovation in the Platform




Generics

Why generics?

Compile
-
time type checking

Performance (no boxing, no downcasts)

Reduced code bloat (typed collections)

VB, C#, MC++ produce & consume generics

Use

generics freely in internal APIs

Consider using generics in public APIs

Generics are not yet in CLS

To be CLS compliant, provide a non
-
generic API
alternative

Microsoft is actively pursuing standardization of
generics in runtime and languages

Enhancing The Base Library

Other Generics to look out for

Nullable(
Of T
)

Extremely useful for situations where null is
a value, such as database valuetypes





EventHandler
<T>

Saves on making your own EventHandlers

Dim intVal as Nullable(
Of Integer
) = 5

If

intVal.HasValue
Then

‘ checks for a value

delegate void

EventHandler
<T>
(
Object

sender,
T

e)
where

T :
EventArgs
;

Whidbey Tracing Features

Pluggable Formatters

Pre
-
Whidbey

: Formatting of Trace
information was predefined, and not
controllable

Whidbey

: Predefined formatters (delimiter,
xml) added, and you can make your own



MySource;Error;13;Wrong key;;;;;;318361290184;

Additional Listeners

Pre
-
Whidbey

: No Console listener, ASP had
their own tracing mechanism

Whidbey

: Added Console listener. Integrated
ASP tracing into our own, and added ETW
listener

Whidbey Tracing Features

Auto
-
generated Data

Pre
-
Whidbey

: Standard information such as
timestamp or callstack would have to be explicitly
generated

Whidbey

: An Admin can easily generate this data
automatically, via config settings


<
listeners
>



<
add

name
="examplelog"
type
= …



Simple Thread Identification

Pre
-
Whidbey

: specific threads were difficult to
identify, and filter on

Whidbey

: Correlation ID has been added, which
allows quick and easy identification of a thread, and
simple subsequent filtering

Whidbey Tracing Features

Listener Filtering

Pre
-
Whidbey

: Formatting of Trace
information was predefined, and not
controllable

Whidbey
: Assign filtering to listeners, so
only certain messages are traced. This
allows filtering on any property of a
message. E.g., ID, TimeStamp, etc.


Switches

Pre
-
Whidbey

: Couldn’t determine what
tracing a component supported

Whidbey

: Support the ability to determine
what tracing mechanisms a component has

Attend a free chat or web cast

http://www.microsoft.com/communities/chats/default.mspx


http://www.microsoft.com/usa/webcasts/default.asp



List of newsgroups

http://communities2.microsoft.com/

communities/newsgroups/en
-
us/default.aspx



MS Community Sites

http://www.microsoft.com/communities/default.mspx



Local User Groups

http://www.msdnbrasil.com.br


Community sites

http://www.microsoft.com/communities/related/default.mspx


Resources

BCL Blog


http://weblogs.asp.net/bclteam

BCL Website


http://www.gotdotnet.com/team/clr/bcl/default.aspx

BCL public mail alias


bclpub@microsoft.com

Reference


.NET Framework Standard Library Annotated Reference


Applied Microsoft .Net Framework Programming


Q & A:

© 2004 Microsoft Corporation. All rights reserved.

This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.