Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: ".NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,"— Presentation transcript:

1

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, J#, …) Multi-Lingual (C#, VB.NET, Perl, J#, …) Last Release: April 2003, Version 1.1 Last Release: April 2003, Version 1.1

3 ADO.NET (Data Access) ADO.NET (Data Access) ASP.NET (Web Applications) ASP.NET (Web Applications) Web Services Web Services Mobile.NET (Mobile Web Forms) Mobile.NET (Mobile Web Forms) Compact.NET Compact.NET Speech.NET Speech.NET.NET Technologies

4 PerlNET is not the Relativity theory, but…

5 PerlNET: Where To Get? PerlNET is part of ActiveState®s Perl Development Kit (PDK) starting from version 4.0. PerlNET is part of ActiveState®s Perl Development Kit (PDK) starting from version 4.0. Available as 30-days trial or commercial version. Available as 30-days trial or commercial version.

6 .NET Framework (available without a fee from the Microsoft web site).NET Framework (available without a fee from the Microsoft web site) ActivePerl starting from build 628 (available without a fee from the ActiveState web site). ActivePerl starting from build 628 (available without a fee from the ActiveState web site). PerlNET: Prerequisites

7 PerlNET Architecture

8 Create Perl packages that are fully functional both in Core Perl and.NET Create Perl packages that are fully functional both in Core Perl and.NET Create monolithic.NET applications Create monolithic.NET applications Working with.NET objects Working with.NET objects Create.NET classes (PerlNET components) Create.NET classes (PerlNET components) Extend existing.NET classes Extend existing.NET classes Features Overview

9 Implement.NET interfaces Implement.NET interfaces Create GUI applications using Windows Forms Create GUI applications using Windows Forms Use ADO.NET Framework to work against various Data Sources Use ADO.NET Framework to work against various Data Sources Authoring ASP.NET Web Application with help of close PerlNET relative - the PerlASPX product Authoring ASP.NET Web Application with help of close PerlNET relative - the PerlASPX product Features Overview (Contd)

10 PerlNET says Hello # Hello.pl use namespace "System"; use PerlNET qw(AUTOCALL); Console->WriteLine("Hello from PerlNET!");

11 # Hello.pl use namespace "System"; use PerlNET qw(AUTOCALL); Console->WriteLine("Hello from PerlNET!"); plc Hello.pl PerlNET says Hello

12 Holds helpful constants and functions specific for usage in the.NET Environment Holds helpful constants and functions specific for usage in the.NET Environment Importing functions and constants syntax: Importing functions and constants syntax: use PerlNET qw(f1, …, fn); PerlNET Module

13 Calling methods through arrow syntax ( -> ) Calling methods through arrow syntax ( -> ) Accessing properties through hash-reference syntax ( ->{} ) Accessing properties through hash-reference syntax ( ->{} ) Getting and Setting static fields with help of PerlNET::get() and PerlNET::set() helpers respectively Getting and Setting static fields with help of PerlNET::get() and PerlNET::set() helpers respectively Constructing new object through the new method Constructing new object through the new method Working with.NET classes

14 Working with.NET Classes Sample 1# fileinfo.pl 2use strict; 3use namespace "System"; 4use namespace "System.IO"; 5use PerlNET qw(AUTOCALL, true) 6 7# Construct FileInfo object 8my $file = FileInfo->new("c:\\fileinfo.pl"); 9 10# Get Length property 11print "File Length: ", $file->{Length}, "\n"; 12 13# Copy the file to "newfile.pl" invoking CopyTo method 14$file->CopyTo("newfile.pl", true); 15 16# Set LastAccessTime property of the file to current time 17$file->{LastAccessTime} = PerlNET::get("DateTime.Now"); 18 19# Output $file object 20print $file, "\n";

15 Provide Interface definition for.NET Framework Provide Interface definition for.NET Framework Implement Methods and Properties exactly as in case of Core Perl Module Implement Methods and Properties exactly as in case of Core Perl Module Pure Perl Components

16 =for interface POD blocks 1package YAPC::Samples::Car; 2 3=for interface 4# special attribute that tells PerlNET that 5# our class is compatible with Core Perl 6[interface: pure] 7 8# Constructor (should be static) 9static Car Car(int Year); 10 11# Method definition (returns string) 12str GetCarInfo(); 13 14# Property definition (an integer) 15int Year; 16=cut 17 18# Implementation goes here 19...

17 Package Implementation 1# Implementation goes here 2# Constructor 3 sub new 4 { 5 my ($self, $Model, $Year) 6 my $s = bless {}, $self; 7 $s->Year($Year); 8 return $s; 9 } # Get information about the car 12 sub OutputCarInfo 13 { 14 my $self = shift; 15 my $info = "Year of production: ". $self->Year(); 16 return $info; 17 }

18 Package Implementation (Contd) 1 # The code for setting and getting property 2 sub Year 3 { 4 my($self, $value) 5 # decide if Year is being read or mutated 6 if (defined $value) 7 { 8 # Property is being mutated 9 $self->{Year} = $value; 10 } 11 else 12 { 13 # Property is being read 14 return $self->{Year}; 15 } 16 }

