• No results found

.NET Experiences. Chris Manhard and David Hearn OSI Software, Inc. Copyright 2002 OSI Software, Inc. All rights reserved.

N/A
N/A
Protected

Academic year: 2021

Share ".NET Experiences. Chris Manhard and David Hearn OSI Software, Inc. Copyright 2002 OSI Software, Inc. All rights reserved."

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)

Copyright © 2002 OSI Software, Inc. All rights reserved.

.NET Experiences

Chris Manhard and David Hearn OSI Software, Inc.

(2)

Agenda

• Microsoft .NET overview

• PI Application Framework and .NET • Development Experiences

• Using .NET with existing PI tools • Opinions and Recommendations

(3)

Microsoft’s .NET Goals

• Unifies programming models

• Dramatically simplifies development

• Supports multiple programming languages • Provides robust execution environment

(4)

Microsoft .NET Platform

• Consistent programming model

• Includes clients, servers, services

(5)

Microsoft .NET Architecture

Operating System

Common Language Runtime Base Class Library

ADO.NET and XML ASP.NET

Web Forms Web Services Mobile Internet Toolkit

Windows Forms Common Language Specification

VB C++ C# JScript V isu al S tudio .NE T

(6)

Unify Programming Models

Windows API

.NET Framework

Consistent API availability regardless of language and programming model

ASP

Stateless, Code embedded in HTML pages

MFC/ATL

Subclassing, Power, Expressiveness

VB Forms

RAD, Composition, Delegation

(7)

The .NET Evolution – Before COM

Before COM, applications were completely separate entities with little or no integration

Applicatio n

Code and data structures

(8)

The .NET Evolution - COM

COM provides a way for components to integrate. However, each

component must provide the “plumbing” and

objects cannot directly interact.

(9)

The .NET Evolution - Now

With the .NET Framework common language runtime, components are built on a common substrate. No

“plumbing” is needed and objects can directly interact

(10)

Robust Environment

• Automatic lifetime management – All objects are garbage collected • Exception handling

– Error handling 1st class and mandatory

• Type-safety

– No buffer overruns, unsafe casts, or uninitialized variables – Base types are treated as true objects

• Deployment and management – Assemblies, side-by-side execution – No more DLL hell!

(11)

Assemblies

• Unit of deployment

– One or more files, independent of packaging – Self-describing via manifest

• Versioning

– Provided by compiler use of attributes

– Policy per-application as well as per-machine • Security boundary

– Assemblies are granted permissions

– Methods can demand proof that a permission has been granted to entire call chain

• Types named relative to assembly

(12)

PI Data from a Web Service Demo

• What is a Web Service • Creating a web service • Demo using PI OLE-DB

(13)

PI Application Framework Background

• Developing PI Application Framework • Business Logic Layer

• Distributed Architecture

• Desire to publish / consume data across the various channels

(14)

PI Application Framework C++

Development

• Used C++ and ATL template library

• Common code abstracted to templates • Override default template methods

(15)

PI Application Framework C#

Development

• Direct access to objects

• Methods declared as ‘internal’ or ‘public’ • Single inheritance of base class

• Reduction in code

• Improved error handling • Faster compile times

(16)

Reduction in Code – iterating a COM

object using C++

// Create the PISDK object PISDK::IPISDKPtr spPISDK;

spPISDK.CreateInstance("PISDK.PISDK");

PISDK::ServersPtr spPIServers= spPISDK->Servers;

// Enumerate over the collection using sequential access HRESULT hr;

IEnumVARIANTPtr spEnum= spPIServers->Get_NewEnum(); do

{

ULONG numFetched; CComVariant varItem;

hr= spEnum->Next(1, &varItem, &numFetched); if(hr == S_OK)

{

PISDK::ServerPtr spPIServer(varItem);

MessageBox(NULL, spPIServer->Name, "PI Server", MB_OK); }

}

(17)

Reduction in Code – iterating a COM

object using C#

// Create the PISDK object

PISDK.IPISDK piSDK= new PISDK.PISDKClass();

// Enumerate over the collection using sequential access foreach(PISDK.Server item in piSDK.Servers)

{

MessageBox.Show(item.Name, "PI Server"); }

(18)

Error Handling in C++

try

