12 microsoft assemblies - mississippi state...

40
Software Architecture – Microsoft Assemblies 1 Chapter 12 Microsoft Assemblies

Upload: others

Post on 20-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 1

Chapter 12 Microsoft Assemblies

Page 2: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 2

Process Phases Discussed in This Chapter

Requirements Analysis

Design

Implementation

Architecture Framework Detailed Design

x Key: = secondary emphasis x = main emphasis

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 3: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 3

Learning Goals for This Chapter

q … Microsoft’s component (“assembly”) architecture q … where assemblies fit in .NET q … required rudiments of C# q … the contents of .NET manifests, including:

Versioning Attributes

q … the difference between private and shared assemblies

q … create assemblies using C#

Understand …

Be able to …

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 4: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 4

.NET Goals and Solutions

q  Create interoperable components from multiple source languages o  C++, Visual Basic, ….

q  Solve multiple component version clashes o  “dll hell”: naming confusion in COM

q  Define a common runtime

q  Avoid registry o  Necessity to register components with host computer

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 5: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 5

Design Goal At Work: à Reusability ß

Microsoft wanted to allow developers to create interoperable components using their favorite source languages.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 6: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 6

The Parts of.NET

Web tools and Languages ASP.NET, Windows Forms; Visual Basic.NET, C#

.NET Framework Classes

net XML IO Security . . . .

Common Language Runtime (CLR)

Memory Management Common Type System (CTS) . . . .

uses

uses

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 7: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 7

q  Boolean

q  DateTime

q  Decimal – 28 significant digits

q  Double – 64-bit double-precision floating point

q  GUID – unique 128-bit integer; unique identifier

q  Int16, Int32, Int64

q  Sbyte – 8-bit signed integer –128 to +127

q  Single – 4-byte single precision floating point

q  TimeSpan – a period of time

Types in the CTS

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 8: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 8

q  Boolean Equals( Object )

q  Int32 GetHashCode() o  Generates an integer corresponding to

the value of the object

o  Used by sorting algorithms in System.Collections

q  Type GetType() o  for the Reflection API

q  String ToString()

Methods of System.Object

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 9: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 9

Selected System.XX .NET Framework NameSpaces

q  Collections

q  ComponentModel

o  “to implement the runtime and design time behavior of components”

q  Data

o  To deal with databases via ADO

q  Drawing

q  IO

q  Net

o  to interface with common network protocols

q  Reflection

q  Runtime

Security

Text

ASII, Unicode etc.

Threading

Web

WinForms

XML

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 10: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 10

Compilation Process in .NET

Source Code C++ VB

Compiler & metadata generator

IL and metadata

Ancillary info

.dll or .exe

Base class library

Class loader

IL compiler

native code

execute Process File Key:

C# J#, Java (3rd parties)

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 11: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 11

A File

A File

A File

A File

The Parts of a .NET Assembly (Component)

Manifest •  Identity

–  name –  version

•  Names of files •  Encrypted hash of files to

ensure integrity •  Specification of types

defined •  Names of referenced

assemblies •  Specification of required

security permissions

Microsoft Intermediate

Language (IL)

Source Files A .NET assembly: xyz.dll

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 12: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 12

Key Concept: à A .NET Assembly ß

-- includes class code from multiple files, in IL form, described by a manifest.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 13: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 13

C# Goals 1 of 2

•  Rapid application development –  as with JavaBeans

•  Cross-platform deployment –  generates character stream interpreted by .Net runtime. –  as with Java Virtual Machine

•  Access to platform-native resources –  take advantage of the Windows API to run as a full-featured

application on Windows 2000 •  Support for the COM and .NET platforms

Unlike

Java

Unlike Java

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 14: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 14

q Features of C and C++ “with the functional ease of rapid application development tools.”

q  Components with properties, methods and events o  built in

C# Goals : 2 of 2

Unlike Java

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 15: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 15

HelloWorld Output

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 16: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 16

Selected C# Features

•  Automatic garbage collection

•  Allows developers to disable garbage collection

locally – –  by marking code as “unsafe”

–  (e.g., where real time performance required?)

•  Eliminates pointers in favor of references

•  Introduces Interfaces

Unlike Java

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 17: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 17

C# Web Features: Web Services q Attribute library allows wrapping of C# classes and

functions as Web services.

–  a hosted software module callable over the Internet typically via SOAP protocol.

–  SOAP wraps method calls, parameters, and return values, in XML packets.

q Using appropriate attributes, programmer can turn any C# class or function into a Web service.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 18: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 18

Creating a .NET Component 1 of 2

csc /t:library /out:hello.dll helloFile.cs

“target” Create a library component: Don’t seek Main()

“output” Component (output) name

Input file C# compilation

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 19: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 19

Creating a .NET Component (“Assembly”) 2 of 2

helloFile.cs

hello.dll

hello.dll

csc /t:library /out:hello.dll helloFile.cs

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 20: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 20

Using a .NET Component

csc /r:hello.dll /out:helloApp.exe helloClient.cs

hello.dll helloClient.cs

helloApp.exe

… now execute helloApp.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 21: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 21

Creating a .NET Component Containing Multiple Classes

csc /t:library /out:helloAuRevoir.dll HelloAuRevoirComponentSource.cs

