net overview managed code (msil) managed code (msil) clr clr jit compiler jit compiler...

35

Upload: elizabeth-holden

Post on 26-Mar-2015

286 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,
Page 2: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

.NET Overview.NET Overview

• Managed Code (MSIL)Managed Code (MSIL)

• CLRCLR

• JIT CompilerJIT Compiler

• Multi-PlatformMulti-Platform

• Multi-Lingual (C#, VB.NET, Perl, J#, Multi-Lingual (C#, VB.NET, Perl, J#, …)…)

• Last Release: April 2003, Version 1.1Last Release: April 2003, Version 1.1

Page 3: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• ADO.NET (Data Access)ADO.NET (Data Access)

• ASP.NET (Web Applications)ASP.NET (Web Applications)

• Web ServicesWeb Services

• Mobile.NET (Mobile Web Forms)Mobile.NET (Mobile Web Forms)

• Compact.NETCompact.NET

• Speech.NETSpeech.NET

.NET Technologies.NET Technologies

Page 4: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

PerlNET is not the Relativity

theory,but…

Page 5: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

PerlNET: Where To PerlNET: Where To Get?Get?

• PerlNET is part of ActiveState®’s PerlNET is part of ActiveState®’s Perl Development Kit (PDK) Perl Development Kit (PDK) starting from version 4.0.starting from version 4.0.

• Available as 30-days trial or Available as 30-days trial or commercial version.commercial version.

Page 6: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• .NET Framework (available .NET Framework (available without a fee from the Microsoft without a fee from the Microsoft web site)web site)

• ActivePerl starting from build ActivePerl starting from build 628 (available without a fee from 628 (available without a fee from the ActiveState web site).the ActiveState web site).

PerlNET: PerlNET: PrerequisitesPrerequisites

Page 7: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

PerlNET PerlNET ArchitectureArchitecture

PerlNETApplication

PerlNETModule

.NETStatements .NET

Framework

ActivePerl

Core PerlStatements

Statements

Page 8: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Create Perl packages that are fully Create Perl packages that are fully functional both in Core Perl and .NETfunctional both in Core Perl and .NET

• Create monolithic .NET applicationsCreate monolithic .NET applications

• Working with .NET objectsWorking with .NET objects

• Create .NET classes (PerlNET Create .NET classes (PerlNET components)components)

• Extend existing .NET classesExtend existing .NET classes

Features OverviewFeatures Overview

Page 9: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Implement .NET interfacesImplement .NET interfaces

• Create GUI applications using Windows FormsCreate GUI applications using Windows Forms

• Use ADO.NET Framework to work against Use ADO.NET Framework to work against various Data Sourcesvarious Data Sources

• Authoring ASP.NET Web Application with help Authoring ASP.NET Web Application with help of close PerlNET relative - the PerlASPX of close PerlNET relative - the PerlASPX productproduct

Features Overview Features Overview (Cont’d)(Cont’d)

Page 10: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

PerlNET says HelloPerlNET says Hello

# Hello.pluse namespace "System";use PerlNET qw(AUTOCALL);

Console->WriteLine("Hello from PerlNET!");

Page 11: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

# Hello.pluse namespace "System";use PerlNET qw(AUTOCALL);

Console->WriteLine("Hello from PerlNET!");

plc Hello.pl

PerlNET says HelloPerlNET says Hello

Page 12: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Holds helpful constants and Holds helpful constants and functions specific for usage in functions specific for usage in the .NET Environmentthe .NET Environment

• Importing functions and Importing functions and constants syntax:constants syntax:

use PerlNET qw(f1, …, fn);use PerlNET qw(f1, …, fn);

PerlNET ModulePerlNET Module

Page 13: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Calling methods through arrow syntax ( -> )Calling methods through arrow syntax ( -> )

• Accessing properties through hash-reference Accessing properties through hash-reference syntax ( ->{} )syntax ( ->{} )

• Getting and Setting static fields with help of Getting and Setting static fields with help of PerlNET::get() and PerlNET::set() helpers PerlNET::get() and PerlNET::set() helpers respectivelyrespectively

• Constructing new object through the Constructing new object through the new new methodmethod

Working with .NET Working with .NET classesclasses

Page 14: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Working with .NET Classes Working with .NET Classes SampleSample

1 # fileinfo.pl2 use strict;3 use namespace "System";4 use namespace "System.IO";5 use PerlNET qw(AUTOCALL, true)67 # Construct FileInfo object8 my $file = FileInfo->new("c:\\fileinfo.pl");910 # Get Length property11 print "File Length: ", $file->{Length}, "\n";1213 # Copy the file to "newfile.pl" invoking CopyTo method14 $file->CopyTo("newfile.pl", true);1516 # Set LastAccessTime property of the file to current time17 $file->{LastAccessTime} = PerlNET::get("DateTime.Now");1819 # Output $file object20 print $file, "\n";

Page 15: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Provide Interface definition Provide Interface definition for .NET Frameworkfor .NET Framework

• Implement Methods and Implement Methods and Properties exactly as in case of Properties exactly as in case of Core Perl ModuleCore Perl Module

Pure Perl Pure Perl ComponentsComponents

Page 16: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

““=for interface” POD =for interface” POD blocksblocks1 package YAPC::Samples::Car;

23 =for interface4 # special attribute that tells PerlNET that5 # our class is compatible with Core Perl6 [interface: pure]78 # Constructor (should be static)9 static Car Car(int Year);1011 # Method definition (returns string)12 str GetCarInfo();1314 # Property definition (an integer)15 int Year;16 =cut1718 # Implementation goes here19 . . .

Page 17: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Package Package ImplementationImplementation1 # Implementation goes here

2 # Constructor3 sub new4 {5 my ($self, $Model, $Year) = @_;6 my $s = bless {}, $self;7 $s->Year($Year);8 return $s;9 }10 11 # Get information about the car12 sub OutputCarInfo13 {14 my $self = shift;15 my $info = "Year of production: " . $self-

>Year();16 return $info;17 }