{ // Code which might throw an exception.

PISDK::ServerPtr spPIServer= spPIServers->GetDefaultServer(); if( spPIServer == NULL )

return AtlReportError(CLSID_PIAF,

“Failed to get default server”, IID_Server, hres); }catch(…)

{

return AtlReportError(CLSID_PIAF,

“Failed to get default server”); }

(19)

Error Handling in C#

PISDK.Server piServer= spPIServers.DefaultServer; if( piServer == null)

(20)

Interop With COM

COM Only COM Client .NET Client COM Server .NET Server .NET Only

Unmanaged Code Managed Code

PIAF SDK PISDK

ASP/IIS

(21)

Invoking PI-SDK from .NET

• Use References, just as in VB6 • Use PISDK 1.2 if calling from IIS

• Some parameters must be ‘boxed’ in C#

namedValues.Add(“Level”, 0.0)

becomes

Object val = 0.0;

namedValues.Add(“Level”, ref val);

• Must create top level PISDK object

(22)

Web Form Demo with PISDK

(23)

Calling the PI API from .NET

1. Must use locking if calling from within IIS 2. Run Migration Utility on PIAPI32.BAS

3. Add Structure Layout Attributes

<struct layout sequential>

4. Change ANY types to defined types

5. Change buffers from Strings to StringBuilder 6. Rename variable as appropriate

(24)

Hints and Tips

• Learn the .NET framework • Option Strict On in VB.NET

• Use StringBuilder instead of String

• Don’t modify a collection while iterating it • Add ASPNET user account bug

• Use ComSourceInterfaces attribute with ‘typeof’ parameter when exposing events.

(25)

Top 10 Favorite Things in .NET

• C# is easy transition • Remoting capabilities

• ASP.NET simplifies web development • Rich Framework • Exception Handling • Com Interop / PI • Code Editor • Development Environment • Compile Speed • Unified Development

(26)

Top 10 Least Favorite Things in .NET

• Information overload • WinForms is step back

from VC6

• All tools not yet integrated • VB Migration Tool • Poor support of VS6 resource editor • Versioning – Side by Side hell?

• Install – not as easy as advertised

• Beta Software

• Can’t Write ActiveX Controls

(27)

When to use Microsoft .NET

• Building Distributed Applications (n-tier)

– Especially client and business tiers

• Creating Web Services • Creating ASP Web Site

(28)

When NOT to use Microsoft .NET

• Large Traditional Applications

• Smaller Applications, especially if distributing .NET Framework (21 Meg) is an issue, or

Win95 support required. • Creating ActiveX Controls • Real-Time Requirements

• External Toolset Requirements

(29)

Summary

What is .NET? • Related Presentations

– PI Application Framework, (351) Wed. 8:00 AM

– Application Module Example Using the Application Framework (112) Mon. 1:50 PM, (352) Wed. 8:50 AM

– Sigmafine 4.0 (342) Wed. 8:50 AM

• Demo Room (Tuesday, 1:00 pm to 6:00 PM) – PI Application Framework

– Application Framework Applications – Sigmafine 4.0

References

Related documents

Collected stories Gimpel the fool to the Letter writer, Isaac Bashevis Singer, Ilan Stavans, 2004, Fiction, 789 pages.. Isaac Bashevis Singer’s first collection of stories, Gimpel

Note: For more information about Python sample contents, refer to Cloud Connect Web Services Python Sample ReadMe available in this folder... Installing Sentinel Cloud Services

SMS Processing Wizard is a tool for updating Microsoft Systems Management Server 2003 and Microsoft System Center Configuration Manager 2007 permissions for the selected objects

To investigate the association between identified gene and keratoconus, we per- formed a case-control analysis using data from 179 patients with keratoconus from Yokohama City

To convert a sequence of image files using Kinoma Producer, simply add the first file in the sequence to the list of files to be encoded in the main Kinoma Producer window. These

technology can absorb up to 80% of the Patient access and revenue cycle workflow, saving users time and saving the hospital money... touchless processing means users only

Action group choice 1: Natural resources management and conservation Action group choice 2 or other: Species richness and biogeography. [email protected]

Finally, by reminding OMT scholars about the assumptions underlying foundational works on performativity, and through facilitating the emergence of conversations between