Tải bản đầy đủ - 0 (trang)
Chapter 3. Property Paths and Response Shapes

Chapter 3. Property Paths and Response Shapes

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

Classpropertyassignedtoeachiteminthedatabase.Ignoring

constraintsandsuch,youcouldturnamessageintoacontact

bysimplyupdatingtheItemClassfieldfromIPM.Noteto

IPM.Contact.Butwhathappenswhenyoudothat?Well,allof

theotherpropertiesstaythesame.Younowhaveacontact

thathasaDateSent.Maybethatisn'ttooweird.Butgointhe

otherdirection.Changethecontactintoamessage.Poof!Now,

youhaveamessagethathasahomephonenumber.Weird.

Torectifythis,youcandooneofthefollowing:

Treateachrowasacollectionofpropertiesandignorethe

factthattherowsrepresentmessages,contacts,andso

forth.ThisisessentiallytheapproachthatWebDistributed

AuthoringandVersioning(WebDAV)takes.

Usebusinesslogicandforceanobjectparadigmontopof

thetablesothatdataisvalidatedgoingbothintoandoutof

thetable.Assuch,amessagecouldneverhaveahome

phonenumberandwouldbeconsidered"corrupt"ifitdid.

Compromiseandtakeahybridapproachinwhichyouhave

bothofthefollowing:

Well-formedbusinesslogicthattreatrowsasspecific

itemtypesandperformsvalidationonreadandwrite

Aflexibledatacollectionviewinwhichrowsarejusta

collectionofanypropertiesyouthrowatit.

Althoughallthreeoptionshavetheirgoodandbadpoints,the

developmentteamchosethethirdoptionforExchangeWeb

Services.Let'slookattheresults.



Chapter3.PropertyPathsandResponse

Shapes

Standardobject-orientedprogramming(OOP)methodsfocuson

objects,hencethename.Attheproxyclasslevel,Exchange

WebServicesprogramminghasItemTypeobjects,MessageType

objects,andthelike.Althoughitiscertainlytruethatyouare

dealingwithobjects,someinterestingthingsaregoingon

behindthescenesofwhichyoushouldbeaware.



AnItembyAnyOtherName

TheMicrosoftExchangeServer2007Storemanagesoneor

moredatabases.Asingledatabasehasanitemtablethat

containsallitemswithinthemailboxesmanagedbythat

database.ConsiderTable3-1.[1]

[1]Thissimplisticexplanationdoesnotreflecttheactualworkingswithina



database.However,itissufficientforthepurposesofthischapterandremoves

detailsthatarenotpertinenttoourcurrentdiscussion.







Table3-1.ConceptualItemTable

ItemClass ParentId Subject DateSent Home

Phone



Message IPM.Note



Fjldsajfdklsa Hereit

is!



Contact IPM.Contact Jfkdlajfd



Jane

Dow



01/02/2004 NULL

NULL



1234567890



Theitemtablecontainstwoitems:amessageandacontact.

Noticethateachrowofthetablehasthepotentialtohavedata

ineachofitscells,whichbecomesinterestingwhenyou

considerthateachrowhasa"nature"toit.Amessageis

conceptuallydifferentthanacontact,andacontactis

conceptuallydifferentthanameetingrequest.Fromthe

ExchangeStore'sviewpoint,thisdistinctionismadebytheItem



Classpropertyassignedtoeachiteminthedatabase.Ignoring

constraintsandsuch,youcouldturnamessageintoacontact

bysimplyupdatingtheItemClassfieldfromIPM.Noteto

IPM.Contact.Butwhathappenswhenyoudothat?Well,allof

theotherpropertiesstaythesame.Younowhaveacontact

thathasaDateSent.Maybethatisn'ttooweird.Butgointhe

otherdirection.Changethecontactintoamessage.Poof!Now,

youhaveamessagethathasahomephonenumber.Weird.

Torectifythis,youcandooneofthefollowing:

Treateachrowasacollectionofpropertiesandignorethe

factthattherowsrepresentmessages,contacts,andso

forth.ThisisessentiallytheapproachthatWebDistributed

AuthoringandVersioning(WebDAV)takes.

Usebusinesslogicandforceanobjectparadigmontopof

thetablesothatdataisvalidatedgoingbothintoandoutof

thetable.Assuch,amessagecouldneverhaveahome

phonenumberandwouldbeconsidered"corrupt"ifitdid.

Compromiseandtakeahybridapproachinwhichyouhave

bothofthefollowing:

Well-formedbusinesslogicthattreatrowsasspecific

itemtypesandperformsvalidationonreadandwrite

Aflexibledatacollectionviewinwhichrowsarejusta

