Tải bản đầy đủ - 0 (trang)
Chapter 6. Moving from VB 6 to VB 2005

Chapter 6. Moving from VB 6 to VB 2005

Tải bản đầy đủ - 0trang

6.1.Migrate,Replace,Rewrite,orReuse?

Onceanorganizationhasdecidedthatacertainapplicationnolongermeetsits

businessneedsandthatdoingnothingisnolongeranoption,modernization

comesintoplay.[1]Thereareatleastfourwaystoapproachthemodernizationof

aVBapplicationthatshouldbeconsidered.Thedecidingfactorsare:

[1]Thefollowingsectionisanexcerptfromthe"DesigninganApplicationMigrationStrategyfor

VisualBasic6.0toVisualBasic.NET"whitepaperauthoredbyArtinSoft,publishedonMSDNat

http://msdn.microsoft.com/library/default.asp?url=/library/enus/dv_vstechart/html/appmigrationstrat.asp.



Thequalityoftheapplicationcode

Thebusinessvalueoftheapplication

Qualityinthiscaseisaboutthesuitabilityoftheapplicationinbusinessand

technicaltermsandshouldbeassessedinaccordancewiththefollowing

parameters:



Currenteffectivenessofapplication

Generatederrors,numberofworkarounds,andlevelofsupportneeded.



Stabilityandcompletenessofcorebusinessrules

Willtheapplicationlogicremainthesameintheforeseeablefuture?An

underlyingassumptioninthispaperisthatthecurrentsoftwareassetisa

valuableone.Ifthebusinessmodelisgoingtochangesubstantially,then

thisassumptionhastobecalledintoquestion.Inpractice,thecodeisoften

theonlyrepositoryofbusinessrulesandthesearescatteredthroughoutthe

code.Thusanyattemptto"startfromscratch"needstoreconstructand

documenttherequirementscapturedinthecurrentcodeandtakethese



requirementsasthestartingpointforthenegotiationofnewrequirements.



Stageofthelifecycle

Intheearlierstagesofitslifecycle,anapplicationwilllikelymapcloselyto

itsfunctionalityrequirements,althoughtheplatformcouldbeobsolete.



Developmentenvironment

Thedevelopmentteamandtheenvironmentalcapabilitiesrequiredto

successfullydeliveramodernizationprojectneedtobeassessed.Here,the

developer'sknowledgeregardingtheapplicationsourcecode,thetarget

technologies,andtheresolutionofmodernizationissuesidentifiedduring

thecodeassessmentarecrucial.Ingeneral,itisrecommendedthat

developersexecutingtheprojectbefullytrainedinVB2005.Additionally,

otherfactorssuchastheexistenceoftestcasesmustbeconsidered.

Thebusinessvalueoftheapplicationisanotherimportantconsiderationandthis

willdependtoaconsiderabledegreeonitsuniqueness.Ifthequalityofthe

applicationispoorandthereiscomparablefunctionalityavailableinathirdpartysoftwarepackage,itmakessensetoreplaceit.

Therearefourbroadmodernizationoptionsmigrate,re-use,rewrite,or

replaceanyoneofwhichcanbetherightchoiceeitherforacompleteapplication

orforpartsofanapplication.Figure6-1showshowthedecisionfactors

correlatewiththemodernizationpath.



Migrate

IftheVBapplicationmeetscurrentbusinessneedsanditsqualityisgood,

chancesaretheapplicationcanbeeffectivelymodernizedtocontinueto

meettheneedsofthebusinessinthefuture.Insuchcases,amigration

processcanbeappliedandthenfunctionalityandbusinessreachcanbe



addedasneeded.Inthischapter,whenwerefertoamigrationoran

upgrade,wearereferringtoanautomaticallyassistedmigrationusingthe

MicrosoftVisualBasicUpgradeWizardthatisintegratedinVisualStudio

.NET(see"UpgradingVB6Applications,"laterinthischapter).

Figure6-1.Modernizationoptionschart



Reuse

Therearetwopossibilitieshere,oneinwhichtheapplicationiscenteredon

athird-partypackage/DBMSalready,andtheotherinwhichthebusiness

hasdevelopeditsownapplicationfromscratch.IftheVB6application

portfolioislargelycenteredonathird-partypackage,thenthebestwayto

moveforwardmaybetoupgradetothelatestversionandusewrapping

techniquestoprovidetherequiredreachandotherfunctionality

improvements.Forin-houseapplications,considerwrappingtheapplication

piecesandintegratingthemwithnewdevelopment.



Rewrite

Thekeyassethereisthebusinessrulesanddatastructures;theapplication

istheproblem.Applicationminingandanalysisofcodelogicanddata

structuresisrequiredtoprovidethestartingpointfortherewrite.



Replace

Lookforasuitablepackageoroutsource.Bepreparedtomakechangesto

thebusinessmodeltomeetthepackagehalfway.



6.1.1.MakingtheRightDecision