19 Types in the Interface Definition.NET Type (System namespace) PerlNET type Booleanbool Charchar Sbytesbyte Int16short Int32int Int64long Bytebyte UInt16ushort UInt32uint UInt64ulong Singlefloat Doubledouble or num Decimaldecimal Objectany Stringstr

20 .NET Assembly: Whats inside? plc Car.pm –target="library"Car.dll

21 Download and Install an appropriate module Download and Install an appropriate module Create interface definition for component (=for interface) Create interface definition for component (=for interface) Perform workarounds if needed Perform workarounds if needed Steps for Wrapping Existing Perl Components

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

23 Wrapping Sample (Contd) 18 require Whitespace; # Convert Perl Hash to array 21 sub Status 22 { 23 my $self = shift; 24 = %{$self->status()}; 26}

24 C# Client Program // construct object Whitespace ws = new Whitespace("input.txt", "output.txt"); // Detect bogus whitespaces int det = ws.detect(); string err = ws.error(); // Check if there was an error if (err != null) { Console.WriteLine(err); return; } Console.Write("{0} bogus whitespaces found\n", det); if (det > 0) { // Output information // about detected whitespaces string[] stat = ws.Status(); foreach (string s in stat) { Console.WriteLine(s); } // Perform input file clean-up ws.cleanup(); }

25 May Extend existing.NET classes May Extend existing.NET classes May Implement.NET interfaces May Implement.NET interfaces Non-sealed Non-sealed.NET Components - Characteristics

26 No [interface: pure] attribute No [interface: pure] attribute Constructor Subroutine has the same name as module Constructor Subroutine has the same name as module First argument for non-static methods is reference and not hash: First argument for non-static methods is reference and not hash: my $this = shift; Unable to access internal object hash Unable to access internal object hash.NET Components – Implementation Issues

27 The same characteristics as.NET Components The same characteristics as.NET Components Mark interface definition with the following attribute: Mark interface definition with the following attribute: [interface: mixed] May store Perl structures as private data inside internal hash May store Perl structures as private data inside internal hash Retrieving internal hash as follows: Retrieving internal hash as follows: my ($this, Mixed Components

28 3 types of PerlNET Components 3 types of PerlNET Components –Pure Perl Type –.NET Type –Mixed Type Components Development Summary

29 Dynamic Web Server Pages (similar to JSP) Dynamic Web Server Pages (similar to JSP) Pages are compiled into.NET assemblies (better performance) Pages are compiled into.NET assemblies (better performance) Full separation of code and presentation layers Full separation of code and presentation layers Access all.NET Framework classes from ASP.NET pages code Access all.NET Framework classes from ASP.NET pages code Web Development and ASP.NET

30 PerlASPX Product Adds Perl to family of ASP.NET compliant languages Adds Perl to family of ASP.NET compliant languages Prerequisites: Prerequisites: –IIS Web Server –.NET Framework Important:.NET Framework should be installed after IIS

31 ASP.NET Page Sample 1 2 Page Language="Perl" Src="RandomCodebehind.aspx.pm" 3 Inherits=MyWebPage %> Random Number Generation

32 Code-Behind # RandomCodebehind.aspx.pm package 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)); }

33 Running ASP.NET Page

34

35 Programming Perl in the.NET Environment, book by Yevgeny Menaker, Michael Saltzman and Robert J. Oberg; ISBN: ; Publisher: Prentice Hall PTR Programming Perl in the.NET Environment, book by Yevgeny Menaker, Michael Saltzman and Robert J. Oberg; ISBN: ; Publisher: Prentice Hall PTR ActiveState PerlNET reference; Web Site: /PerlNET/Reference.html ActiveState PerlNET reference; Web Site: /PerlNET/Reference.html /PerlNET/Reference.html /PerlNET/Reference.html Make Your Existing Perl Apps.NET-compliant, article by Yevgeny Menaker, Publisher: DevX Inc.; Make Your Existing Perl Apps.NET-compliant, article by Yevgeny Menaker, Publisher: DevX Inc.; Web Site: PerlNET - An Introduction, article by Srinivasan Manickam and Michael Saltzman; Publisher: CoDe Magazine - September-October 2002 issue; PerlNET - An Introduction, article by Srinivasan Manickam and Michael Saltzman; Publisher: CoDe Magazine - September-October 2002 issue; Web site: Author Advanced.NET Applications in Perl article by Yevgeny Menaker and Srinivasan Manickam; Publisher: CoDe Magazine - November- December 2002 issue; Author Advanced.NET Applications in Perl article by Yevgeny Menaker and Srinivasan Manickam; Publisher: CoDe Magazine - November- December 2002 issue; Web site: speaks Perl now, article by Yevgeny Menaker, Publisher: DotNetForce.com; Web Site: der=article&File=article xml.NET speaks Perl now, article by Yevgeny Menaker, Publisher: DotNetForce.com; Web Site: der=article&File=article xml der=article&File=article xml der=article&File=article xml


Download ppt ".NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,"

Similar presentations


Ads by Google