collectionofanypropertiesyouthrowatit.

Althoughallthreeoptionshavetheirgoodandbadpoints,the

developmentteamchosethethirdoptionforExchangeWeb

Services.Let'slookattheresults.



InExchangeWebServices,Properties

AreKing

PropertiesinExchangeWebServicestakeonasignificantrole,

evenoutsideoftheobjectsonwhichtheyreside.Whenwerefer

toaproperty,wearetalkingaboutoneofthecolumnsinthe

itemtable,suchasthesubject.Apropertyasanentitycanbe

referencedbyusingapropertypath.Apropertypathhas

nothingtodowithanyspecificvalueonanyspecificitem.The

propertyissimplyapieceofmetadata.Comparingitwith

standardOOPprinciples,apropertypathistoapropertyasa

classistoaninstance.Comparingitwithrelationaldatabases,a

propertypathistoapropertyasacolumndefinitionistoa

specificvaluewithinthatcolumn.

ExchangeWebServicesexposesseveraldifferenttypesof

propertypathsasshowninTable3-2.

Table3-2.PropertyPathsinExchangeWebServices

PropertyPath

SchemaType

Comments

Type

FieldURI



PathToUnindexedFieldType Apropertypath

thatisseenasa

singleentity;

mightcontain

multiplevalues.

Examplesarethe

subject,thedate

anitemwas

created,andso

on.



IndexedFieldURI



PathToIndexedFieldType



Apropertypath

thatisseenasa

collectionof

related

properties;



requiresa"key"

todetermine

exactlywhich

propertywithin

thecollectionis

beingreferredto.

Examplesarea

contact'se-mail

addresses,phone

numbers,and

physical

addresses.

ExtendedFieldURI PathToExtendedFieldType Apropertypath

thatreferstoa

MAPIproperty

usingMAPI

naming

constructssuch

aspropertytags.

Extended

propertypaths

areusedto

accessproperties

thatarenot

exposedthrough

theschema.

ExceptionFieldURI PathToExceptionFieldType Apropertypath

thatisusedonly

inresponsesto

indicate

propertieswithin

errorXML.



UnindexedPropertyPaths

Anunindexedpropertypathisthemostcommonpropertypath



typethatyouwillencounter.Thepropertythatagiven

unindexedpropertypathreferstoisspecifiedwithintheschema

bytheUnindexedFieldURITypeenumeration,meaningthat

thereisapredefined,limited,andnonextensiblesetof

propertiesthatcanbereferencedasanunindexedproperty

path.Inaddition,theenumerationvalueissufficientto

determineexactlywhatpropertyisbeingreferenced,whichisin

contrasttoindexedpropertypathsthatrequirebothan

enumerationvalueandakeytodeterminewhichpropertyis

beingreferenced.[2]

[2]Wewilldiscussindexedpropertypathsinthenextsection.



Althoughtheschematypeforanunindexedpropertypathis

PathToUnindexedFieldType,youusuallyencounteritwithinXML

bythenameofitsglobalinstance,FieldURI.






TheFieldURIelementhasasingleattributecalledFieldURIthat

mustcontainavaluefromtheUnindexedFieldURIType

enumeration.AppendixC,"MAPIPropertyMapping,"containsa

detailedlistofallofthesevaluesalongwithnotesunderlying

suchthingsasMAPIproperties.

Herearesomeexamples:















Eachenumerationvalueisprefixedbythetypetowhichit

applies.Thatprefixhelpsyouquicklydeterminewhich



enumerationvaluetouseinyourunindexedpropertypathfor

theitemtypeinquestion.Thatbeingsaid,aclasshierarchy

doesexistamongitemtypes.Descendantclassescantypically

useunindexedpropertypathsthatareapplicabletotheir

parents.RefertotheitemclasshierarchyshowninFigure3-1.

Figure3-1.Itemclasshierarchy

[Viewfullsizeimage]



TheclasshierarchyinFigure3-1showsthatanypropertywith

an"item:"prefixshouldbeapplicabletoanyitemtype

descendant.However,becausebothMessageTypeand

CalendarItemTypearepeers,propertieswitha"message:"

prefixcannotbeusedoncalendaritems,andpropertieswitha

"calendar:"prefixcannotbeusedonamessage.Refertothe

folderclasshierarchyshowninFigure3-2.

Figure3-2.Folderclasshierarchy



Theunindexedpropertypathsforfoldersbreakthenicely

definedrelationshipdescribedearlier.Ifyouexaminethe

schemaintypes.xsd,younoticethatallunindexedproperty

pathsforfolderpropertiesstartwiththe"folder:"prefix,