Upontheinitiationoftheprojectyoushouldprepareafeasibilityanalysisthat

providesanassessmentofthebusinessandtechnicalqualityoftheapplication.

Thefollowingseriesofchecklistspresentssomeofthequestionsthatyoushould

considerwhenchoosingoneofthealternatives.

6.1.1.1.Migrate

Belowisthechecklistforchoosingtomigrate:

Existingapplicationfulfillscurrentbusinessneeds

Moderatefunctionalitychangesneededinexistingapplication

Highoperationalcostsofexistingapplication

Needtomigratetothe.NETFrameworkforstrategicreasons

Futurevisionincludestheuseofwebservicesorwebaccess

Stablecodebaseandatestsuitethatcertifiesit

Resourcesneededtomaintainoramendapplicationsonexistingplatform

aredifficulttofind

6.1.1.2.Reuse

Belowisthechecklistforchoosingtoreuse:

Businessrulessatisfactory

Lowoperationalcostsofexistingapplication

Simplewebaccessrequired,allowingawrappingsolution

HaveresourcestokeepcoreVisualBasic6.0applicationmaintained



Off-the-shelfsoftwarecentraltoexisting,relyonathirdpartytosupport

andmaintain

6.1.1.3.Rewrite

Belowisthechecklistforchoosingtorewrite:

Functionalitydoesnotmeetbusinessneeds

Nooff-the-shelfsolutioncomesclosetomeetingneeds

Poorqualitycodeinexistingplatformandhighmaintenancecosts

Canaffordtime,cost,anddisruptioninvolved

NeedtousetheMicrosoft.NETFrameworkforstrategicreasons

Futurevisionincludestheuseofwebservices

6.1.1.4.Replace

Belowisthechecklistforchoosingtoreplace:

Applicationsignificantlyoutoflinewithbusinessneeds

Willingtomakechangestobusinessmodeltofitoff-the-shelfsolutionor

availabilityofoff-the-shelfsolutionthatcloselyfityourbusiness

requirements

Canaffordtime,cost,anddisruptioninvolved

Theprecedingquestionscanapplytocompleteapplicationsortodiscreteparts

ofapplications.Typicallyalargeapplicationwillrequireuseofmorethanone

modernizationalternative.Whendecidingthebestpathforaparticularpartofan

application,bearinmindthatmanydeveloperswillinvariablysaythatrewriting

yourapplicationisthebestsolutionifyouneedtoupgradeit,becausethey

usuallyfeeltheycanwriteitbetterthesecondtime,armedwiththebenefitof

hindsight.Certainlyiftheapplicationispoorlydesigned,rewritingitcanbea

goodoptionbecauseitprovidesanopportunitytodoitright.However,

examiningthebusinesscaseforupgrading,rewriting,replacing,orleavingthe

applicationinVisualBasic6.0alwaysprovidessomeinterestinginsights.

Iftheapplicationalreadysupportsyourbusinessneeds,doesn'trequire



enhancementstoitsfunctionality,andifyoualreadyhavesupportstafftrainedin

VB6,thenleavingtheapplicationinVB6isagoodoption.Nevertheless,your

organizationneedstoassesstherisksofthisapproachinlightofcurrentlifecycle

guidelinesfromMicrosoftandtheopportunitiesthattheVB2005and.NET

frameworkoffertoyourorganization.

IfthereisabusinessneedtomovetheapplicationtoVB2005,thenthereisa

needtolookmorecloselyatrewritingversusupgrading.Upgradingthe

applicationusingtheVB6toVB2005migrationtoolisacost-effectivewayto

migrateyourapplications.OnepopularreasonformovinganapplicationtoVB

2005istoeitherweb-enabletheapplication,ortoenhanceanexistingwebenabledapplicationwithASP.NETfeaturessuchastracing,flexiblestate

management,scaleabledataaccess,andimprovedperformance.Asmentioned

previously,rewritingsometimesyieldsanimprovedapplication.Thedownsideis

thatthedevelopmentcostwillbemuchgreaterthanupgrading.

Therearesomebenefitstorewriting.Rewritingallowsyoutocorrectapoor

design,andCOMobjectscanbereplacedwith.NETobjectsthataremore

scaleableanddon'trequireregistrationduringdeployment.Theflipsideofthisis

thatupgradingismuchquickerandCOMobjectscanbereplacedwith.NET

objectsaftertheupgradehastakenplace.

Inbrief,youhavetodecideonhowtomoveforwardwithyourmodernization

project.IfyoudecidethatthebestsolutionistoleavetheapplicationinVB6,

thenyouaredone!Ontheotherhand,ifyouhaveassessedthatthebestsolution

istorewriteyourapplication,thenthebestpieceofadviceistomakesurethat

youfollowanaccepteddevelopmentmethodologyandthatyoureallylookback

attheissueyourcurrentapplicationhastomakesureyoucanleveragethat

knowledgewhenmovingforward.Ifyouthinkyourcurrentapplicationandits