Page 18: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Package Implementation Package Implementation (Cont’d)(Cont’d)

1 # The code for setting and getting property2 sub Year3 {4 my($self, $value) = @_;5 # decide if Year is being read or mutated6 if (defined $value)7 {8 # Property is being mutated9 $self->{Year} = $value;10 }11 else12 {13 # Property is being read14 return $self->{Year};15 }16 }

Page 19: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Types in the Interface Types in the Interface DefinitionDefinition

.NET Type(System namespace)

PerlNET type

Boolean bool

Char char

Sbyte sbyte

Int16 short

Int32 int

Int64 long

Byte byte

UInt16 ushort

UInt32 uint

UInt64 ulong

Single float

Double double or num

Decimal decimal

Object any

String str

Page 20: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

.NET Assembly: What’s .NET Assembly: What’s inside?inside?

plc Car.pm –target="library" Car.dll

Page 21: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Download and Install an Download and Install an appropriate moduleappropriate module

• Create interface definition for Create interface definition for component (“=for interface”)component (“=for interface”)

• Perform workarounds if neededPerform workarounds if needed

Steps for Wrapping Steps for Wrapping Existing Perl Existing Perl ComponentsComponents

Page 22: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Wrapping Sample Wrapping Sample (Whitespace.pm)(Whitespace.pm)

1 # Whitespace.pm2 package Whitespace;3 use strict;4 =for interface5 [interface: pure]6 static Whitespace(str infile);7 static Whitespace(str infile, str outfile);8 int detect();9 int cleanup();10 wantarray! str[] Status();11 str error();12 int leadclean();13 int trailclean();14 int indentclean();15 int spacetabclean();16 int eolclean();17 =cut

Page 23: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Wrapping Sample Wrapping Sample (Cont’d)(Cont’d)

18 require Whitespace;19 20 # Convert Perl Hash to array 21 sub Status22 {23 my $self = shift;24 my @arr = %{$self->status()};25 return @arr;26 }

Page 24: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

C# Client ProgramC# Client Program// construct objectWhitespace ws = new Whitespace("input.txt", "output.txt");

// Detect bogus whitespacesint det = ws.detect();string err = ws.error();

// Check if there was an errorif (err != null) {

Console.WriteLine(err);return;

}Console.Write("{0} bogus whitespaces found\n", det);if (det > 0){

// Output information// about detected whitespacesstring[] stat = ws.Status();foreach (string s in stat){

Console.WriteLine(s);}

// Perform input file clean-upws.cleanup();

}

Page 25: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• May Extend existing .NET classesMay Extend existing .NET classes

• May Implement .NET interfacesMay Implement .NET interfaces

• Non-sealedNon-sealed

.NET Components - .NET Components - CharacteristicsCharacteristics

Page 26: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• No [interface: pure] attributeNo [interface: pure] attribute

• Constructor Subroutine has the same Constructor Subroutine has the same name as modulename as module

• First argument for non-static methods is First argument for non-static methods is reference and not hash:reference and not hash:my $this = shift;my $this = shift;

• Unable to access internal object hashUnable to access internal object hash

.NET Components – .NET Components – Implementation IssuesImplementation Issues

Page 27: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• The same characteristics as .NET ComponentsThe same characteristics as .NET Components

• Mark interface definition with the following Mark interface definition with the following attribute:attribute:[interface: mixed][interface: mixed]

• May store Perl structures as private data inside May store Perl structures as private data inside internal hashinternal hash

• Retrieving internal hash as follows:Retrieving internal hash as follows:my ($this, $self, @args) = @_;my ($this, $self, @args) = @_;

