motionslatelickSoftware and s/w Development

Nov 2, 2013 (5 years and 3 months ago)


Se dovessimo mostrare a video un pulsante saremmo costretti a ricostruire il programma, come invece

si tendeva a fare in passato. .NET e' un COTS che ci consente di non dover “reinventare la ruota”.

The .NET framework is the latest platform from Microsoft, and it provides a multilanguage

environment that enables you to develop, deploy, and run Web-based applications and services. It

provides a new level of interoperability that enables you to reuse components created in other

languages. It also provides new and advanced features such as garbage collection and enhanced

security. Here we examines the components of the .NET framework.
Components of the .NET Framework
The .NET framework is composed of classes and services
that form a layer between applications and

the operating system
It consists of the following two main components:

Common language runtime (CLR)

.NET framework class library
The next sections look at these two components in detail.
Common Language Runtime
is the runtime environment of the .NET framework. CLR provides
common set of services
—such as exception handling, security, and debugging—to
languages that are CLR compatible
. All

programming languages in Visual Studio.NET, such as Visual Basic.NET and Visual C#.NET, support

the CLR.
During the execution of a program, the CLR controls the interaction of code with the operating system.

Code that is executed by the CLR is known as managed code. In contrast, code that is not executed by

the CLR is known as unmanaged code. Managed code “cooperates” with the CLR by providing

metadata to the CLR. The CLR, in turn, provides services, such as garbage collection and memory

management, to the code.
Unlike managed code, unmanaged code can


the .NET Framework API and make

direct calls to the operating system
During compi
lation, the CLR converts code into
Microsoft Intermediate Language
MSIL is a set of instructions that are CPU independent. MSIL includes instructions for loading, storing,

initializing, and calling methods. It also contains instructions about
arithmetic and logical operations

and exception handling.
When any code is compiled in addition to MSIL, metadata is created and

stored with the compiled code. Metadata contains information about the members, types, and

references in the code. The CLR uses
metadata to locate and load classes, generate native code, provide

security, and execute code
. Thus, after code is compiled, the compiled file contains MSIL and

metadata. The compiled file containing MSIL and metadata is known as a
portable executable (PE
) file

Before code is executed, however, the MSIL in the PE file is
converted to native code.
The just-in-time (JIT) compiler of the CLR uses the metadata
and converts

MSIL into
native code
Unlike MSIL, native code is CPU dependent
The .NET Framework r

uns on an

operating system and supports any language that conforms to the common language specification