HelloAuRevoirComponentSource.cs

helloAuRevoir.dll

GreetingUtility HelloClass AuRevoirClass

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 22: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 22

Output For “Multiple Class” Example

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 23: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 23

Using metadata allows the CLR to support: q Multiple execution models

o  interpreted, o  JITted (Just-in-time) o  native o  legacy code (prior to .NET)

q Uniform services available to debuggers, profilers etc. q Consistent exception handling q Code access security q Memory management q Reflection q  Interoperability with existing unmanaged COM

applications q  Interoperability with existing unmanaged code q Optimization to match the particular CPU or

environment.

Uses for Metadata

Amended from http://msdn.microsoft.com/library/default.asp

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 24: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 24

Manifest of Component helloAuRevoir.dll

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 25: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 25

Manifest Contents for helloAuRevoir.dll Component 1.  - 2.  - 3.  - 4.  - 5.  - 6.  - 7.  - 8.  - 9.  - 10.  - 11.   - 12.  - 13.  - 14.  - 15.  - 16.  --

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 26: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 26

Manifest Detail of sayHelloWorld() in HelloClass

1.  - 2.  - 3.  - 4.  - 5.  - 6.  - 7.  - 8.  -

Recall the source: public void SayHelloWorld( )

{ GreetingUtility.OutputMessage ( "Component says: Hello World" ); }

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 27: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 27

The Version Field of an Assembly

•  Major version •  Minor version •  Revision •  Build number

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 28: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 28

Versioning

(The process of evolving a component over time in a compatible manner.)

A new version is … q  … source compatible with a previous version if code that

depends on the previous version can, when recompiled, work with the new version.

q  … binary compatible if code that depended on the old version can, without recompilation, work with the new version.” (adapted from Microsoft)

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 29: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 29

Attributes in .NET q  Metadata: about …

o  … variables o  … classes o  … functions

q  Types of attributes: –  Built-in –  User-defined

q  Available at runtime

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 30: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 30

Output of main() in ConditionalDemo with #define DEBUG without #define DEBUG

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 31: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 31

Output For Authorship Querying

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 32: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 32

Key Concept: à A .NET Manifest Lists … ß

.. the files containing the IL-compiled classes, the .NET components on which the assembly depends, version numbers, attributes, and encrypted hash to verify not tampered in transit.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 33: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 33

Design Goal At Work: à Reusability ß

We want to reuse an assembly, confident it is the one it’s supposed to be.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 34: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 34

Using NameSpaces Application 1: List available flights in following form

<Animated airline logo goes here> <Material introducing available flights here > From <city> to <city> departing at <time> and arriving at <time>. <Animated logo of the Intergalactic Reservation Service goes here>

Application 2: List bookings already made in following form <Animated logo of the Intergalactic Reservation Service goes here > <Material introducing instructions to the traveler goes here > Please arrive at <time> at <city> airport for your flight.

Implement applications 1and 2. Exploit common components.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 35: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 35

Namespaces Across Multiple Components

Logo

AvailabilityAnnouncement

Itinerary namespace

(Physical) File organization (3 files)

Airlines namespace

Namespace stated: Airlines.Availability Classes: Logo, AvailabilityAnnouncement Availability namespace

ItineraryAnnouncement

Logo

(Logical) Namespace organization Source file name: AvailabilityComponentSource.cs

Component name: availability.dll

Namespace stated: Airlines.Itinerary Class: Logo

Source file name: ItineraryLogoComponentSource.cs

Component name: itineraryLogo.dll

Namespace stated: Airlines.Itinerary Class: ItineraryAnnouncement

Source file name: ItineraryAnnouncement.cs

Component name: itineraryAnnouncmnt.dll

Page 36: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 36

Airline Reservation System Display

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 37: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 37

Public Key Cryptography •  Any message encoded with one key can be

decoded with the other. •  One can’t encrypt and decrypt a message with the

same key. •  It’s practically impossible to deduce one key from

the other. •  It’s very unlikely that an encoded document can be

decoded with an unmatched key

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 38: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 38

Public Key Encryption Used in .NET

Public key: …iemhdZX… Private key: …92JiuHKM3… (secret)

myKeys.snk

Hashed version Encoded version

use private

key

Manifest Names & contents of assembly

Verification process

AssemblyInfo.cs

Assembly source

assembly

hash

OK / not OK

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 39: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 39

Key Concept: à Component Identity ß

To ensure that the component we are using is the one intended, we use relatively or globally unique names: .NET also applies tamper-proofing via public key encryption.

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Page 40: 12 Microsoft Assemblies - Mississippi State Universityweb.cse.msstate.edu/~hamilton/7700/lessons/12_Microsoft_Assemb… · Software Architecture – Microsoft Assemblies 4 .NET Goals

Software Architecture – Microsoft Assemblies 40

Summary q Microsoft “assembly” == component q Microsoft distributes computing among desktops and

servers via, in part, .NET assemblies q  .NET assemblies supercede and are more versatile

than (D)COM(+) objects. o  Exist in Intermediate Language o  Permit versioning o  Include “attribute” feature o  Identity technique for shared assemblies reduces “dll hell”

q C# language designed for .NET q Assemblies constructed via C#, VB, ... are

interoperable

Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.