Lab 5Creating a Foundational Module.docx

上传人:b****8 文档编号:9100955 上传时间:2023-02-03 格式:DOCX 页数:12 大小:214.21KB
下载 相关 举报
Lab 5Creating a Foundational Module.docx_第1页
第1页 / 共12页
Lab 5Creating a Foundational Module.docx_第2页
第2页 / 共12页
Lab 5Creating a Foundational Module.docx_第3页
第3页 / 共12页
Lab 5Creating a Foundational Module.docx_第4页
第4页 / 共12页
Lab 5Creating a Foundational Module.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

Lab 5Creating a Foundational Module.docx

《Lab 5Creating a Foundational Module.docx》由会员分享,可在线阅读,更多相关《Lab 5Creating a Foundational Module.docx(12页珍藏版)》请在冰豆网上搜索。

Lab 5Creating a Foundational Module.docx

Lab5CreatingaFoundationalModule

Lab5:

CreatingaFoundationalModule

Purpose

Estimatedtimetocompletethislab:

25minutes.

Inthislab,youwillusetheSmartClientDevelopmentguidancepackagetoaddafoundationalmoduletoyousmartclientapplicationsolution.Youwillalsocreateanewglobalservicethatwillsimulatearealprintingservice.

Aftercompletingthislab,youwillbeableto:

Understandthecomponentsofafoundationalmodule

Addanewfoundationalmoduletoasmartclientapplicationusingtheguidancepackage.

Createaglobalservice

Preparation

Beforeproceedingwiththislab,youmustinstallandconfiguretheprerequisitesoftware.Formoreinformation,seethetopicStartHere.

Openthesolutionforthepreviouslab(eithertheonethatyoucreatedortheendsolutionforthatlab.)

Background:

FoundationalModules

Afoundationalmoduleisamodulethateitherprovidesservicestotheshellandothermodules,providesalayout,orboth.ItdoesnotimplementausecaseorcontainaWorkItem.Anexampleofafoundationalmoduleisamodulethatcontainsinfrastructureservices,likecachingorloggingservices.SinceafoundationalmoduledoesnotcontainaWorkItem,alltheservicescreatedwithinafoundationalmoduleareregisteredasglobalserviceswiththerootWorkItem.

Exercise1:

CreatingaNewFoundationalModule

Inthisexerciseyoucreateafoundationalmodulewhichwillprovideaprintingserviceforallthemodulesintheapplication.TheShippingModulemodulewillconsumeittoprintpackingslipsandshippinglabelsforsalesorders.

Task1.UsetheGuidancePackagetoaddanewFoundationalModule

