Workshop i Microsoft .NET og C#

advertisement
1. .NET Architecture
Based on slides by Joe Hummel
Aim
“Microsoft .NET is based on the Common Language Runtime (CLR)
and an extensive set of Framework Class Libraries (FCL). The
CLR defines a common programming model and a standard type
system for cross-platform, multi-language development.”
• CLR-based execution
• Application design
• Component-based development
UCN Technology: Computer Science - 2014
2
Inspiration
• .NET is inspired by a number of elements
OOP
JVM
GUI
.NET
component-based
design
UCN Technology: Computer Science - 2014
Web
n-tier design
3
.NET supports a number of languages
• .NET supports VB, C# (C-sharp), C++, J# (Java 1.1), Eiffel, etc.
code.vb
code.cs
code.cpp
Development Tools
...
FCL
app.exe
UCN Technology: Computer Science - 2014
4
.NET is “platform independent”
• Compiled .NET applications run on all supported platforms:
APP.exe
CIL: Common
Intermediate
Language
?
Win64
Win32
Windows Phone
(XP,2K,98)
UCN Technology: Computer Science - 2014
5
CLR-based execution
• .NET applications are not stand-alone .exe-programs
APP.exe
OS Process
other FCL
components
JIT Compiler
obj code
Compare to
Java JVM
Core
FCL
CLR
View the CIL Code
(“byte code”):
ILDASM
Underlying OS and HW
UCN Technology: Computer Science - 2014
6
Execution of Java programs
source
(xxx.java)
compiler
bytecode
(xxx.class)
Java Virtual Machine
Interpreter
fortolker
CPU
UCN Technology: Computer Science - 2014
7
CLR-based execution implies:
•
•
Clients need CLR & core FCL to run .NET apps
– Obtained through Redistributable .NET Framework
– Runs on Windows 98 and higher, NT (sp6a) and higher
– Runtime is integrated in Windows Vista, Windows 7,
Windows 8 and Windows Phone 7+ and newer.
Design issues…
+ managed execution (memory protection, etc.)
+ portability:
• general assembly language
• FCL = layer of abstraction between app and OS
– slower execution?
• JIT compilation is expensive
• But the JIT-compiler may take advantage of specific
target HW
• pre-JIT is possible
UCN Technology: Computer Science - 2014
8
Part 2
• Application Design…
UCN Technology: Computer Science - 2014
9
Application Design
• Often applications are designed as N "tiers"
– good separation of responsibility
– allows the same back-end tier for different clients
object
object
Front-end
object
Presentation
Business
UCN Technology: Computer Science - 2014
Data Access
Data
View demo in VS10
Physical Design
• Where should tiers be physically deployed?
– There are a range of different designs…
• Most common are:
– locally
– remote
– web app
– web service
UCN Technology: Computer Science - 2014
11
(1) Local Design
• Local implies that tiers are all deployed on one local
computer
– though may data be on a remote computer
obj
obj
FE
obj
• Pros?
– Simple to develop!
• Cons?
– Hard to deploy and maintain
– Are to be installed and configured on every client
UCN Technology: Computer Science - 2014
12
(2) Remote Design
• If Remote Design is used then the presentation (user
interface, front end) runs on a separate computer
obj
obj
FE
obj
Client
Server
proprietary protocols
• Pros?
– Easier to maintain, back-end tiers May be updated without any
changes on the clients.
– More secure, since the database only is accessed from the
server, and directly from the client.
• Cons?
– Clients Must often use the same OS as the server; firewalls
may cause troubles.
UCN Technology: Computer Science - 2014
13
(3) Web App Design
• In Web app presentation is generated by a Web server
Web
Page
Browser
ANY platform
Web server
obj
obj
obj
Server
HTML / HTTP
• Pros?
– scales to the internet, enhances the user group of the
applications.
– No firewall problems (HTTP / port 80 communication only)
• Cons?
– browser-based clients have limited functionality.
UCN Technology: Computer Science - 2014
14
(4) Web Service Design
• Web services are objects that are available through Web
technology
• In stead of HTML data is communicated in XML
custom FE
obj
obj
obj
ANY platform
Web server
obj
other APP
ANY platform
Server
XML / SOAP
• Pros?
– Open! Opens for integration of applications.
• Cons?
– A technology under development…
UCN Technology: Computer Science - 2014
15
WCF – Window Communication Foundation
• The new way of doing it: Supports
•
•
•
web-services (HTTP-based, SOAP and REST),
binary protocols (remoting) and
and much more (p2p, message queuing …)
custom FE
obj
ANY platform
obj
obj
Web server
obj
other APP
ANY platform
Server
XML / SOAP / REST…
And proprietary binary protocols
UCN Technology: Computer Science - 2014
16
Part 3
• Component-based Development…
UCN Technology: Computer Science - 2014
17
Component-based Development
• Application tier is usually build from many
components/classes/objects.
• E.g..:
– A typical GUI application with local design has 3 components
packed as 1 EXE and 2 DLL
object
object
Front-end
object
business.dll
data.dll
app.exe
UCN Technology: Computer Science - 2014
18
Assemblies
• .NET packs components in what is known as assemblies
• 1 assembly = 1 or more compiled classes
– .EXE represents an assembly with classes + Main program
– .DLL represents an assembly with classes
code.vb
code.vb
code.cs
Development Tools
assembly
.EXE / .DLL
UCN Technology: Computer Science - 2014
19
CLR-based execution revisited
• All assemblies must be present:
.DLL
.DLL
.DLL
.EXE
OS Process
other FCL
assemblies
JIT Compiler
obj code
obj code
obj code
obj code
Core FCL
assembly
CLR
Underlying OS and HW
UCN Technology: Computer Science - 2014
20
Assembly – where are they?
• How does CLR find the needed assemblies?
• So far this is sufficient:
– DLL-files must be in the same directory as the EXE
– FCL assemblies are in GAC (Global Assembly Cache)
– CLR starts looking in GAC, the in the directory of the EXE…
UCN Technology: Computer Science - 2014
21
GAC?
• GAC = Global Assembly Cache
– C:\Windows or C:\WinNT katalog
• Observations:
– Windows Explorer gives a flat view of GAC.
– Command prompt gives the real view.
– GAC may have different versions of same assembly.
– Some assemblies are pre-JIT-compiled ("native image").
– Hacker-proof by digital signature…
UCN Technology: Computer Science - 2014
22
Summing Up
• .NET architecture is:
– multi-language
– cross-platform
– based on CLR, FCL, and JIT
• Application design is typically multi-tier
• Application design provides component-based development
– .NET components are packed as assemblies
UCN Technology: Computer Science - 2014
23
Summing Up
• .NET is multi-language
– SDK Framework based on C# and VB.NET
– But many other languages are supported as well
• .NET-development is component-based
– Auxiliary classes are implemented as one or more DLLs
– .EXE is implemented using the DLLs.
– if (assembly A is using a class from assembly B)
A must reference B!;
UCN Technology: Computer Science - 2014
24
References
• Textbooks:
– J. Richter, "Applied Microsoft .NET Framework Programming"
– T. Thai and H. Lam, ".NET Framework Essentials“
– Andrew Troelsen.: Pro C# 5.0 and the .NET 4.5 Framework,
6th Ed.
– J. Richter, "Applied Microsoft .NET Framework Programming"
• Web sites:
– http://msdn.microsoft.com/net
– http://www.gotdotnet.com/
UCN Technology: Computer Science - 2014
25
References
• More textbooks:
– T. Archer and A. Whitechapel, "Inside C#" (2nd edition)
– S. Lippman, "C# Primer"
– J. Mayo, "C# Unleashed“
– Anders Hejsberg, Mads Torgersen, Scott Wiltamuth, Peter
Golde: “The C# Programming Language”. Third Edition
UCN Technology: Computer Science - 2014
26
Download