Produced by Araxis Merge on 2/1/2017 2:56:33 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\GeneralProgramming\EarlyBound | WorkingWithRelatedAttributesforNto1Relationships.cs | Tue Dec 20 19:51:45 2016 UTC |
| 2 | Wed Feb 1 19:56:33 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 261 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 2 | // This f ile is par t of the M icrosoft D ynamics CR M SDK code samples. | |||||
| 3 | // | |||||
| 4 | // Copyri ght (C) Mi crosoft Co rporation. All righ ts reserve d. | |||||
| 5 | // | |||||
| 6 | // This s ource code is intend ed only as a supplem ent to Mic rosoft | |||||
| 7 | // Develo pment Tool s and/or o n-line doc umentation . See the se other | |||||
| 8 | // materi als for de tailed inf ormation r egarding M icrosoft c ode sample s. | |||||
| 9 | // | |||||
| 10 | // THIS C ODE AND IN FORMATION ARE PROVID ED "AS IS" WITHOUT W ARRANTY OF ANY | |||||
| 11 | // KIND, EITHER EXP RESSED OR IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E | |||||
| 12 | // IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR A | |||||
| 13 | // PARTIC ULAR PURPO SE. | |||||
| 14 | // ======= ========== ========== ========== ========== ========== ========== == | |||||
| 15 | ||||||
| 16 | //<snippet WorkingWit hRelatedAt tributesfo rNto1Relat ionships> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | ||||||
| 20 | // These n amespaces are found in the Mic rosoft.Xrm .Sdk.dll a ssembly | |||||
| 21 | // located in the SD K\bin fold er of the SDK downlo ad. | |||||
| 22 | using Micr osoft.Xrm. Sdk; | |||||
| 23 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 25 | ||||||
| 26 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 27 | { | |||||
| 28 | /// <s ummary> | |||||
| 29 | /// De monstrates how to do work with related a ttributes for N:1 | |||||
| 30 | /// re lationship s (Lookups ) using st rong types .</summary > | |||||
| 31 | /// <r emarks> | |||||
| 32 | /// At run-time, you will be given t he option to delete all the | |||||
| 33 | /// da tabase rec ords creat ed by this program.< /remarks> | |||||
| 34 | class WorkingWit hRelatedAt tributesfo rNto1Relat ionships | |||||
| 35 | { | |||||
| 36 | #r egion Clas s Level Me mbers | |||||
| 37 | ||||||
| 38 | pr ivate Guid _leadId; | |||||
| 39 | pr ivate Guid _contactI d; | |||||
| 40 | pr ivate Guid _phoneCal lId; | |||||
| 41 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 42 | pr ivate IOrg anizationS ervice _se rvice; | |||||
| 43 | ||||||
| 44 | #e ndregion C lass Level Members | |||||
| 45 | ||||||
| 46 | #r egion How To Sample Code | |||||
| 47 | // / <summary > | |||||
| 48 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, | |||||
| 49 | // / a phone call is cr eated to a contact r egarding a lead. | |||||
| 50 | // / </summar y> | |||||
| 51 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 52 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 53 | // / created entities.< /param> | |||||
| 54 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 55 | { | |||||
| 56 | try | |||||
| 57 | { | |||||
| 58 | //<s nippetWork ingWithRel atedAttrib utesforNto 1Relations hips1> | |||||
| 59 | // C onnect to the Organi zation ser vice. | |||||
| 60 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 61 | usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials, serverConf ig.DeviceC redentials )) | |||||
| 62 | { | |||||
| 63 | // This st atement is required to enable early-boun d type sup port. | |||||
| 64 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 65 | ||||||
| 66 | _service = (IOrganiz ationServi ce)_servic eProxy; | |||||
| 67 | ||||||
| 68 | // Create a lead. | |||||
| 69 | Lead lead = new Lead () | |||||
| 70 | { | |||||
| 71 | Compan yName = "L itware, In c." | |||||
| 72 | }; | |||||
| 73 | _leadId = _service.C reate(lead ); | |||||
| 74 | ||||||
| 75 | Console.Wr ite("Lead created, " ); | |||||
| 76 | ||||||
| 77 | // Create a contact. | |||||
| 78 | Contact co ntact = ne w Contact( ) | |||||
| 79 | { | |||||
| 80 | FirstN ame = "Dan ", | |||||
| 81 | LastNa me = "Park ", | |||||
| 82 | Addres s1_Line1 = "23 Marke t St.", | |||||
| 83 | Addres s1_City = "Sammamish ", | |||||
| 84 | Addres s1_StateOr Province = "MT", | |||||
| 85 | Addres s1_PostalC ode = "999 99", | |||||
| 86 | Teleph one1 = "12 345678", | |||||
| 87 | EMailA ddress1 = "dan@litwa reinc.com" | |||||
| 88 | }; | |||||
| 89 | _contactId = _servic e.Create(c ontact); | |||||
| 90 | contact.Co ntactId = _contactId ; | |||||
| 91 | ||||||
| 92 | Console.Wr ite("conta ct created , "); | |||||
| 93 | ||||||
| 94 | // Create a blank ph one call. | |||||
| 95 | PhoneCall phoneCall = new Phon eCall(); | |||||
| 96 | _phoneCall Id = _serv ice.Create (phoneCall ); | |||||
| 97 | ||||||
| 98 | Console.Wr ite("phone call crea ted, "); | |||||
| 99 | ||||||
| 100 | // Create an Activit yParty for the phone call's "t o" field. | |||||
| 101 | ActivityPa rty activi tyParty = new Activi tyParty() | |||||
| 102 | { | |||||
| 103 | PartyI d = new En tityRefere nce | |||||
| 104 | { | |||||
| 105 | Id = _contac tId, | |||||
| 106 | Lo gicalName = Contact. EntityLogi calName, | |||||
| 107 | }, | |||||
| 108 | Activi tyId = new EntityRef erence | |||||
| 109 | { | |||||
| 110 | Id = _phoneC allId, | |||||
| 111 | Lo gicalName = PhoneCal l.EntityLo gicalName, | |||||
| 112 | }, | |||||
| 113 | Partic ipationTyp eMask = ne w OptionSe tValue(9) | |||||
| 114 | }; | |||||
| 115 | ||||||
| 116 | // Create a phone ca ll and add the prope rties we a re updatin g. | |||||
| 117 | PhoneCall updatePhon eCall = ne w PhoneCal l() | |||||
| 118 | { | |||||
| 119 | Id = _ phoneCallI d, | |||||
| 120 | Subjec t = "Test Phone Call ", | |||||
| 121 | Regard ingObjectI d = new En tityRefere nce | |||||
| 122 | { | |||||
| 123 | Id = _leadId , | |||||
| 124 | Lo gicalName = Lead.Ent ityLogical Name | |||||
| 125 | }, | |||||
| 126 | To = n ew Activit yParty[] { activityP arty } | |||||
| 127 | }; | |||||
| 128 | ||||||
| 129 | // Update the phone call. | |||||
| 130 | UpdateRequ est update Request = new Update Request() | |||||
| 131 | { | |||||
| 132 | Target = updateP honeCall | |||||
| 133 | }; | |||||
| 134 | _service.E xecute(upd ateRequest ); | |||||
| 135 | ||||||
| 136 | Console.Wr ite("phone call upda ted.\n"); | |||||
| 137 | ||||||
| 138 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 139 | } | |||||
| 140 | //</ snippetWor kingWithRe latedAttri butesforNt o1Relation ships1> | |||||
| 141 | } | |||||
| 142 | ||||||
| 143 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 144 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 145 | { | |||||
| 146 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 147 | thro w; | |||||
| 148 | } | |||||
| 149 | } | |||||
| 150 | ||||||
| 151 | // / <summary > | |||||
| 152 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 153 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 154 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 155 | // / </summar y> | |||||
| 156 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 157 | { | |||||
| 158 | bool toB eDeleted = true; | |||||
| 159 | ||||||
| 160 | if (prom pt) | |||||
| 161 | { | |||||
| 162 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 163 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 164 | Stri ng answer = Console. ReadLine() ; | |||||
| 165 | if ( answer.Sta rtsWith("y ") || | |||||
| 166 | answer.Sta rtsWith("Y ") || | |||||
| 167 | answer == String.Emp ty) | |||||
| 168 | { | |||||
| 169 | toBeDelete d = true; | |||||
| 170 | } | |||||
| 171 | else | |||||
| 172 | { | |||||
| 173 | toBeDelete d = false; | |||||
| 174 | } | |||||
| 175 | } | |||||
| 176 | ||||||
| 177 | if (toBe Deleted) | |||||
| 178 | { | |||||
| 179 | // D elete all records cr eated in t his sample . | |||||
| 180 | ||||||
| 181 | _ser vice.Delet e(Lead.Ent ityLogical Name, _lea dId); | |||||
| 182 | _ser vice.Delet e(Contact. EntityLogi calName, _ contactId) ; | |||||
| 183 | ||||||
| 184 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 185 | } | |||||
| 186 | } | |||||
| 187 | ||||||
| 188 | #e ndregion H ow To Samp le Code | |||||
| 189 | ||||||
| 190 | #r egion Main method | |||||
| 191 | ||||||
| 192 | // / <summary > | |||||
| 193 | // / Standard Main() me thod used by most SD K samples. | |||||
| 194 | // / </summar y> | |||||
| 195 | // / <param n ame="args" ></param> | |||||
| 196 | st atic publi c void Mai n(string[] args) | |||||
| 197 | { | |||||
| 198 | try | |||||
| 199 | { | |||||
| 200 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 201 | // c redentials from the user. | |||||
| 202 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 203 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 204 | ||||||
| 205 | Work ingWithRel atedAttrib utesforNto 1Relations hips app = new Worki ngWithRela tedAttribu tesforNto1 Relationsh ips(); | |||||
| 206 | app. Run(config , true); | |||||
| 207 | } | |||||
| 208 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 209 | { | |||||
| 210 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 211 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 212 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 213 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 214 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 215 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 216 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 217 | } | |||||
| 218 | catch (S ystem.Time outExcepti on ex) | |||||
| 219 | { | |||||
| 220 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 221 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 222 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 223 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 224 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 225 | } | |||||
| 226 | catch (S ystem.Exce ption ex) | |||||
| 227 | { | |||||
| 228 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 229 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 230 | ||||||
| 231 | // D isplay the details o f the inne r exceptio n. | |||||
| 232 | if ( ex.InnerEx ception != null) | |||||
| 233 | { | |||||
| 234 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 235 | ||||||
| 236 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 237 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 238 | if (fe != null) | |||||
| 239 | { | |||||
| 240 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 241 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 242 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 243 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 244 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 245 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 246 | } | |||||
| 247 | } | |||||
| 248 | } | |||||
| 249 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 250 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 251 | ||||||
| 252 | finally | |||||
| 253 | { | |||||
| 254 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 255 | Cons ole.ReadLi ne(); | |||||
| 256 | } | |||||
| 257 | } | |||||
| 258 | #e ndregion M ain method | |||||
| 259 | } | |||||
| 260 | } | |||||
| 261 | //</snippe tWorkingWi thRelatedA ttributesf orNto1Rela tionships> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.