Inthistaskyouwilladdafoundationmoduletoyourapplication.TheguidancepackageincludestheVisualStudiotemplatenamedAddFoundationalModule(C#).Thistemplateunfoldsanewclasslibraryprojectforthemodule.

1.InSolutionExplorer,right-clicktheSourcesolutionfolder,pointtoSmartClientSoftwareFactory,andthenclickAddFoundationalModule(C#).TheAddNewProjectdialogboxappearswiththeAddFoundationalModule(C#)templateselected.

2.EnterPrintingModuleastheNameandsettheLocationtotheSourcefolderofthesolution.

ClickOK.TheguidancepackagedisplaystheAddFoundationalModulewizard.

Figure1

AddFoundationalModuleWizard

3.DeselecttheoptionCreateaninterfacelibraryforthismodule.Ifyouselectthisoption,therecipewillcreateanadditionalprojecttocontaintheelementsthatprovidethepublicinterfacetotheassembly.Formoreinformationaboutseparatingtheinterfacefromtheimplementationofmodules,seetheModuleInterfaceSeparationpatternintheSmartClientSoftwareFactorydocumentation.

4.DeselecttheoptionCreateaunittestprojectforthismodule.Ifyouselectthisoption,therecipewillcreateatestprojectforthemodulewithtestclassesforyourmodulecomponents.Inthislabyouwillnotwriteunittestsforthemodule.

5.Optionally,selecttheoptionShowdocumentationafterrecipecompletesifyouwanttoseeasummaryoftherecipeactionsandsuggestednextstepsaftertherecipecompletes.

6.ClickFinish.TheguidancepackagewillgenerateanewclasslibraryprojectnamedPrintingModule.

Figure2

PrintingModulemoduleinSolutionExplorer

Therootfolderoftheprojectcontainsaclass,Module.TheModuleclassderivesfromtheCompositeUIApplicationBlockclassModuleInit.TheCompositeUIApplicationBlockcallstheLoadmethodofthisclassonstartup.

Theprojectalsocontainsthefollowingfolders:

Constants.ThisfoldercontainsfourclassesnamedCommandNames,EventTopicNames,UIExtensionSiteNames,andWorkspaceNames.Youcanmodifytheseclassestodefinemodule-specificidentifiersforyourcommands,eventtopics,UIExtensionSites,andWorkSpaces.

Services.Youusethisfoldertostoretheimplementationofglobalservices.

TherecipealsoaddsthefollowingXMLentryforthemoduletotheprofilecatalogoftheapplication(definedinthefileShell\ProfileCatalog.xml).ThismeansthattheCompositeUIApplicationBlockwillloadthemoduleatapplicationinitializationtime.

XML

TheCompositeUIApplicationBlockloadsmodulesintheordertheyarespecifiedintheprofilecatalogfile,unlessyouexplicitlydefineinter-moduledependencies.Thus,theShippingModulemodulewillbeloadedbeforethePrintingModule.ThismightleadtoproblemsiftheShippingModuleinstantiatesaserviceduringmoduleinitializationthathasadependencyinacomponentthatbelongstothePrintingServicemodule.Toavoidthisproblem,youcanspecifymoduledependenciesbyarrangingmodulesintosectionsandestablishingdependenciesbetweenthesections.Whenyoucreateasmartclientsolution,twosectionsaredefinedbydefault:

Services.Includeinthissectionmodulesthatexposeglobalservicestoothermodules.Typicallyyouwillincludefoundationalmodulesinthissection.

Apps.Includeinthissectionmodulesthatmighthavedependenciesonservicespublishedbyothermodules.Typicallyyouwillincludebusinessmodulesinthissection.

InthenextstepyouwillmovethePrintingModulemoduletotheServicessectionsothattheCompositeUIApplicationBlockloadsitbeforetheShippingModulemodule.

7.MovetheelementforthePrintingModulemoduleintotheServicessection,asshowninthefollowingcode.

XML

Note:

Youcanalsodefinedependenciesforaparticularmoduleincodeusingthe[ModuleDependency]attribute.Formoreinformation,seeCreatingaModuleintheSmartClientSoftwareFactoryhelp.

Task2.MoveBusinessEntitiestoInfrastructure.Interfaceproject

Inthenexttask(Task3)youwilladdaprintingservicetothePrintingModulemodule.Thisservicewillsimulatetheprintingofasalesorder,thusitsmethodswillreceiveanOrderentityasaparameter.SincetheOrderclassisdefinedintheShippingModuleproject,youwouldneedtoaddareferencetoitinthePrintingModuleproject.ToavoidhavingareferencetotheShippingModuleprojectinthePrintingModuleproject,inthistaskyouwillmovetheOrderandOrderLineItementitiestotheInfrastructure.Interfaceproject.

8.InSolutionExplorer,selecttheOrder.csandOrderLineItem.csfilesintheBusinessEntitiesfolderoftheShippingModuleproject,cutthem,andpastethemintheBusinessEntitiesfolderintheInfrastructure.Interfaceproject.

EventhoughyoumovedthesourcecodefilestotheInfrastructure.Interfaceproject,theclasses´namespaceisstillAdventureWorks.ShippingModule.BusinessEntities.InthefollowingstepsyouwillrenamethenamespacetoAdventureWorks.Infrastructure.Interface.BusinessEntities.

9.GototheEditmenu,pointtoFindandReplaceandthenselectQuickReplace.

10.SetAdventureWorks.ShippingModule.BusinessEntitiesintheFindwhatfield.

11.SetAdventureWorks.Infrastructure.Interface.BusinessEntitiesintheReplacewithfield.

12.IntheLookindropdownlist,setEntireSolution.

13.ClickReplaceAll.13occurrencesshouldbereplaced.

Task3.Implementtheprintingservice

InthistaskyouwillcreateasimpleprintingservicethatwillbeconsumedbytheShipNewOrderViewview.

14.InSolutionExplorer,right-clicktheServicesfolderinthePrintingModuleproject,pointtoAddandthenclickNewItem.

15.FromtheTemplateswindow,selectInterfaceandsetthenametoIPrintingService.

16.ClickAdd.

17.Addthefollowingusingstatementtothefile.YouwilluseittorefertotheOrderandOrderLineItemclasses.

C#

usingAdventureWorks.Infrastructure.Interface.BusinessEntities;

18.Changetheinterfacesignaturetomakeitpublic:

C#

publicinterfaceIPrintingService

19.AddamethodnamedPrintPackingSliptotheinterfacebody.Thismethodwillbeusedtoprintthepackingslipsforanorder.

C#

voidPrintPackingSlip(Orderorder);

20.AddamethodnamedPrintShippingLabelstotheinterfacebody.Thismethodwillbeusedtoprinttheshippinglabesforanorder.

C#

voidPrintShippingLabels(Orderorder);

21.InSolutionExplorer,right-clicktheServicesfolderinthePrintingModuleproject,pointtoAddandthenclickClass.

22.SettheclassnametoLocalPrintingServiceandthenclickAdd.

23.Addthefollowingusingstatementsatthetopofthefile:

C#

usingSystem.Windows.Forms;

usingAdventureWorks.Infrastructure.Interface.BusinessEntities;

24.ChangetheclasssignaturetomakeitpublicandtoimplementtheIPrintingServiceinterface:

C#

publicclassLocalPrintingService:

IPrintingService

25.ImplementthePrintPackingSlipmethod.Inthismethod,displayamessageboxasdemonstratedinthefollowingcode.

C#

publicvoidPrintPackingSlip(Orderorder)

{

MessageBox.Show(String.Format("PackingslipforOrder#{0}senttoprinter...",order.OrderId.ToString()));

}

26.ImplementthePrintShippingLabelsmethod.Inthismethod,displayamessageboxasshowninthefollowingcode.

C#

publicvoidPrintShippingLabels(Orderorder)

{

MessageBox.Show(String.Format("ShippinglabelsforOrder#{0}senttoprinter...",order.OrderId.ToString()));

}

Task4.RegisterthePrintingServiceasaGlobalService

Inthistask,youwillregistertheprintingserv

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1