( Medatata + (
converte in)->

converte in → Native Code
Therefore, the CLR provides various JIT compilers (a seconda del native code), and each works on a

different architecture. This implies that, depending on the JIT compiler used to compile MSIL, the
same MSIL can be executed on different architectures.
While managing code, the CLR also performs various tasks such as managing memory, security, and

threads and verifying and compiling code. For example, when an application is running, the CLR

allocates memory, manages threads and processes, and enforces the security policy.
CLR defines the common type system (
which is a standard type system used
by all languages that support the CLR. The CTS lists the types supported by the CLR,
and they include the following:
Value types
The use of the
(common type system) ensures that data types, such as Integer, String, and Long,
have the same implementation across CLR-compatible languages. This implies that you can pass a

variable from a class created in a CLR-compatible language to another class regardless of the

programming language used because data types have the same implementation across languages.
Now that you’ve looked at the features of the CLR (Commmon language runtime), you’ll look at the

features of the .NET framework class library.
Framework Class Library
The .NET framework class library includes multiple reusable,
object-oriented, and extensible classes. It

with the
and is common to all programming languages in Visual Studio.NET.
The .NET framework class library provides a common set of classes across programming languages.

While developing applications, you can use these classes to create new classes. You can use the classes

in the .NET framework class library to develop applications and implement cross-language inheritance.
The classes in the .NET framework class library are organized hierarchically. In the .NET framework

class library, the System namespace is at the top of the hierarchy and contains all other classes. On a

broad level, the System namespace contains classes that enable you to perform the following tasks:
Converting data types
Manipulating parameters
Invoking local and remote programs
Managing the application environment
You will learn more
about using namespaces
later . Table 1-1 describes
some of the namespaces in the .NET framework class library.
Namespaces and CLR (Common language runtime)


es That Enable You To Compile.


generate code in Visual C#.NET



Compile and generate code in JScript

Compile and generate code in Visual Basic.NET

Programming languages
ADO.NET, Windows Forms,
Globalization, Security
.NET Framework Class Library
Common Language Runtime (CLR)

Manipulate the system registry and manage operating system events


Manage exceptions and define data types, events and event handlers, interfaces, and attributes.

The System namespace contains various
other namespaces
, such as
System.Text, and System.Security.
Now that you know the basic structure of the .NET framework
, you will take a look at its
.NET Framework Features
The .NET framework provides the basic functionality that can be used across languages. For example,

the .NET framework provides Windows forms and Web forms. You can use Windows forms to create

Windows applications in any .NET language. Similarly, using any language that supports the .NET

framework, you can access Web forms and create Web applications.
The .NET framework provides an integrated debugger
. You can use the integrated

debugger to debug

the code written for the .NET framework regardless of the

programming language used to write the

code. For example, you can use the debugger

to debug an application that was written in Visual

Basic.NET and that includes

components created in Visual C#.NET. In addition, in the .NET

framework, you can also

debug a program while it is running. To do so, you attach the debugger to the


ogram. The debugger also enables you to perform remote debugging.
The .NET framework introduces the
concept of assemblies
An assembly is a collection

of one or more

classes that can be used by multiple applications
. You can use

assemblies to build appl
ications. The

applications you create are made up of one or

more assemblies. Assemblies, which are self-describing

components, simplify the

deployment of applications. In the .NET framework, you don’t need to


assemblies in the system registry.
You can store assemblies in a directory on your

computer. In

addition, assemblies enable you to solve version-control problems.
Assemblies provide an infrastructure that enables you to enforce versioning rules. You don’t need to

register assemblies. However, if multiple applications need to access an assembly, you must add the

assembly to the global assembly cache (GAC). The GAC stores the assemblies that are shared among
applications running on a computer. You can install and remove assemblies from the GAC. You can

use the Global Assembly Cache tool to install and remove assemblies. You can also view the contents

of an assembly by using the Global Assembly Cache tool.
The .NET framework also introduces a new security mechanism for applications by providing code-
access security (CAS) and role-based security. CAS enables you to specify permissions for code. CAS

settings determine the actions that the code can or cannot perform. By specifying CAS, you ensure that

the code is not misused. Role-based security ensures that unauthorized users cannot access

applications. Using role-based security, you can specify permissions for a user, also known as the

The .NET framework validates the individual and group permissions of the principal. Role-based

security enables you to specify generic, Windows, and custom principals for applications. In addition,

you can define new principals for an application by using role-based security. Although you can use

role-based security on both the client side and the server side, it is most suitable for applications in

which processing occurs on the server side, such as ASP.NET Web applications.
Now that you’ve looked at the .NET framework and its features, you will look at the features of Visual

Introduction to Visual Studio .NET
Visual Studio.NET, which is the latest version of Visual Studio, is based on the .NET


Visual Studio.NET provides languages and tools that enable you to build

Web-based, de
sktop, and

mobile applications. You can also create
Web services

Visual Studio.NET.
Visual Studio.NET includes the following programming languages:
Visual Basic.NET
Visual C++.NET
Visual C#.NET
It also provides additional technologies, such as ASP.NET, that enable you to develop and deploy

applications. In addition, Visual Studio.NET includes the MSDN library that contains documentation

on various development tools and applications.
Using the integrated development environme
nt (IDE) of Visual Studio.NET, you can


applications in the various .NET languages.
The IDE of Visual Studio.NET

enables you to share tools

and create applications in multiple languages.
Visual Studio.NET
includes various enhancements over earlier
versions of Visual Studio.
The following sections describe the enhancements in Visual Studio.NET.
Extension Name Description
Visual Studio solution
Organizes projects, project items, and
solution items in the solution by giving the
environment references to their locations on
Solution user options
Records all of the options that you may
associate with your solution so that each time
you open the solution, it includes any
customizations that you made.
.cs Visual C#
Represents forms, user controls, classes, and
module files that belong to a single-project
solution. Any files that are not based on a
programming language have their own
extension. For example, a Crystal Report file
has the extension .rpt, and a text file has the
extension .txt.
.csproj Visual C#
Represents forms, user controls, classes, and
module files that belong to a multiple-project
solution. This extension allows you to
differentiate between files written in Visual

Web project items Web project items include Web-specific files
.aspx such as .aspx for Web Forms,
.asmx for XML

.asax Web services, and .asax for global application
classes. Web projects also use the .cs file
extension for classes and modules.
An assembly is the main component of a .NET Framework application and is a collection
of all of the functionality for the particular application. The assembly is created as either
a .dll file for web sites or an .exe file for Windows applications, and it contains all of the
MSIL code
to be used by the framework. Without the assembly there is no application.
The creation of an assembly is automatically performed by VS20XX. It is possible to cre-
ate applications for the .NET Framework without VS—however, you need to use the
various tools that come with the .NET Framework Software Development Kit (SDK) to
create the assemblies and perform other tasks that are automatically done by VS. Since
this is a beginning book, I will not address those other tasks or how to create an assem-
bly without VS.
Microsoft ha introdotto .NET con il suo nuovo paradigma di programmazione, per porre
rimedio ad una serie di limiti ed inadeguatezze insiti nello standard COM e per riuscire a
portare anche su Internet la metafora di programmazione per componenti che così
produttiva è stata su altre piattaforme. Si riesce a fare tutto ciò con un forte rispetto degli
standard ed è per questo che, a fondamento di tutta questa visione, ritroviamo protocolli
standard di Internet: SOAP, HTTP, SMTP, XML, FTP.
Come Web Service, abbiamo Visual
Studio come strumento di produttività sui servizi messi a disposizione dal .NET Framework
e le applicazioni che emergono come un’opportuna sinergia od orchestrazione di diversi
attori che possono essere componenti COM, Assembly.NET, Web Service e quant’altro.
Tecnologia alla base di tutti i nuovi prodotti (SQL Server, WinFX, Windows Vista): i
linguaggi devono interagire tra loro. Standard ISO.
Progettata nel 1998 come evoluzione di COM.
Strato software che si interpone tra l’applicazione e il sistema operativo: ambiente di
esecuzione (Framework) che si appoggia su Windows.
Alla base vi è il CLR (Common Language Runtime) l’implementazione Microsoft di
un’insieme di specifiche note come CLI (Common Language Infrastructure) che sono state
standardizzate da ECMA (ECMA-334, ECMA-335) nel dicembre del 2001 per creare
un’architettura aperta. Esistono già altre implementazioni di CLI. SSCLI (Microsoft, per
Windows, FreeBSD e Macintosh). Mono (per Linux).
DotGNU. Intel OCL (Open CLI
In particolare il CLR mette a disposizione componenti tecnologiche sofisticate per
la gestione degli oggetti, un sottosistema per la gestione della sicurezza, un sottosistema
per garantire un debugging intuitivo e facile anche quando l’applicazione utilizza diversi
linguaggi al proprio interno, un sistema che permette d’interagire con l’Application Server
Microsoft che anche per il .NET Framework resta COM+. Infine abbiamo una parte relativa
alla compilazione, in particolare la compilazione JIT (Just In Time), perché il concetto di
compilazione è stato ridefinito nel mondo del .NET Framework. A differenza di quanto
avveniva con la generazione precedente degli strumenti di sviluppo, la compilazione
tramite i linguaggi del .NET Framework, con l’unica eccezione del C++, porta ad una
rappresentazione del codice in un formato non dipendente dalla CPU che è detto MSIL
(Microsoft Intermediate Language). IL (Intermediate Language) Standard ECMA del 1997.
Ma poiché all’interno del mondo del .NET Framework nulla gira in interpretato, ma tutto è
compilato, è evidente che questa rappresentazione non dipendente dalla CPU, dovrà
essere soggetta ad una fase di compilazione JIT, prima di poter essere mandata in
esecuzione. La fase di compilazione JIT è seguita tra l’altro con tecniche di forte
ottimizzazione e in grado di minimizzare l’impatto dei tempi di compilazione
sull’esecuzione. Esiste poi una libreria di classi che riespone con una metafora ad oggetti,
tutti i servizi del CLR, i servizi del sistema operativo sottostante e dell’Application Server
Microsoft COM+. Il .NET Framework include anche ADO.NET l’evoluzione dell’EDB, una
tecnologia per l’accesso ai dati che si trova a proprio agio in scenari disconnessi ed ha un
forte supporto per l’XML. Le Windows Forms, una tecnologia che permette di realizzare
applicazioni per il sistema operativo sottostante in particolare per Win32, ma anche per i
servizi Windows e di applicazioni dalla console. ASP.NET, una componente innovativa
perché offre un supporto nativo per il Web Service. Le Web Forms permette di realizzare
applicazioni ASP.NET con una metafora di programmazione indistinguibile da quella
utilizzata dai programmatori Visual Basic che realizzano applicazioni WIN32. Abbiamo poi
le CLS (Common Language Specification), un’insieme di regole alle quali i linguaggi del
.NET Framework devono sottostare, in particolare è quell’insieme di regole rispettate dai
produttori di compilatori per poter realizzare un linguaggio ospitabile dal .NET Framework.
Questi linguaggi hanno la peculiarità di conservare tutte le caratteristiche che li rendono
univoci, ad esempio il fatto di avere una determinata sintassi, di consentire o meno
l’overloading degli operatori. Le CLS definiscono le specifiche comuni a tutti i linguaggi
.NET in modo che gli assembly prodotti siano usabili da tutti i linguaggi: vantaggio è la
compatibilità binaria. Il CTS (Commom Type System) definisce come devono essere
costruiti e definiti i tipi: visibilità, contenuto in termini di proprietà, metodi.
Ciò che nessuno di questi linguaggi è autorizzato a fare è implementare un proprio
insieme di tipi, perché il concetto di compatibilità è stato ridefinito nel .NET Framework e
non è più un concetto di compatibilità binario come avveniva in COM, ma è un concetto
diverso, è un concetto di compatibilità a livello di tipo, nessuno di questi linguaggi
implementa un proprio insieme di tipi, ma tutti quando hanno bisogno di una stringa, di una
struttura, di una classe, chiedono al .NET Framework. Il vantaggio è che la
rappresentazione in memoria di questa entità è la stessa per tutti i linguaggi e ciò
consente di implementare tecniche estremamente sofisticate. Visual Studio è volutamente
rappresentato come un’entità separata rispetto al .NET Framework in quanto è uno
strumento di produttività sopra ai servizi del .NET Framework, una sorta di grande wizard
sui servizi messi a disposizione dal .NET Framework.