Produced by Araxis Merge on 2/1/2017 2:56:31 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\DataManagement\ExecuteMultiple | ExecuteMultiple.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:31 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 498 |
| 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 | // <snippe tExecuteMu ltiple> | |||||
| 17 | using Syst em; | |||||
| 18 | using Syst em.Service Model; | |||||
| 19 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 20 | using Micr osoft.Xrm. Sdk; | |||||
| 21 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 22 | using Micr osoft.Xrm. Sdk.Messag es; | |||||
| 23 | using Micr osoft.Xrm. Sdk.Metada ta; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Query; | |||||
| 25 | using Syst em.Collect ions.Gener ic; | |||||
| 26 | ||||||
| 27 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 28 | { | |||||
| 29 | public class Exe cuteMultip le | |||||
| 30 | { | |||||
| 31 | #r egion Clas s Level Me mbers | |||||
| 32 | ||||||
| 33 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 34 | pr ivate read only List< Guid> _new AccountIds = new Lis t<Guid>(); | |||||
| 35 | ||||||
| 36 | #e ndregion | |||||
| 37 | ||||||
| 38 | #r egion How To Sample Code | |||||
| 39 | ||||||
| 40 | // / <summary > | |||||
| 41 | // / This sam ple demons trates how to execut e a collec tion of me ssage requ ests using a single web servic e | |||||
| 42 | // / call and optionall y return t he results . | |||||
| 43 | // / </summar y> | |||||
| 44 | // / <seealso cref="htt p://msdn.m icrosoft.c om/en-us/l ibrary/gg3 28075.aspx "/> | |||||
| 45 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 46 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 47 | // / created entities.< /param> | |||||
| 48 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 49 | { | |||||
| 50 | ExecuteM ultipleReq uest reque stWithResu lts = null ; | |||||
| 51 | try | |||||
| 52 | { | |||||
| 53 | //<s nippetExec uteMultipl e1> | |||||
| 54 | // G et a refer ence to th e organiza tion servi ce. | |||||
| 55 | 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 )) | |||||
| 56 | { | |||||
| 57 | // Enable early-boun d type sup port to ad d/update e ntity reco rds requir ed for thi s sample. | |||||
| 58 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 59 | ||||||
| 60 | #region Ex ecute Mult iple with Results | |||||
| 61 | // Create an Execute MultipleRe quest obje ct. | |||||
| 62 | requestWit hResults = new Execu teMultiple Request() | |||||
| 63 | { | |||||
| 64 | // Ass ign settin gs that de fine execu tion behav ior: conti nue on err or, return responses . | |||||
| 65 | Settin gs = new E xecuteMult ipleSettin gs() | |||||
| 66 | { | |||||
| 67 | Co ntinueOnEr ror = fals e, | |||||
| 68 | Re turnRespon ses = true | |||||
| 69 | }, | |||||
| 70 | // Cre ate an emp ty organiz ation requ est collec tion. | |||||
| 71 | Reques ts = new O rganizatio nRequestCo llection() | |||||
| 72 | }; | |||||
| 73 | ||||||
| 74 | // Create several (l ocal, in m emory) ent ities in a collectio n. | |||||
| 75 | EntityColl ection inp ut = GetCo llectionOf EntitiesTo Create(); | |||||
| 76 | ||||||
| 77 | // Add a C reateReque st for eac h entity t o the requ est collec tion. | |||||
| 78 | foreach (v ar entity in input.E ntities) | |||||
| 79 | { | |||||
| 80 | Create Request cr eateReques t = new Cr eateReques t { Target = entity }; | |||||
| 81 | reques tWithResul ts.Request s.Add(crea teRequest) ; | |||||
| 82 | } | |||||
| 83 | ||||||
| 84 | // Execute all the r equests in the reque st collect ion using a single w eb method call. | |||||
| 85 | ExecuteMul tipleRespo nse respon seWithResu lts = | |||||
| 86 | (Execu teMultiple Response)_ servicePro xy.Execute (requestWi thResults) ; | |||||
| 87 | ||||||
| 88 | // Display the resul ts returne d in the r esponses. | |||||
| 89 | foreach (v ar respons eItem in r esponseWit hResults.R esponses) | |||||
| 90 | { | |||||
| 91 | // A v alid respo nse. | |||||
| 92 | if (re sponseItem .Response != null) | |||||
| 93 | Di splayRespo nse(reques tWithResul ts.Request s[response Item.Reque stIndex], responseIt em.Respons e); | |||||
| 94 | ||||||
| 95 | // An error has occurred. | |||||
| 96 | else i f (respons eItem.Faul t != null) | |||||
| 97 | Di splayFault (requestWi thResults. Requests[r esponseIte m.RequestI ndex], | |||||
| 98 | response Item.Reque stIndex, r esponseIte m.Fault); | |||||
| 99 | } | |||||
| 100 | //</snippe tExecuteMu ltiple1> | |||||
| 101 | #endregion Execute M ultiple wi th Results | |||||
| 102 | ||||||
| 103 | ||||||
| 104 | #region Ex ecute Mult iple with No Results | |||||
| 105 | ||||||
| 106 | ExecuteMul tipleReque st request WithNoResu lts = new ExecuteMul tipleReque st() | |||||
| 107 | { | |||||
| 108 | // Set the execu tion behav ior to not continue after the first erro r is recei ved | |||||
| 109 | // and to not re turn respo nses. | |||||
| 110 | Settin gs = new E xecuteMult ipleSettin gs() | |||||
| 111 | { | |||||
| 112 | Co ntinueOnEr ror = fals e, | |||||
| 113 | Re turnRespon ses = fals e | |||||
| 114 | }, | |||||
| 115 | Reques ts = new O rganizatio nRequestCo llection() | |||||
| 116 | }; | |||||
| 117 | ||||||
| 118 | // Update the entiti es that we re previou sly create d. | |||||
| 119 | EntityColl ection upd ate = GetC ollectionO fEntitiesT oUpdate(); | |||||
| 120 | ||||||
| 121 | foreach (v ar entity in update. Entities) | |||||
| 122 | { | |||||
| 123 | Update Request up dateReques t = new Up dateReques t { Target = entity }; | |||||
| 124 | reques tWithNoRes ults.Reque sts.Add(up dateReques t); | |||||
| 125 | } | |||||
| 126 | ||||||
| 127 | ExecuteMul tipleRespo nse respon seWithNoRe sults = | |||||
| 128 | (Execu teMultiple Response)_ servicePro xy.Execute (requestWi thNoResult s); | |||||
| 129 | ||||||
| 130 | // There s hould be n o response s unless t here was a n error. O nly the fi rst error | |||||
| 131 | // should be returne d. That is the behav ior define d in the s ettings. | |||||
| 132 | if (respon seWithNoRe sults.Resp onses.Coun t > 0) | |||||
| 133 | { | |||||
| 134 | foreac h (var res ponseItem in respons eWithNoRes ults.Respo nses) | |||||
| 135 | { | |||||
| 136 | if (response Item.Fault != null) | |||||
| 137 | DisplayF ault(reque stWithNoRe sults.Requ ests[respo nseItem.Re questIndex ], | |||||
| 138 | resp onseItem.R equestInde x, respons eItem.Faul t); | |||||
| 139 | } | |||||
| 140 | } | |||||
| 141 | else | |||||
| 142 | { | |||||
| 143 | Consol e.WriteLin e("All acc ount recor ds have be en updated successfu lly."); | |||||
| 144 | } | |||||
| 145 | ||||||
| 146 | #endregion Execute M ultiple wi th No Resu lts | |||||
| 147 | ||||||
| 148 | ||||||
| 149 | #region Ex ecute Mult iple with Continue O n Error | |||||
| 150 | ||||||
| 151 | ExecuteMul tipleReque st request WithContin ueOnError = new Exec uteMultipl eRequest() | |||||
| 152 | { | |||||
| 153 | // Set the execu tion behav ior to con tinue on a n error an d not retu rn respons es. | |||||
| 154 | Settin gs = new E xecuteMult ipleSettin gs() | |||||
| 155 | { | |||||
| 156 | Co ntinueOnEr ror = true , | |||||
| 157 | Re turnRespon ses = fals e | |||||
| 158 | }, | |||||
| 159 | Reques ts = new O rganizatio nRequestCo llection() | |||||
| 160 | }; | |||||
| 161 | ||||||
| 162 | // Update the entiti es but int roduce som e bad attr ibute valu es so we g et errors. | |||||
| 163 | EntityColl ection upd ateWithErr ors = GetC ollectionO fEntitiesT oUpdateWit hErrors(); | |||||
| 164 | ||||||
| 165 | foreach (v ar entity in updateW ithErrors. Entities) | |||||
| 166 | { | |||||
| 167 | Update Request up dateReques t = new Up dateReques t { Target = entity }; | |||||
| 168 | reques tWithConti nueOnError .Requests. Add(update Request); | |||||
| 169 | } | |||||
| 170 | ||||||
| 171 | ExecuteMul tipleRespo nse respon seWithCont inueOnErro r = | |||||
| 172 | (Execu teMultiple Response)_ servicePro xy.Execute (requestWi thContinue OnError); | |||||
| 173 | ||||||
| 174 | // There s hould be n o response s except f or those t hat contai n an error . | |||||
| 175 | if (respon seWithCont inueOnErro r.Response s.Count > 0) | |||||
| 176 | { | |||||
| 177 | if (re sponseWith ContinueOn Error.Resp onses.Coun t < reques tWithConti nueOnError .Requests. Count) | |||||
| 178 | { | |||||
| 179 | Co nsole.Writ eLine("Res ponse coll ection con tain a mix of succes sful respo nse object s and erro rs."); | |||||
| 180 | } | |||||
| 181 | foreac h (var res ponseItem in respons eWithConti nueOnError .Responses ) | |||||
| 182 | { | |||||
| 183 | if (response Item.Fault != null) | |||||
| 184 | DisplayF ault(reque stWithCont inueOnErro r.Requests [responseI tem.Reques tIndex], | |||||
| 185 | resp onseItem.R equestInde x, respons eItem.Faul t); | |||||
| 186 | } | |||||
| 187 | } | |||||
| 188 | else | |||||
| 189 | { | |||||
| 190 | // No errors mea ns all tra nsactions are succes sful. | |||||
| 191 | Consol e.WriteLin e("All acc ount recor ds have be en updated successfu lly."); | |||||
| 192 | } | |||||
| 193 | ||||||
| 194 | #endregion Execute M ultiple wi th Continu e On Error | |||||
| 195 | ||||||
| 196 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 197 | } | |||||
| 198 | } | |||||
| 199 | ||||||
| 200 | // <snip petExecute Multiple2> | |||||
| 201 | catch (F aultExcept ion<Organi zationServ iceFault> fault) | |||||
| 202 | { | |||||
| 203 | // C heck if th e maximum batch size has been exceeded. The maximu m batch si ze is only included in the fau lt if it | |||||
| 204 | // t he input r equest col lection co unt exceed s the maxi mum batch size. | |||||
| 205 | if ( fault.Deta il.ErrorDe tails.Cont ains("MaxB atchSize") ) | |||||
| 206 | { | |||||
| 207 | int maxBat chSize = C onvert.ToI nt32(fault .Detail.Er rorDetails ["MaxBatch Size"]); | |||||
| 208 | if (maxBat chSize < r equestWith Results.Re quests.Cou nt) | |||||
| 209 | { | |||||
| 210 | // Her e you coul d reduce t he size of your requ est collec tion and r e-submit t he Execute Multiple r equest. | |||||
| 211 | // For this samp le, that o nly issues a few req uests per batch, we will just print out some info. However, | |||||
| 212 | // thi s code wil l never be executed because th e default max batch size is 10 00. | |||||
| 213 | Consol e.WriteLin e("The inp ut request collectio n contains %0 reques ts, which exceeds th e maximum allowed (% 1)", | |||||
| 214 | re questWithR esults.Req uests.Coun t, maxBatc hSize); | |||||
| 215 | } | |||||
| 216 | } | |||||
| 217 | // R e-throw so Main() ca n process the fault. | |||||
| 218 | thro w; | |||||
| 219 | } | |||||
| 220 | // </sni ppetExecut eMultiple2 > | |||||
| 221 | } | |||||
| 222 | ||||||
| 223 | ||||||
| 224 | #r egion Publ ic Methods | |||||
| 225 | ||||||
| 226 | // / <summary > | |||||
| 227 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 228 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 229 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 230 | // / </summar y> | |||||
| 231 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 232 | { | |||||
| 233 | bool del eteRecords = true; | |||||
| 234 | ||||||
| 235 | if (prom pt) | |||||
| 236 | { | |||||
| 237 | Cons ole.WriteL ine("\nDo you want t o delete t he account record? ( y/n) [y]: "); | |||||
| 238 | Stri ng answer = Console. ReadLine() ; | |||||
| 239 | ||||||
| 240 | dele teRecords = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty); | |||||
| 241 | } | |||||
| 242 | ||||||
| 243 | if (!del eteRecords ) | |||||
| 244 | retu rn; | |||||
| 245 | ||||||
| 246 | ExecuteM ultipleReq uest reque stWithNoRe sults = ne w ExecuteM ultipleReq uest() | |||||
| 247 | { | |||||
| 248 | // Set t he executi on behavio r to not c ontinue af ter the fi rst error is receive d | |||||
| 249 | // and t o not retu rn respons es. | |||||
| 250 | Settings = new Exe cuteMultip leSettings () | |||||
| 251 | { | |||||
| 252 | Cont inueOnErro r = false, | |||||
| 253 | Retu rnResponse s = false | |||||
| 254 | }, | |||||
| 255 | Requests = new Org anizationR equestColl ection() | |||||
| 256 | }; | |||||
| 257 | ||||||
| 258 | // Updat e the enti ties that were previ ously crea ted. | |||||
| 259 | EntityCo llection d elete = Ge tCollectio nOfEntitie sToDelete( ); | |||||
| 260 | ||||||
| 261 | foreach (var entit y in delet e.Entities ) | |||||
| 262 | { | |||||
| 263 | Dele teRequest deleteRequ est = new DeleteRequ est { Targ et = entit y.ToEntity Reference( ) }; | |||||
| 264 | requ estWithNoR esults.Req uests.Add( deleteRequ est); | |||||
| 265 | } | |||||
| 266 | ||||||
| 267 | ExecuteM ultipleRes ponse resp onseWithNo Results = | |||||
| 268 | (Exe cuteMultip leResponse )_serviceP roxy.Execu te(request WithNoResu lts); | |||||
| 269 | ||||||
| 270 | // There should be no respon ses unless there was an error. Only the first erro r | |||||
| 271 | // shoul d be retur ned. That is the beh avior defi ned in the settings. | |||||
| 272 | if (resp onseWithNo Results.Re sponses.Co unt > 0) | |||||
| 273 | { | |||||
| 274 | fore ach (var r esponseIte m in respo nseWithNoR esults.Res ponses) | |||||
| 275 | { | |||||
| 276 | if (respon seItem.Fau lt != null ) | |||||
| 277 | Displa yFault(req uestWithNo Results.Re quests[res ponseItem. RequestInd ex], | |||||
| 278 | re sponseItem .RequestIn dex, respo nseItem.Fa ult); | |||||
| 279 | } | |||||
| 280 | } | |||||
| 281 | else | |||||
| 282 | { | |||||
| 283 | Cons ole.WriteL ine("All a ccount rec ords have been delet ed success fully."); | |||||
| 284 | } | |||||
| 285 | } | |||||
| 286 | ||||||
| 287 | #e ndregion | |||||
| 288 | ||||||
| 289 | #r egion Priv ate Method s | |||||
| 290 | ||||||
| 291 | // / <summary > | |||||
| 292 | // / Create a collectio n of entit y objects for updati ng. Give t hese entit ies a new | |||||
| 293 | // / name for the updat e. However , use a ba d (empty) GUID in so me entitie s to demon strate | |||||
| 294 | // / returnin g errors i n ExecuteM ultipleRes ponse. | |||||
| 295 | // / </summar y> | |||||
| 296 | // / <returns >An entity collectio n.</return s> | |||||
| 297 | pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToUp dateWithEr rors() | |||||
| 298 | { | |||||
| 299 | EntityCo llection c ollection = new Enti tyCollecti on() | |||||
| 300 | { | |||||
| 301 | Enti tyName = A ccount.Ent ityLogical Name | |||||
| 302 | }; | |||||
| 303 | ||||||
| 304 | for (int i = 1; i <= _newAcc ountIds.Co unt; i++) | |||||
| 305 | { | |||||
| 306 | if ( i % 2 > 0) | |||||
| 307 | { | |||||
| 308 | collection .Entities. Add( | |||||
| 309 | new Accoun t | |||||
| 310 | { | |||||
| 311 | Name = "Again Up dated Exam ple Accoun t " + i.To String(), | |||||
| 312 | Id = n ew Guid() | |||||
| 313 | }); | |||||
| 314 | } | |||||
| 315 | else | |||||
| 316 | { | |||||
| 317 | ||||||
| 318 | collection .Entities. Add( | |||||
| 319 | new Ac count | |||||
| 320 | { | |||||
| 321 | Na me = "Agai n Updated Example Ac count " + i.ToString (), | |||||
| 322 | Id = _newAcc ountIds[i - 1] | |||||
| 323 | }); | |||||
| 324 | } | |||||
| 325 | } | |||||
| 326 | ||||||
| 327 | return c ollection; | |||||
| 328 | } | |||||
| 329 | ||||||
| 330 | // / <summary > | |||||
| 331 | // / Create a collectio n of entit y objects for updati ng. Give t hese entit ies a new | |||||
| 332 | // / name for the updat e. | |||||
| 333 | // / </summar y> | |||||
| 334 | // / <returns >An entity collectio n.</return s> | |||||
| 335 | pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToUp date() | |||||
| 336 | { | |||||
| 337 | EntityCo llection c ollection = new Enti tyCollecti on() | |||||
| 338 | { | |||||
| 339 | Enti tyName = A ccount.Ent ityLogical Name | |||||
| 340 | }; | |||||
| 341 | ||||||
| 342 | for (int i = 1; i <= _newAcc ountIds.Co unt; i++) | |||||
| 343 | { | |||||
| 344 | coll ection.Ent ities.Add( | |||||
| 345 | new Accoun t | |||||
| 346 | { | |||||
| 347 | Name = "Updated Example Ac count " + i.ToString (), | |||||
| 348 | Id = _ newAccount Ids[i - 1] | |||||
| 349 | }); | |||||
| 350 | } | |||||
| 351 | ||||||
| 352 | return c ollection; | |||||
| 353 | } | |||||
| 354 | ||||||
| 355 | // / <summary > | |||||
| 356 | // / Create a collectio n of new e ntity obje cts. | |||||
| 357 | // / </summar y> | |||||
| 358 | // / <returns >A collect ion of ent ity object s.</return s> | |||||
| 359 | pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToCr eate() | |||||
| 360 | { | |||||
| 361 | return n ew EntityC ollection( ) | |||||
| 362 | { | |||||
| 363 | Enti tyName = A ccount.Ent ityLogical Name, | |||||
| 364 | Enti ties = { | |||||
| 365 | new Accoun t { Name = "Example Account 1" }, | |||||
| 366 | new Accoun t { Name = "Example Account 2" }, | |||||
| 367 | new Accoun t { Name = "Example Account 3" }, | |||||
| 368 | new Accoun t { Name = "Example Account 4" }, | |||||
| 369 | new Accoun t { Name = "Example Account 5" } | |||||
| 370 | } | |||||
| 371 | }; | |||||
| 372 | } | |||||
| 373 | ||||||
| 374 | // / <summary > | |||||
| 375 | // / Delete a collectio n of entit y objects. | |||||
| 376 | // / </summar y> | |||||
| 377 | // / <returns >A collect ion of ent ity object s</returns > | |||||
| 378 | pr ivate Enti tyCollecti on GetColl ectionOfEn titiesToDe lete() | |||||
| 379 | { | |||||
| 380 | EntityCo llection c ollection = new Enti tyCollecti on() | |||||
| 381 | { | |||||
| 382 | Enti tyName = A ccount.Ent ityLogical Name | |||||
| 383 | }; | |||||
| 384 | ||||||
| 385 | for (int i = 1; i <= _newAcc ountIds.Co unt; i++) | |||||
| 386 | { | |||||
| 387 | coll ection.Ent ities.Add( | |||||
| 388 | new Accoun t | |||||
| 389 | { | |||||
| 390 | Id = _ newAccount Ids[i - 1] | |||||
| 391 | }); | |||||
| 392 | } | |||||
| 393 | ||||||
| 394 | return c ollection; | |||||
| 395 | } | |||||
| 396 | ||||||
| 397 | // / <summary > | |||||
| 398 | // / Display the respon se of an o rganizatio n message request. | |||||
| 399 | // / </summar y> | |||||
| 400 | // / <param n ame="organ izationReq uest">The organizati on message request.< /param> | |||||
| 401 | // / <param n ame="organ izationRes ponse">The organizat ion messag e response .</param> | |||||
| 402 | pr ivate void DisplayRe sponse(Org anizationR equest org anizationR equest, Or ganization Response o rganizatio nResponse) | |||||
| 403 | { | |||||
| 404 | Console. WriteLine( "Created " + ((Accou nt)organiz ationReque st.Paramet ers["Targe t"]).Name | |||||
| 405 | + " with accou nt id as " + organiz ationRespo nse.Result s["id"].To String()); | |||||
| 406 | _newAcco untIds.Add (new Guid( organizati onResponse .Results[" id"].ToStr ing())); | |||||
| 407 | } | |||||
| 408 | ||||||
| 409 | // / <summary > | |||||
| 410 | // / Display the fault that resul ted from p rocessing an organiz ation mess age reques t. | |||||
| 411 | // / </summar y> | |||||
| 412 | // / <param n ame="organ izationReq uest">The organizati on message request.< /param> | |||||
| 413 | // / <param n ame="count ">nth requ est number from Exec uteMultipl e request< /param> | |||||
| 414 | // / <param n ame="organ izationSer viceFault" >A WCF fau lt.</param > | |||||
| 415 | pr ivate void DisplayFa ult(Organi zationRequ est organi zationRequ est, int c ount, | |||||
| 416 | Organiza tionServic eFault org anizationS erviceFaul t) | |||||
| 417 | { | |||||
| 418 | Console. WriteLine( "A fault o ccurred wh en process ing {1} re quest, at index {0} in the req uest colle ction with a fault m essage: {2 }", count + 1, | |||||
| 419 | orga nizationRe quest.Requ estName, | |||||
| 420 | orga nizationSe rviceFault .Message); | |||||
| 421 | } | |||||
| 422 | ||||||
| 423 | #e ndregion | |||||
| 424 | ||||||
| 425 | #e ndregion H ow To Samp le Code | |||||
| 426 | ||||||
| 427 | #r egion Main method | |||||
| 428 | ||||||
| 429 | // / <summary > | |||||
| 430 | // / Standard Main() me thod used by most SD K samples. | |||||
| 431 | // / </summar y> | |||||
| 432 | // / <param n ame="args" ></param> | |||||
| 433 | st atic publi c void Mai n(string[] args) | |||||
| 434 | { | |||||
| 435 | try | |||||
| 436 | { | |||||
| 437 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 438 | // c redentials from the user. | |||||
| 439 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 440 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 441 | ||||||
| 442 | var app = new ExecuteMul tiple(); | |||||
| 443 | app. Run(config , true); | |||||
| 444 | } | |||||
| 445 | ||||||
| 446 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 447 | { | |||||
| 448 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 449 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 450 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 451 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 452 | Cons ole.WriteL ine("Trace : {0}", ex .Detail.Tr aceText); | |||||
| 453 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 454 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 455 | } | |||||
| 456 | catch (S ystem.Time outExcepti on ex) | |||||
| 457 | { | |||||
| 458 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 459 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 460 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 461 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 462 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 463 | } | |||||
| 464 | catch (S ystem.Exce ption ex) | |||||
| 465 | { | |||||
| 466 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 467 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 468 | ||||||
| 469 | // D isplay the details o f the inne r exceptio n. | |||||
| 470 | if ( ex.InnerEx ception != null) | |||||
| 471 | { | |||||
| 472 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 473 | ||||||
| 474 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 475 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 476 | if (fe != null) | |||||
| 477 | { | |||||
| 478 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 479 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 480 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 481 | Consol e.WriteLin e("Trace: {0}", fe.D etail.Trac eText); | |||||
| 482 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 483 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 484 | } | |||||
| 485 | } | |||||
| 486 | } | |||||
| 487 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 488 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 489 | finally | |||||
| 490 | { | |||||
| 491 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 492 | Cons ole.ReadLi ne(); | |||||
| 493 | } | |||||
| 494 | } | |||||
| 495 | #e ndregion M ain method | |||||
| 496 | } | |||||
| 497 | } | |||||
| 498 | // </snipp etExecuteM ultiple> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.