Mixed ComponentsMixed Components

Page 28: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• 3 types of PerlNET Components3 types of PerlNET Components

– Pure Perl TypePure Perl Type

– .NET Type.NET Type

– Mixed TypeMixed Type

Components Components Development SummaryDevelopment Summary

Page 29: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• Dynamic Web Server Pages (similar to JSP)Dynamic Web Server Pages (similar to JSP)

• Pages are compiled into .NET assemblies Pages are compiled into .NET assemblies (better performance)(better performance)

• Full separation of code and presentation Full separation of code and presentation layerslayers

• Access all .NET Framework classes from Access all .NET Framework classes from ASP.NET pages codeASP.NET pages code

Web Development and Web Development and ASP.NETASP.NET

Page 30: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

PerlASPX ProductPerlASPX Product

• Adds Perl to family of ASP.NET Adds Perl to family of ASP.NET compliant languagescompliant languages

• Prerequisites:Prerequisites:– IIS Web ServerIIS Web Server– .NET Framework.NET Framework

Important: .NET Framework should be installed after IIS

Page 31: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

ASP.NET Page SampleASP.NET Page Sample1 <!-- RandomCodeBehind.aspx -->2 <%@ Page Language="Perl"

Src="RandomCodebehind.aspx.pm"3 Inherits=MyWebPage %>4 <HTML>5 <BODY>6 <DIV align="center">7 <H2>Random Number Generation</H2>8 <asp:Label RUNAT="SERVER" id="lblNum"/>9 <BR>10 <FORM RUNAT="SERVER">11 <asp:button RUNAT="SERVER“12 id="btnGenerate"13 TEXT="Generate New Number"14 onClick=Generate15 tooltip="Click to generate new random number"/>16 </FORM>17 </DIV>18 </BODY>19 </HTML>

Page 32: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Code-BehindCode-Behind# RandomCodebehind.aspx.pmpackage MyWebPage;

use namespace "System";use namespace "System.Web";use namespace "System.Web.UI";use namespace "System.Web.UI.WebControls";

=for interface[extends: System.Web.UI.Page]public void Generate(Object source, EventArgs e);protected field Label lblNum;

=cut

sub Generate{

my $this = shift;

$this->{lblNum}->{Text} = "Random number is " . int(rand(37));

}

Page 33: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

Running ASP.NET PageRunning ASP.NET Page

Page 34: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,
Page 35: NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,

• ““Programming Perl in the .NET Environment“Programming Perl in the .NET Environment“, book by , book by Yevgeny Menaker, Michael Saltzman and Robert J. Oberg; ISBN: Yevgeny Menaker, Michael Saltzman and Robert J. Oberg; ISBN: 0130652067; Publisher: Prentice Hall PTR0130652067; Publisher: Prentice Hall PTR

• ActiveState PerlNET referenceActiveState PerlNET reference; Web Site: ; Web Site: http://aspn.activestate.com/ASPN/Perl/Reference/Products/PDK/Perhttp://aspn.activestate.com/ASPN/Perl/Reference/Products/PDK/PerlNET/Reference.htmllNET/Reference.html

• ““Make Your Existing Perl Apps .NET-compliant“Make Your Existing Perl Apps .NET-compliant“, article by , article by Yevgeny Menaker, Publisher: DevX Inc.; Yevgeny Menaker, Publisher: DevX Inc.; Web Site: Web Site: http://www.devx.com/dotnet/Article/8015http://www.devx.com/dotnet/Article/8015

• ““PerlNET - An Introduction“PerlNET - An Introduction“, article by Srinivasan Manickam , article by Srinivasan Manickam and Michael Saltzman; Publisher: CoDe Magazine - September-and Michael Saltzman; Publisher: CoDe Magazine - September-October 2002 issue; October 2002 issue; Web site: Web site: http://www.devx.com/codemag/Article/8515http://www.devx.com/codemag/Article/8515

• ““Author Advanced .NET Applications in Perl“Author Advanced .NET Applications in Perl“ article by article by Yevgeny Menaker and Srinivasan Manickam; Publisher: CoDe Yevgeny Menaker and Srinivasan Manickam; Publisher: CoDe Magazine - November-December 2002 issue; Magazine - November-December 2002 issue; Web site: Web site: http://www.devx.com/codemag/Article/10306http://www.devx.com/codemag/Article/10306

• ““.NET speaks Perl now“.NET speaks Perl now“, article by Yevgeny Menaker, Publisher: , article by Yevgeny Menaker, Publisher: DotNetForce.com; Web Site: DotNetForce.com; Web Site: http://www.dotnetforce.com/SiteContent.aspx?Type=10000&Foldehttp://www.dotnetforce.com/SiteContent.aspx?Type=10000&Folder=article&File=article20023107001.xmlr=article&File=article20023107001.xml