suggestingthatonlyFolderType,SearchFolderType,and

TasksFolderTypecanusethoseproperties.However,thisisnot

thecase.Inreality,allexcepttwoofthe"folder:"prefixed

propertiesareapplicabletoBaseFolderTypeandthereforetoall

descendanttypes.Thetwoexceptionsarefolder:UnreadCount

andfolder:SearchParameters.

Theconceptofanunreadcount,whichrepresentsthenumber

ofitemswithinthefolderthathavenotyetbeenread,makes

goodsenseforanormalfolder(FolderType),searchfolder

(SearchFolderType),and,toalesserextent,tasksfolder

(TasksFolderType).However,itdoesn'tmakeanysensefora

calendarfolder(CalendarFolderType)orcontactsfolder

(ContactsFolderType).Therefore,ExchangeWebServices

developerscreatedtheBaseFolderTypetypethatsurfacesall

folderpropertiesexceptfolder:UnreadCountandplacesthe

unreadcountonFolderType.Tobeconsistent,ExchangeWeb

Servicesdevelopersshouldhaveprefixedtheotherproperties

with"basefolder:",butalas,theydidnot.



Table3-3providesthelistoffolderpropertyenumerationvalues

andthefolderclassestowhichtheyapply.

Table3-3.FolderPropertyPathApplicability

EnumerationName

Actsasifitwas

folder:FolderId



basefolder:FolderId



folder:ParentFolderId



basefolder:ParentFolderId



folder:DisplayName



basefolder:DisplayName



folder:UnreadCount



Theonlyonethatiscorrect!



folder:TotalCount



basefolder:TotalCount



folder:ChildFolderCount



basefolder:ChildFolderCount



folder:FolderClass



basefolder:FolderClass



folder:SearchParameters



searchfolder:SearchParameters



folder:ManagedFolderInformation basefolder:managedFolderInformation



IfyouuseproxyclassestotalktoExchangeWebServices,itis

usefultoaddanoverloadedconstructortothe

PathToUnindexedFieldTypeclasssothatyoucanassignthe

enumerationvaluewhenyoucreatetheunindexedproperty

path.

CodeView:



///

///Extensionoftheunindexedfielduritype

///


publicpartialclassPathToUnindexedFieldType

{

///

///Constructor

///


///enumvaluethatindica



///propertywearedealingwith

///

publicPathToUnindexedFieldType(UnindexedFieldURITypepropert

{

this.fieldURIField=propertyUriEnumValue;

}

///

///Defaultconstructorneededforserializationtowork

///


///

publicPathToUnindexedFieldType(){}

}

























[3]Theauto-generatedproxiesdonotincludeadefaultconstructorsincethere



werenootherconstructors.Sinceanon-defaultconstructorisbeingadded,the

implicitdefaultconstructor"magically"disappearsandyoumustexplicitlyadd

thedefaultconstructorsothattheXMLserializerhasawaytoinstantiatethe

typeduringdeserialization.



Thissimplifiesthingsslightly.Asaresult,youcandefine

unindexedpropertypathsinasingleline(ignoringwordwrap):



PathToUnindexedFieldTypesubject=new

PathToUnindexedFieldType(UnindexedFieldURIType.i



Ifyoudidn'tmakethischange,itwouldrequiretwolines.



PathToUnindexedFieldTypesubject=newPathToUnindexedFieldType

subject.FieldURI=UnindexedFieldURIType.itemSubject;



Everylittlebithelps.



Noticethattheenumerationvaluenamesintheproxyclassare

missingthecolonbetweentheapplicableclassandthe

property.Therefore,"item:Subject"becomes"itemSubject"and

soforth.Thisisreasonablebecausecolonsarenotallowedas

partofidentifiers.



IndexedPropertyPaths

Anindexedpropertypathisapropertypaththatidentifiesa

singlepropertyfromwithinarelatedsetofproperties.Whilean

unindexedpropertypathisidentifiedusingasinglevaluefrom

theUnindexedFieldURITypeenumeration,anindexedproperty

pathrequirestwopiecesofinformationtoproperlyidentifythe

propertybeingreferenced.Onepieceidentifiesthe"scope"or

groupofrelatedproperties,andanotherpieceidentifiesa

specificpropertywithinthatscope.

Toexplainindexedpropertypaths,wewillbeginwithan

illustration.Let'ssayafamilycontainsindividualsandtheyall

sharealastname.Thislastnamewouldbethe"scope"that

identifiesthemasaunitdistinctfromotherunitswith

individuals.ThisisshowninFigure3-3.

Figure3-3.Thefamilytree



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

Chapter 3. Property Paths and Response Shapes

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

×
x