28
The .NET Framework

EAD Lecture - Introduction to the DotNET Framework

Embed Size (px)

DESCRIPTION

vghmbmnm

Citation preview

  • The .NET Framework

    The .NET Framework

    Page *AgendaWhat is the .NET framework?

    An overview of the CLR the .NET virtual machine

    A comparison between the CLR and the JVM

    A brief intro to C#

    Hello World!Command LineGUI

    The .NET Framework

    Page *What is the .NET framework?A software platform

    Language neutral

    Provides a runtime and a set of common libraries for writing and executing written programs in any compliant language.

    The runtime is called the .NET CLR (Common Language Runtime) similar to the Java Runtime

    The .NET Framework

    Page *Common Language RuntimeIncludes a virtual machine (similar to the Java VM)

    The CLR provides a secure sandboxed environment for running MSIL (Microsoft Intermediate Language) code similar to Java byte code.Activates objectsPerforms security checksAllocates memory for the objectsExecutesKeeps track of references to the objectsHandles garbage collection

    The .NET Framework

    Page *Inside The .NET FrameworkCommon Language RuntimeExecutes code, maintains security, handles component plumbing and dependenciesSecure, integrated class librariesUnifies programming models across languagesEnables cross-language integrationFactored for extensibilityDesigned for toolsASP.NETHigh-productivity environment for building and running Web services

    The .NET Framework

    Page *The .NET FrameworkA comparison with the Java platformOne LanguageMultiple languages Same base class library, allowing knowledge reuse.

    The .NET Framework

    Page *.NET Language Support Common Language Specification First class support for all CLS compliant languages

    Microsoft provided languagesVisual Basic, C#, C++, J#, JScript

    3rd-party provided languagesAPL, Cobol, Component Pascal, Eiffel, Fortran, Haskell, Mercury, Oberon, Oz, Perl, Python, RPG, Scheme, Smalltalk, Standard ML, Ruby, Delphi and the list is growing!

    The .NET Framework

    Page *The .NET Framework Class LibrarySpans All Programming LanguagesEnables cross-language inheritance and debuggingIntegrates well with tools

    Is Object-Oriented and ConsistentEnhances developer productivity by reducing the number of APIs to learn

    Has a Built-In Common Type Systemhttp://msdn.microsoft.com/en-us/library/zcx1eb1e(v=vs.110).aspxIs ExtensibleMakes it easy to add or modify framework features

    Is SecureAllows creation of secure applications

    The .NET Framework

    Page *Common Classes.NET Framework Class LibrarySystem GlobalizationResourcesThreadingRuntimeSerialization

    The .NET Framework

    Page *LifecycleCompilation and ExecutionSource CodeCompilationAt installation or the first time each method is calledLanguage CompilerAssemblyExecutionJIT CompilerNativeCodeCode (IL)Metadata

    The .NET Framework

    Page *AssembliesAssemblyManifestMultiple Managed Modules and Resource Files Are Compiled to Produce an AssemblyManaged Module(MSIL and Metadata)Managed Module(MSIL and Metadata)Resource Files

    The .NET Framework

    Page *The Process of Managed Execution Class LoaderJIT Compiler with optional verificationExecutionSecurity ChecksEXE/DLL (MSIL and metadata)Class Libraries (MSIL and metadata)Trusted, pre-JITed code onlyCall to an uncompiled methodRuntime EngineManaged Native CodeCompilerSource Code

    The .NET Framework

    Build System MS BuildThe underlying build engine in Visual Studio 2005Fully open and published XML file format for describing buildVisual Studio 2005 build is fully customizableYou extend the build by writing managed code (tasks and loggers)You dont need the IDE to build Visual Studio projectsMSBuild.exe MyProj.proj /property:Configuration=Debug

    Page *

    The .NET Framework

    The Building BlocksOverall architecture of MSBuild and Team BuildMSBuild (core components)EngineTasksLoggers.TARGETSTeam Foundation ServerSource controlWork item trackingTeam BuildWeb ServiceTasksLoggers.TARGETS.NET Framework 2.0 RedistPage *

    The .NET Framework

    Team BuildBuild ExecutionGet sources from source controlPage *

    The .NET Framework

    Page *DeploymentRequires the .NET Runtime to Be Installed on Local ComputerCan Be Run Directly from a File Server or Copied LocallyMake No Registry EntriesCannot Break Another ApplicationEliminate DLL HellCan Be Uninstalled by Deleting Locally Copied File(s)

    The .NET Framework

    ClickOnce DeploymentWindows-based rich client application deployed as a web application. Page *

    The .NET Framework

    Application Security.NET Framework Security FeaturesCode Access SecurityRole-Based SecurityCryptographySecuring ASP.NET Web ApplicationsSecuring ASP.NET Web Services

    Page *

    The .NET Framework

    Page *The C# languageVery similar to Java70% Java, 10% C++, 5% Visual Basic, 15% new

    As in Java

    Object-orientation (single inheritance)InterfacesExceptionsThreadsNamespaces (like Packages)Strong typingGarbage CollectionReflectionDynamic loading of code...As in C++

    (Operator) OverloadingPointer arithmetic in unsafe codeSome syntactic details

    The .NET Framework

    Page *New Features in C#Really new (compared to Java)

    References and output parametersObjects on the stack (structs)EnumerationsUnified Type System (CTS)VersioningAttributesSyntactic Sugar

    DelegatesIndexersOperator overloadingforeach statementsBoxing/unboxing

    The .NET Framework

    Page *Source codeAssemblyDLL or EXECompilationCommand Linecsc /out:parceltracker.dll /debug+ /target:library parceltracker.csCompilercsc.exe

    The .NET Framework

    Page *Hello C# WorldCommand LineFile HelloWorld.csuses the namespace Systementry point must be called Mainoutput goes to the consolefile name and class nameneed not be identicalusing System;class HelloWorld{ static void Main() { Console.WriteLine("Hello, C# World"); }}

    The .NET Framework

    Page *Compiler OptionsCommand LineCompile Directly from a Command Prompt Window

    Use /t to indicate target

    Use /reference to reference assembliesC:\>csc HelloWorld.csC:\>csc /t:exe HelloWorld.csC:\>csc /t:exe /reference:assemb1.dll HelloWorld.cs

    The .NET Framework

    Page *CompilingVisual Studio

    The .NET Framework

    Page *Hello WorldGUIpublic partial class Form1 : Form{ public Form1() { InitializeComponent(); } private void buttonSayHello_Click(object sender, EventArgs e) { MessageBox.Show("Hello World!"); }}

    The .NET Framework

    Page *http://www.c-sharpcorner.comhttp://www.thecodeproject.comhttp://windowsforms.nethttp://www.gotdotnet.com/http://msdn.microsoft.com/netframework/using/Further readingThe C# Language Specification ECMA 334Professional C# 2005C# 2.0, The Complete Reference Herbert SchildtProfessional .NET Framework 2.0 Joe DuffyGood links

    The .NET Framework

    Page *Summary

    What You DidWrite a command line clientWrite a GUI clientWhat You LearnedAn overview of the .NET frameworkAn introduction to the C# programming language

  • End of Lesson

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    Objectives:Provide an overall view of the .NET framework and its main language C#, finishing with a hands-on example of using the command line compiler and visual studio to create a simple Hello World application.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: The .NET framework is a platform (not a language)SLIDE BUILDS: None SLIDE SCRIPT:The .NET framework is easily comparable to the Java platform: Its basically the same idea with a smart twist.

    Main difference: A language neutral platform as opposed to a Java only platform. Advantage: Write your code in your favorite language and call it from any other compatible language. Avoid language wars!

    The .NET framework provides a large set of libraries that can be used from any compatible language, allowing knowledge reuse. Learn the libraries once and reuse the knowledge in any language.

    ADDITIONAL INFORMATION FOR PRESENTER:

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    A sandbox is a testing environment that isolates untested code changes and outright experimentation from the production environment or repository, in the context of software development including Web development and revision control. IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Understanding the FrameworkSLIDE BUILDS: None SLIDE SCRIPT:The .NET Framework exposes numerous classes to the developer. These classes allow the development of rich client applications and Web-based applications alike. In the above slide, these classes have been divided into four areas.ASP.NET provides the core Web infrastructure such as Web Forms for UI-based development and Web services for programmatic interface development. User interface development on the Windows platform can be done using Windows Forms.ADO.NET and XML provide the functionality for data access.Finally, the core base classes provide infrastructure services such as security, transaction management, etc.

    ADDITIONAL INFORMATION FOR PRESENTER:

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Both platforms are very similar, but .NET has a few more bells and whistlesSLIDE BUILDS: None SLIDE SCRIPT:The CLR is the parallel of the JVM Base class libraries are almost identical (i.e. String handling, collections)ADO.NET(ActiveX Data Object) is an evolution of ADO and the parallel of JDBC.ASP.NET is similar to servlets and jsp combined. The new JSF (Java Server Faces) framework is like ASP.NET drag and drop support for web development.Windows Forms vs AWT/Swing. Windows Forms have built-in support for data-binding..NET is platform independent in theory. So far, Microsoft not attempting to provide support for other operating systems. However, open source projects like Mono are attempting to provide a CLR for different operating systems. All in all though, Java has been well tested on many platforms and is stable. .NET cannot claim to be the same so farThere are additional languages targeting the JVM such as Scala and JRuby. However, the JVM was never designed from the ground up for this purpose.

    ADDITIONAL INFORMATION FOR PRESENTER:

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Microsoft and 3rd party languages supported.

    SLIDE BUILDS: NoneSLIDE SCRIPT:The .Net platform is truly language neutral. All .net languages are first class. All have complete access to the entire platform. Its simply not the case that one language has more or different capabilities than another. So when you move to the .net platform you can completely leverage all of you existing skills.

    In order to ensure this, Microsoft has defined the common language specification. This has been done in conjunction with a number of partners. This is a spec of functionality that you can expect to find in any language that has been implemented on top of the .net platform. Because the CLS must be the union of all capabilities of all languages targeting .net, there are certainly some features of individual language that are not part of the CLS definition. For example pointers are not a part of the CLS because they couldnt be directly consumed by all other .net languages. But this doesnt mean that C++ doesnt have pointers of course C++ has pointers. It just means that you can use pointers internally in a C++ app, or you could even expose pointers in a C++ component youve written, but then that component may not be useable by all other .net languages jscript, for example.

    Microsoft provides four .Net languages. Third parties are providing a wealth of others. Again, this goes to show the truly multi-lingual nature and design that was implemented with .NET from the bottom up.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: A common class library allows knowledge reuse

    SLIDE BUILDS: NoneSLIDE SCRIPT:Use the same class libraries in your favorite languageWrite your class in C# and inherit in VBThe base class library itself is quite flexible

    The common type system defines how types are declared, used, and managed in the common language runtime, and is also an important part of the runtime's support for cross-language integration.Reference Types and Value Types Five categories of types Classes(ref), Interfaces(ref), Structures(val), Enumerations(val) and Delegates(ref), These five categories are falling into value types and reference types.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: A look at how the BCL is organized

    SLIDE BUILDS: NoneSLIDE SCRIPT:The diagram provides an idea of how the framework is put together. Things in the System namespace are low-level classes that provide much of the .NET functionality. On top of that, there is a layer of classes targeted at data access, including database, and XML. Then, theres the classes that are specific to certain kinds of user interfaces.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Lifetime of a .NET application.

    SLIDE BUILDS: 4SLIDE SCRIPT:You can author your code in any .NET language. These include the Microsoft languages of C#, C++, VB.NET, J#, etc. In addition, there are a number of 3rd party .NET languages available, including COBOL and Eiffel.

    BUILD 1:Regardless of the language, when you hit the compile button, it isnt really doing a compile in the traditional sense. Its really more like a translate.

    BUILD 2:The output of a compile is written to an assembly.

    BUILD 3:The assembly doesnt contain machine code, but another language called Microsoft Intermediate Language (MSIL). You can think of this as .NETs own platform independent assembly language. This is packaged into a file with a traditional .DLL or .EXE extension, but in .NET speak, this is referred to as an assembly.

    BUILD 4:When you execute this code, the framework runs the IL through a Just In Time compiler, which produces native code that is optimized for the platform where the code is executing. The JIT happens once, and the native code is cached for subsequent executions. This makes JIT fundamentally different that a Java VM. The only thing that ever actually executes in the .NET framework is native machine code.

    There is also an option to use a utility called NGEN to pre-JIT your code so that it doesnt have to be compiled on execution. However, with NGEN, you loose the ability to have the same IL optimized for the current platform.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Assemblies are the smallest unit of code distribution, deployment and versioningSLIDE BUILDS: NoneSLIDE SCRIPT:Source code and resources can be compiled and packaged into an assemblyAn assembly can be a DLL or EXEHence an assembly is somewhat comparable to a JAR archive in Java.Assemblies are the smallest unit of code distribution, deployment and versioning.This is different from java, where the smallest unit of distribution is an individual class. Advantages include better manageability, support for versioning which Java classes do not have, and easier deployment.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: How the runtime engine worksSLIDE BUILDS: NoneSLIDE SCRIPT:

    SPEAKER NOTES:This slide should not go into a detailed explanation of these features, but concentrate on providing a rough idea of language differences.

    IFS Training IFS Applications 2003

    MSBuild is a build tool that helps automate the process of creating a software product, including compiling the source code, packaging, testing, deployment and creating documentations. With MSBuild, it is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed.MSBuild was previously bundled with .NET Framework; starting with Visual Studio 2013, however, it is bundled with Visual Studio insteadMSBuild acts on MSBuild project files which have a similar XML syntax to Apache Ant or NAnt. Even though the syntax is based upon well-defined XML schema.Visual Studio uses MSBuild to load and build managed projects. The project files in Visual Studio (.csproj,.vbproj, vcxproj, and others) contain MSBuild XML code that executes when you build a project by using the IDE.VS Build is fully customizable we can change platforms and other things from the project properties > Build options

    More Info- http://msdn.microsoft.com/en-us/library/dd393574.aspx

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    A Target contains a set of tasks for MSBuild to execute. The focus of MSBuild is the result Target specified when invoking MSBuild with the project fileTask -A Task is a command which is executed in order to complete a Target.

    You can use Team Foundation Build to automatically compile, test, and deploy your application. Your build system can automatically run builds when developers check in code (for example, as part of a Continuous Integration strategy) or according to a schedule (for example, a nightly Build Verification Test build). Team Foundation Build compiles your code by using MSBuild. IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    DLL hell-It's when Application A installs a Shared DLL vers 1.0, Application B comes and updates the Shared DLL to vers 1.1 which should be compatible but there are slightly different behaviors, then App A stops working correctly and reinstalls vers 1.0 then App B stops working

    The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components and for applications running on the platform that have opted to use the registry.IFS Training IFS Applications 2003

    Simply stated, a ClickOnce application is any Windows Presentation Foundation, Windows Forms, or console application published using ClickOnce technology. You can publish a ClickOnce application in three different ways: from a Web page, from a network file share, or from media such as a CD-ROM. A ClickOnce application can be installed on an end user's computer and run locally even when the computer is offline, or it can be run in an online-only mode without permanently installing anything on the end user's computer.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    Code Access Security

    1.Type-safe code - is code that accesses types only in well-defined, allowable ways. For example, given a valid object reference, type-safe code can access memory at fixed offsets that correspond to actual field members. If the code accesses memory at arbitrary offsets outside the range of memory that belongs to that object's publicly exposed fields, it is not type-safe.

    2.Imperative and declarative syntax - Code that targets the common language runtime can interact with the security system by requesting permissions, demanding that callers have specified permissions, and overriding certain security settings (given enough privileges). You use two forms of syntax to programmatically interact with the .NET Framework security system: declarative syntax and imperative syntax. Declarative calls are performed using attributes; imperative calls are performed using new instances of classes within your code. Some calls can be performed only imperatively, others can be performed only declaratively, and some calls can be performed in either manner.

    3.Secure class libraries: A secure class library uses security demands to ensure that the library's callers have permission to access the resources that the library exposes. For example, a secure class library might have a method for creating files that would demand that its callers have permissions to create files.

    4.Secure class libraries -A secure class library uses security demands to ensure that the library's callers have permission to access the resources that the library exposes. For example, a secure class library might have a method for creating files that would demand that its callers have permissions to create files.

    Role-Based Security

    .NET Framework role-based security provides System.Security.Permissions.PrincipalPermission objects that enable the common language runtime to perform authorization in a way that is similar to code access security checks. The PrincipalPermission class represents the identity or role that the principal must match and is compatible with both declarative and imperative security checks.

    Cryptography

    The base for all symmetric algorithms is SymmetricAlgorithm, which is inherited by the following algorithms:AesDESRC2RijndaelTripleDES

    Securing ASP.NET Web ApplicationsASP.NET, in conjunction with Microsoft Internet Information Services (IIS), can authenticate user credentials such as names and passwords using any of the following authentication methods:Windows: Basic, digest, or Integrated Windows Authentication (NTLM or Kerberos).Forms authentication, in which you create a login page and manage authentication in your application.Client Certificate authenticationASP.NET controls access to site information by comparing authenticated credentials, or representations of them, to NTFS file system permissions or to an XML file that lists authorized users, authorized roles (groups), or authorized HTTP verbs.

    Securing ASP.NET Web ServicesWeb services created using ASP.NET can choose their security options from the authentication and authorization options offered by ASP.NET or customized SOAP-based security. ASP.NET operates in conjunction with Internet Information Services (IIS) to provide several authentication and authorization options. It is also possible to create custom authentication options, such as the use of SOAP headers.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: A brief comparison to similar languagesSLIDE BUILDS: NoneSLIDE SCRIPT:

    SPEAKER NOTES:This slide should not go into a detailed explanation of these features, but concentrate on providing a rough idea of language differences.

    IFS Training IFS Applications 2003

    Boxing/UnboxingThis difference has the following consequences. First of all, in C#, primitive types can define methods, such as an override of Object's ToString() method. In Java, this task is accomplished by the primitive wrapper classes.Secondly, in Java an extra cast is needed whenever one tries to directly dereference a primitive value, as it will not be boxed automatically. The expression ((Integer)42).toString() will convert an integer literal to string in Java while 42.ToString() performs the same operation in C#. This is because the latter one is actually an instance call on the primitive value 42, while the former one is an instance call on an object of type java.lang.Integer.

    EnumerationsIn Java, the enumeration type is a class, and its values are objects (instances) of that class. The only valid values are the ones listed in the enumeration. The enumeration type may declare fields, allowing each individual enumerated value to reference additional data associated uniquely with that specific value. The enumeration type may also declare or override methods, or even implement interfaces

    Enumerations in C# are implicitly derived from the Enum type that again is a value type derivative. The value set of a C# enumeration is defined by the underlying type that can be a signed or unsigned integer type of 8, 16, 32 or 64 bits. The enumeration definition defines names for the selected integer values and is syntactic sugar.[15][16][17] By default the first name is assigned the value 0 (zero) and the following names are assigned in increments of 1. Any value of the underlying primitive type is a valid value of the enumeration type, though an explicit cast may be needed to assign it.

    Attributes enable you to embed information about a type or method in the metadata which describes that type or method. And also we can create our own attributes.

    http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java

    http://msdn.microsoft.com/en-us/library/aa288454(v=vs.71).aspxIFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Understanding compilationSLIDE SCRIPT:As a developer, you will write code in the language of your choice. BUILD: CompilerThis source code is then be passed through a compiler such as the Microsoft Visual Basic compiler (Vbc.exe) or the Microsoft C# compiler (Csc.exe). Its worth noting that other compilers are available (for example, Microsoft Visual C++) and others are likely to be developed by third-party manufacturers in the future.BUILD: AssemblyOnce compiled, the resultant EXE or DLL, referred to as an assembly, will contain the managed code (MSIL), resources and metadata.Example command line to compile a C# module into an assembly:csc /out:parceltracker.dll /debug+ /target:library parceltracker.cs

    ADDITIONAL INFORMATION FOR PRESENTER:

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    KEY MESSAGE: Writing a simple command line applicationSLIDE BUILDS: NoneSLIDE SCRIPT:

    SPEAKER NOTES:This slide should not go into a detailed explanation of these features, but concentrate on providing a rough idea of language differences.

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003

    IFS Training IFS Applications 2003