sourcecodehavevalue,andthatbymovingitto.NETyoucanextendits

lifecycle,thenyouhavedecidedthatautomaticallyassistedmigrationisthebest

solutionforyourcode.Finally,youmaydecidetogoforacombinationofthe

abovesolutions,asisthecaseformostmodernizationprojects.



6.2.UsingCOMObjectsinVB2005

OneoftheprimaryreasonsVB6programmersandtheircompaniesarereluctant

tomigratetoVB2005isthehugeinvestmentstheyhavemadeindeveloping

COMcomponents.However,COMcomponentscontinuetobesupportedin

.NET.Inthefollowingsections,youwillseehowyoucanuselegacyCOM

componentsinyourVB2005applications.

ThemostdirectwaytouseCOMobjectsinVB2005istouseCOMInterop.

Althoughapplicationsthatrununderthe.NETFrameworkcanonlyworkwith

.NETcomponents,.NETallowsyoutouseyourexistingCOMcomponentsby

meansofaRuntimeCallableWrapper(RCW).WhenyouuseRCWtointeract

withaCOMobject,anassemblyisusedasawrapperfortheCOMobject.The

RCWactsasabridgebetweentheunmanagedcode(theCOMobject)and

managedcode(your.NETapplication),andallcommunicationswiththeCOM

objectareroutedthroughthisclass(seeFigure6-2).

Figure6-2.RuntimeCallableWrapper



COMobjectsareunmanagedcode,thereforeyouneedtorememberto

freeuptheirresourceswhentheyarenolongerinuse.



ToillustratethesupportofCOMin.NET,let'sconsiderasimpleexample.



SupposeyouwanttodisplayaPDFfileinaVB2005Windowsapplication.To

doso,youcanmakeuseoftheAdobeAcrobatBrowserDocumentcontrol

(whichisaCOMobject)installedonyoursystem(thecomponentisinstalledon

yourcomputerwhenyouinstalltheAdobeAcrobatReader).

First,createanewWindowsapplication.TousetheAdobeCOMcomponent,

lookforitandselectitfromthelistofCOMcomponentsonyoursystem.Tosee

thelist,clicktheCOMtagoftheAddReferencedialoginSolutionExplorerin

VisualStudio2005,asshowninFigure6-3.ClickOK.

DraganddroptheAdobeAcrobat7.0BrowserDocument,whichisnowlocated

intheToolboxundertheAllWindowsFormstab,ontoyourWindowsForm

(Form1,unlessyouhaverenamedit).TheresultisshowninFigure6-4.

Figure6-3.AddaCOMcomponenttoyourproject



Figure6-4.FillingtheformwiththeAdobeCOMcomponent



TodisplayaPDFdocumentusingthecontrol,double-clickontheWindows

FormandcodetheLoadeventasshowninExample6-1.

Example6-1.Form1Loadeventhandler



PrivateSubForm1_Load(_





ByValsenderAsSystem.Object,_







ByValeAsSystem.EventArgs)_







HandlesMyBase.Load,_















MyBase.Load







AxAcroPDF1.LoadFile("C:\MiniReader.pdf")



EndSub



Thereisn'tmuchdifferenceincoding;yourCOMcomponentisusedmuchlikea

.NETcomponent.



BesidesexposingusingCOMcomponentsina.NETapplication,you

canalsouse.NETComponentsinaCOMapplicationviatheCOM

CallableWrapper(CCW).TheCCWisusedtomarshalcallsbetween

managedandunmanagedcode(seeFigure6-5),therebyallowing

COMapplicationstomakeuseof.NETcomponents.



Figure6-5.COMCallableWrapper



Figure6-6showswhathappenswhentheapplicationisrun.

Figure6-6.UsingtheCOMcomponent



NotonlydoesCOMinteropmakeiteasytouseCOMcomponentsinyourVB

2005application,italsodoesawaywiththeerror-pronetaskofinstallingand

registeringCOMcomponentsontargetcomputersthroughanewfeatureknown

asRegFreeCOM(Registration-FreeCOM).



RegFreeCOMrunsonlyonWindowsXPandlaterreleasesofthe

Windowsoperatingsystem.



UsingRegFreeCOM,youcandeployanapplicationthatusesaCOM

componentwithoutregisteringitontheuser'smachine,thusavoidingthe

notoriuscollectionofproblemscommonlyreferredtoas"DLLHell."RegFree

COMevenallowsyoutorunmultipleversionsofaCOMcomponentonthe

samemachine.



RegFreeCOMworksbyautomaticallygeneratingamanifestfromthe

COMcomponent'stypelibraryandcomponentregistrationonthe

developer'smachine.Therefore,whileitisnotrequiredtoinstallthe

componentontheendusers'machines,acopymustberegisteredon

thedeveloper'smachine.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 6. Moving from VB 6 to VB 2005

Tải bản đầy đủ ngay(0 tr)

×