Produced by Araxis Merge on 2/1/2017 2:56:28 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\BusinessDataModel\Service | WorkingWithContracts.cs | Tue Dec 20 19:51:43 2016 UTC |
| 2 | Wed Feb 1 19:56:28 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 1 | 481 |
| 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 hContracts > | |||||
| 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.Query; | |||||
| 24 | using Micr osoft.Xrm. Sdk.Client ; | |||||
| 25 | ||||||
| 26 | // This na mespace is found in Microsoft. Crm.Sdk.Pr oxy.dll as sembly | |||||
| 27 | // found i n the SDK\ bin folder . | |||||
| 28 | using Micr osoft.Crm. Sdk.Messag es; | |||||
| 29 | ||||||
| 30 | namespace Microsoft. Crm.Sdk.Sa mples | |||||
| 31 | { | |||||
| 32 | /// <s ummary> | |||||
| 33 | /// De monstrates how to do manage co ntract rec ords progr ammaticall y.</summar y> | |||||
| 34 | /// <r emarks> | |||||
| 35 | /// At run-time, you will be given t he option to delete all the | |||||
| 36 | /// da tabase rec ords creat ed by this program.< /remarks> | |||||
| 37 | public class Wor kingWithCo ntracts | |||||
| 38 | { | |||||
| 39 | #r egion Clas s Level Me mbers | |||||
| 40 | ||||||
| 41 | pr ivate Guid _accountI d; | |||||
| 42 | pr ivate Guid _contract Id; | |||||
| 43 | pr ivate Guid _contract TemplateId ; | |||||
| 44 | pr ivate Guid _firstClo neId; | |||||
| 45 | pr ivate Guid _secondCl oneId; | |||||
| 46 | pr ivate Guid _renewedI d; | |||||
| 47 | pr ivate Orga nizationSe rviceProxy _serviceP roxy; | |||||
| 48 | ||||||
| 49 | #e ndregion C lass Level Members | |||||
| 50 | ||||||
| 51 | #r egion How To Sample Code | |||||
| 52 | // / <summary > | |||||
| 53 | // / This met hod first connects t o the Orga nization s ervice. Af terwards, | |||||
| 54 | // / a Contra ct Templat e and seve ral Contra cts are cr eated, dem onstrating how to | |||||
| 55 | // / create a nd work wi th the Con tract enti ty. | |||||
| 56 | // / </summar y> | |||||
| 57 | // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param> | |||||
| 58 | // / <param n ame="promp tforDelete ">When Tru e, the use r will be prompted t o delete a ll | |||||
| 59 | // / created entities.< /param> | |||||
| 60 | pu blic void Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete) | |||||
| 61 | { | |||||
| 62 | try | |||||
| 63 | { | |||||
| 64 | //<s nippetWork ingWithCon tracts1> | |||||
| 65 | // C onnect to the Organi zation ser vice. | |||||
| 66 | // T he using s tatement a ssures tha t the serv ice proxy will be pr operly dis posed. | |||||
| 67 | 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 )) | |||||
| 68 | { | |||||
| 69 | // This st atement is required to enable early-boun d type sup port. | |||||
| 70 | _servicePr oxy.Enable ProxyTypes (); | |||||
| 71 | ||||||
| 72 | CreateRequ iredRecord s(); | |||||
| 73 | ||||||
| 74 | #region Cr eate Contr act Templa te | |||||
| 75 | ||||||
| 76 | // First, attempt to retrieve the Contra ct Templat e. Otherwi se, | |||||
| 77 | // create the templa te. | |||||
| 78 | QueryExpre ssion temp lateQuery = new Quer yExpressio n() | |||||
| 79 | { | |||||
| 80 | Entity Name = Con tractTempl ate.Entity LogicalNam e, | |||||
| 81 | Column Set = new ColumnSet( "contractt emplateid" ), | |||||
| 82 | Criter ia = | |||||
| 83 | { | |||||
| 84 | Co nditions = | |||||
| 85 | { | |||||
| 86 | new Cond itionExpre ssion("abb reviation" , Conditio nOperator. Equal, "SC T") | |||||
| 87 | } | |||||
| 88 | } | |||||
| 89 | }; | |||||
| 90 | EntityColl ection ec = _service Proxy.Retr ieveMultip le(templat eQuery); | |||||
| 91 | ||||||
| 92 | if (ec.Ent ities.Coun t > 0) | |||||
| 93 | { | |||||
| 94 | _contr actTemplat eId = ec.E ntities[0] .Id; | |||||
| 95 | Consol e.Write("T emplate re trieved, " ); | |||||
| 96 | } | |||||
| 97 | else | |||||
| 98 | { | |||||
| 99 | Contra ctTemplate contractT emplate = new Contra ctTemplate () | |||||
| 100 | { | |||||
| 101 | Na me = "Samp le Contrac t Template ", | |||||
| 102 | Bi llingFrequ encyCode = new Optio nSetValue( (int)Contr actTemplat eBillingFr equencyCod e.Monthly) , | |||||
| 103 | Ab breviation = "SCT", | |||||
| 104 | Al lotmentTyp eCode = ne w OptionSe tValue((in t)Contract TemplateAl lotmentTyp eCode.Numb erofCases) , | |||||
| 105 | Ef fectivityC alendar = | |||||
| 106 | "------- -+++++++++ ---------- -----+++++ ++++------ ---------+ ++++++++-- ---------- ---+++++++ ++-------- -------+++ ++++++---- ---------- ---------- ---------- ---------- ---------- -" | |||||
| 107 | }; | |||||
| 108 | _contr actTemplat eId = _ser viceProxy. Create(con tractTempl ate); | |||||
| 109 | Consol e.Write("T emplate cr eated, "); | |||||
| 110 | } | |||||
| 111 | ||||||
| 112 | #endregion | |||||
| 113 | ||||||
| 114 | #region Cr eate Contr act | |||||
| 115 | ||||||
| 116 | // Create a Contract from the Contract T emplate. | |||||
| 117 | Contract c ontract = new Contra ct() | |||||
| 118 | { | |||||
| 119 | Title = "Sample Contract", | |||||
| 120 | Contra ctTemplate Id = new E ntityRefer ence | |||||
| 121 | { | |||||
| 122 | Id = _contra ctTemplate Id, | |||||
| 123 | Lo gicalName = Contract Template.E ntityLogic alName | |||||
| 124 | }, | |||||
| 125 | Custom erId = new EntityRef erence | |||||
| 126 | { | |||||
| 127 | Id = _accoun tId, | |||||
| 128 | Lo gicalName = Account. EntityLogi calName | |||||
| 129 | }, | |||||
| 130 | Billin gCustomerI d = new En tityRefere nce | |||||
| 131 | { | |||||
| 132 | Id = _accoun tId, | |||||
| 133 | Lo gicalName = Account. EntityLogi calName | |||||
| 134 | }, | |||||
| 135 | Active On = new D ateTime(20 15, 1, 1), | |||||
| 136 | Expire sOn = new DateTime(2 020, 1, 1) , | |||||
| 137 | Billin gStartOn = new DateT ime(2015, 1, 1), | |||||
| 138 | Billin gEndOn = n ew DateTim e(2020, 1, 1) | |||||
| 139 | }; | |||||
| 140 | _contractI d = _servi ceProxy.Cr eate(contr act); | |||||
| 141 | ||||||
| 142 | Console.Wr ite("paren t contract created, "); | |||||
| 143 | ||||||
| 144 | // Create a contract line item . | |||||
| 145 | ContractDe tail contr actLineIte m = new Co ntractDeta il() | |||||
| 146 | { | |||||
| 147 | Title = "Sample Contract L ine Item", | |||||
| 148 | Contra ctId = new EntityRef erence | |||||
| 149 | { | |||||
| 150 | Id = _contra ctId, | |||||
| 151 | Lo gicalName = Contract .EntityLog icalName | |||||
| 152 | }, | |||||
| 153 | Custom erId = new EntityRef erence | |||||
| 154 | { | |||||
| 155 | Id = _accoun tId, | |||||
| 156 | Lo gicalName = Account. EntityLogi calName | |||||
| 157 | }, | |||||
| 158 | Active On = new D ateTime(20 15, 1, 1), | |||||
| 159 | Expire sOn = new DateTime(2 020, 1, 1) , | |||||
| 160 | Price = new Mone y(20.0M), | |||||
| 161 | TotalA llotments = 20 | |||||
| 162 | }; | |||||
| 163 | _servicePr oxy.Create (contractL ineItem); | |||||
| 164 | ||||||
| 165 | Console.Wr ite("contr act line a ttached, " ); | |||||
| 166 | ||||||
| 167 | #endregion | |||||
| 168 | ||||||
| 169 | #region Cl one contra ct twice | |||||
| 170 | ||||||
| 171 | //<snippet CloneContr act> | |||||
| 172 | // Create the first clone of t he contrac t. | |||||
| 173 | CloneContr actRequest cloneRequ est = new CloneContr actRequest () | |||||
| 174 | { | |||||
| 175 | Contra ctId = _co ntractId, | |||||
| 176 | Includ eCanceledL ines = fal se | |||||
| 177 | }; | |||||
| 178 | CloneContr actRespons e cloneRes ponse = | |||||
| 179 | (Clone ContractRe sponse)_se rviceProxy .Execute(c loneReques t); | |||||
| 180 | _firstClon eId = ((Co ntract)clo neResponse .Entity).C ontractId. Value; | |||||
| 181 | ||||||
| 182 | //</snippe tCloneCont ract> | |||||
| 183 | Console.Wr ite("first clone cre ated, "); | |||||
| 184 | ||||||
| 185 | // Create the second clone of the contra ct. | |||||
| 186 | cloneReque st = new C loneContra ctRequest( ) | |||||
| 187 | { | |||||
| 188 | Contra ctId = _co ntractId, | |||||
| 189 | Includ eCanceledL ines = tru e | |||||
| 190 | }; | |||||
| 191 | cloneRespo nse = | |||||
| 192 | (Clone ContractRe sponse)_se rviceProxy .Execute(c loneReques t); | |||||
| 193 | _secondClo neId = ((C ontract)cl oneRespons e.Entity). ContractId .Value; | |||||
| 194 | ||||||
| 195 | Console.Wr ite("secon d clone cr eated. \n" ); | |||||
| 196 | ||||||
| 197 | // Retriev e all Cont racts. | |||||
| 198 | QueryExpre ssion cont ractQuery = new Quer yExpressio n() | |||||
| 199 | { | |||||
| 200 | Entity Name = Con tract.Enti tyLogicalN ame, | |||||
| 201 | Column Set = new ColumnSet( "contracti d"), | |||||
| 202 | Criter ia = | |||||
| 203 | { | |||||
| 204 | Co nditions = | |||||
| 205 | { | |||||
| 206 | new Cond itionExpre ssion("cus tomerid", ConditionO perator.Eq ual, _acco untId) | |||||
| 207 | } | |||||
| 208 | } | |||||
| 209 | }; | |||||
| 210 | EntityColl ection con tracts = _ servicePro xy.Retriev eMultiple( contractQu ery); | |||||
| 211 | ||||||
| 212 | // Display the retri eved Contr act Ids. | |||||
| 213 | for (int i = 0; i < contracts. Entities.C ount; i++) | |||||
| 214 | { | |||||
| 215 | Consol e.WriteLin e("Retriev ed contrac t with Id: {0}", | |||||
| 216 | (( Contract)c ontracts.E ntities[i] ).Contract Id); | |||||
| 217 | } | |||||
| 218 | ||||||
| 219 | #endregion | |||||
| 220 | ||||||
| 221 | #region De activate a cloned co ntract | |||||
| 222 | ||||||
| 223 | // In orde r to deact ivate a co ntract (pu t it on ho ld), it is first | |||||
| 224 | // necessa ry to invo ice the co ntract. | |||||
| 225 | SetStateRe quest setS tateReques t = new Se tStateRequ est() | |||||
| 226 | { | |||||
| 227 | Entity Moniker = new Entity Reference | |||||
| 228 | { | |||||
| 229 | Id = _firstC loneId, | |||||
| 230 | Lo gicalName = Contract .EntityLog icalName | |||||
| 231 | }, | |||||
| 232 | State = new Opti onSetValue ((int)Cont ractState. Invoiced), | |||||
| 233 | Status = new Opt ionSetValu e(2) | |||||
| 234 | }; | |||||
| 235 | _servicePr oxy.Execut e(setState Request); | |||||
| 236 | ||||||
| 237 | Console.Wr ite("Contr act invoic ed, "); | |||||
| 238 | ||||||
| 239 | // Now tha t the cont ract has b een invoic ed, it is possible t o put | |||||
| 240 | // the con tract on h old. | |||||
| 241 | setStateRe quest = ne w SetState Request() | |||||
| 242 | { | |||||
| 243 | Entity Moniker = new Entity Reference | |||||
| 244 | { | |||||
| 245 | Id = _firstC loneId, | |||||
| 246 | Lo gicalName = Contract .EntityLog icalName | |||||
| 247 | }, | |||||
| 248 | State = new Opti onSetValue ((int)Cont ractState. OnHold), | |||||
| 249 | Status = new Opt ionSetValu e(4) | |||||
| 250 | }; | |||||
| 251 | _servicePr oxy.Execut e(setState Request); | |||||
| 252 | ||||||
| 253 | Console.Wr ite("and p ut on hold .\n"); | |||||
| 254 | ||||||
| 255 | #endregion | |||||
| 256 | ||||||
| 257 | #region Re new an inv oiced cont ract | |||||
| 258 | ||||||
| 259 | // In orde r to renew a contrac t, it must be invoic ed first, and | |||||
| 260 | // then ca nceled. | |||||
| 261 | ||||||
| 262 | //<snippet SetStateFo rContract> | |||||
| 263 | // Invoice the contr act. | |||||
| 264 | setStateRe quest = ne w SetState Request() | |||||
| 265 | { | |||||
| 266 | Entity Moniker = new Entity Reference | |||||
| 267 | { | |||||
| 268 | Id = _contra ctId, | |||||
| 269 | Lo gicalName = Contract .EntityLog icalName | |||||
| 270 | }, | |||||
| 271 | State = new Opti onSetValue ((int)Cont ractState. Invoiced), | |||||
| 272 | Status = new Opt ionSetValu e(3) | |||||
| 273 | }; | |||||
| 274 | _servicePr oxy.Execut e(setState Request); | |||||
| 275 | //</snippe tSetStateF orContract > | |||||
| 276 | ||||||
| 277 | Console.Wr ite("Contr act invoic ed, "); | |||||
| 278 | ||||||
| 279 | //<snippet CancelCont ract> | |||||
| 280 | // Cancel the contra ct. | |||||
| 281 | setStateRe quest = ne w SetState Request() | |||||
| 282 | { | |||||
| 283 | Entity Moniker = new Entity Reference | |||||
| 284 | { | |||||
| 285 | Id = _contra ctId, | |||||
| 286 | Lo gicalName = Contract .EntityLog icalName | |||||
| 287 | }, | |||||
| 288 | State = new Opti onSetValue ((int)Cont ractState. Canceled), | |||||
| 289 | Status = new Opt ionSetValu e(5) | |||||
| 290 | }; | |||||
| 291 | _servicePr oxy.Execut e(setState Request); | |||||
| 292 | ||||||
| 293 | //</snippe tCancelCon tract> | |||||
| 294 | Console.Wr ite("cance led, "); | |||||
| 295 | ||||||
| 296 | //<snippet RenewContr act> | |||||
| 297 | // Renew t he cancele d contract . | |||||
| 298 | RenewContr actRequest renewRequ est = new RenewContr actRequest () | |||||
| 299 | { | |||||
| 300 | Contra ctId = _co ntractId, | |||||
| 301 | Includ eCanceledL ines = tru e, | |||||
| 302 | Status = 1 | |||||
| 303 | }; | |||||
| 304 | RenewContr actRespons e renewRes ponse = | |||||
| 305 | (Renew ContractRe sponse)_se rviceProxy .Execute(r enewReques t); | |||||
| 306 | ||||||
| 307 | // Retriev e Id of re newed cont ract. | |||||
| 308 | _renewedId = ((Contr act)renewR esponse.En tity).Cont ractId.Val ue; | |||||
| 309 | ||||||
| 310 | //</snippe tRenewCont ract> | |||||
| 311 | // Display the Id of the renew ed contrac t. | |||||
| 312 | Console.Wr iteLine("a nd renewed ."); | |||||
| 313 | ||||||
| 314 | #endregion | |||||
| 315 | ||||||
| 316 | DeleteRequ iredRecord s(promptfo rDelete); | |||||
| 317 | } | |||||
| 318 | //</ snippetWor kingWithCo ntracts1> | |||||
| 319 | } | |||||
| 320 | ||||||
| 321 | // Catch any servi ce fault e xceptions that Micro soft Dynam ics CRM th rows. | |||||
| 322 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>) | |||||
| 323 | { | |||||
| 324 | // Y ou can han dle an exc eption her e or pass it back to the calli ng method. | |||||
| 325 | thro w; | |||||
| 326 | } | |||||
| 327 | } | |||||
| 328 | ||||||
| 329 | // / <summary > | |||||
| 330 | // / Creates any entity records t hat this s ample requ ires. | |||||
| 331 | // / </summar y> | |||||
| 332 | pu blic void CreateRequ iredRecord s() | |||||
| 333 | { | |||||
| 334 | // Insta ntiate an Account ob ject. | |||||
| 335 | // See t he Entity Metadata t opic in th e SDK docu mentation to determi ne | |||||
| 336 | // which attribute s must be set for ea ch entity. | |||||
| 337 | Account setupAccou nt = new A ccount() | |||||
| 338 | { | |||||
| 339 | Name = "Litwar e, Inc." | |||||
| 340 | }; | |||||
| 341 | _account Id = _serv iceProxy.C reate(setu pAccount); | |||||
| 342 | } | |||||
| 343 | ||||||
| 344 | // / <summary > | |||||
| 345 | // / Deletes any entity records t hat were c reated for this samp le. | |||||
| 346 | // / <param n ame="promp t">Indicat es whether to prompt the user | |||||
| 347 | // / to delet e the reco rds create d in this sample.</p aram> | |||||
| 348 | // / </summar y> | |||||
| 349 | pu blic void DeleteRequ iredRecord s(bool pro mpt) | |||||
| 350 | { | |||||
| 351 | // Two o f the cont racts, the ir associa ted accoun t and the contract t emplate | |||||
| 352 | // recor ds that we re created and used in this sa mple will continue t o exist | |||||
| 353 | // on yo ur system because co ntracts th at have be en invoice d cannot b e deleted | |||||
| 354 | // in Mi crosoft Dy namics CRM . They can only be p ut on hold or cancel ed. | |||||
| 355 | ||||||
| 356 | bool toB eDeleted = true; | |||||
| 357 | ||||||
| 358 | if (prom pt) | |||||
| 359 | { | |||||
| 360 | // A sk the use r if the c reated ent ities shou ld be dele ted. | |||||
| 361 | Cons ole.Write( "\nDo you want these entity re cords dele ted? (y/n) [y]: "); | |||||
| 362 | Stri ng answer = Console. ReadLine() ; | |||||
| 363 | if ( answer.Sta rtsWith("y ") || | |||||
| 364 | answer.Sta rtsWith("Y ") || | |||||
| 365 | answer == String.Emp ty) | |||||
| 366 | { | |||||
| 367 | toBeDelete d = true; | |||||
| 368 | } | |||||
| 369 | else | |||||
| 370 | { | |||||
| 371 | toBeDelete d = false; | |||||
| 372 | } | |||||
| 373 | } | |||||
| 374 | ||||||
| 375 | if (toBe Deleted) | |||||
| 376 | { | |||||
| 377 | _ser viceProxy. Delete(Con tract.Enti tyLogicalN ame, _seco ndCloneId) ; | |||||
| 378 | _ser viceProxy. Delete(Con tract.Enti tyLogicalN ame, _rene wedId); | |||||
| 379 | _ser viceProxy. Delete(Con tract.Enti tyLogicalN ame, _cont ractId); | |||||
| 380 | SetS tateReques t setState Request = new SetSta teRequest( ) | |||||
| 381 | { | |||||
| 382 | EntityMoni ker = new EntityRefe rence | |||||
| 383 | { | |||||
| 384 | Id = _ firstClone Id, | |||||
| 385 | Logica lName = Co ntract.Ent ityLogical Name | |||||
| 386 | }, | |||||
| 387 | State = ne w OptionSe tValue((in t)Contract State.Invo iced), | |||||
| 388 | Status = n ew OptionS etValue(3) | |||||
| 389 | }; | |||||
| 390 | _ser viceProxy. Execute(se tStateRequ est); | |||||
| 391 | setS tateReques t = new Se tStateRequ est() | |||||
| 392 | { | |||||
| 393 | EntityMoni ker = new EntityRefe rence | |||||
| 394 | { | |||||
| 395 | Id = _ firstClone Id, | |||||
| 396 | Logica lName = Co ntract.Ent ityLogical Name | |||||
| 397 | }, | |||||
| 398 | State = ne w OptionSe tValue((in t)Contract State.Canc eled), | |||||
| 399 | Status = n ew OptionS etValue(5) | |||||
| 400 | }; | |||||
| 401 | _ser viceProxy. Execute(se tStateRequ est); | |||||
| 402 | _ser viceProxy. Delete(Con tract.Enti tyLogicalN ame, _firs tCloneId); | |||||
| 403 | _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntId); | |||||
| 404 | Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. "); | |||||
| 405 | } | |||||
| 406 | } | |||||
| 407 | ||||||
| 408 | #e ndregion H ow To Samp le Code | |||||
| 409 | ||||||
| 410 | #r egion Main method | |||||
| 411 | ||||||
| 412 | // / <summary > | |||||
| 413 | // / Standard Main() me thod used by most SD K samples. | |||||
| 414 | // / </summar y> | |||||
| 415 | // / <param n ame="args" ></param> | |||||
| 416 | st atic publi c void Mai n(string[] args) | |||||
| 417 | { | |||||
| 418 | try | |||||
| 419 | { | |||||
| 420 | // O btain the target org anization' s Web addr ess and cl ient logon | |||||
| 421 | // c redentials from the user. | |||||
| 422 | Serv erConnecti on serverC onnect = n ew ServerC onnection( ); | |||||
| 423 | Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on(); | |||||
| 424 | ||||||
| 425 | Work ingWithCon tracts app = new Wor kingWithCo ntracts(); | |||||
| 426 | app. Run(config , true); | |||||
| 427 | } | |||||
| 428 | catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex ) | |||||
| 429 | { | |||||
| 430 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 431 | Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p); | |||||
| 432 | Cons ole.WriteL ine("Code: {0}", ex. Detail.Err orCode); | |||||
| 433 | Cons ole.WriteL ine("Messa ge: {0}", ex.Detail. Message); | |||||
| 434 | Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text); | |||||
| 435 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 436 | null == ex .Detail.In nerFault ? "No Inner Fault" : "Has Inner Fault"); | |||||
| 437 | } | |||||
| 438 | catch (S ystem.Time outExcepti on ex) | |||||
| 439 | { | |||||
| 440 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 441 | Cons ole.WriteL ine("Messa ge: {0}", ex.Message ); | |||||
| 442 | Cons ole.WriteL ine("Stack Trace: {0 }", ex.Sta ckTrace); | |||||
| 443 | Cons ole.WriteL ine("Inner Fault: {0 }", | |||||
| 444 | null == ex .InnerExce ption.Mess age ? "No Inner Faul t" : ex.In nerExcepti on.Message ); | |||||
| 445 | } | |||||
| 446 | catch (S ystem.Exce ption ex) | |||||
| 447 | { | |||||
| 448 | Cons ole.WriteL ine("The a pplication terminate d with an error."); | |||||
| 449 | Cons ole.WriteL ine(ex.Mes sage); | |||||
| 450 | ||||||
| 451 | // D isplay the details o f the inne r exceptio n. | |||||
| 452 | if ( ex.InnerEx ception != null) | |||||
| 453 | { | |||||
| 454 | Console.Wr iteLine(ex .InnerExce ption.Mess age); | |||||
| 455 | ||||||
| 456 | FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n | |||||
| 457 | as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>; | |||||
| 458 | if (fe != null) | |||||
| 459 | { | |||||
| 460 | Consol e.WriteLin e("Timesta mp: {0}", fe.Detail. Timestamp) ; | |||||
| 461 | Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code); | |||||
| 462 | Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage); | |||||
| 463 | Consol e.WriteLin e("Plugin Trace: {0} ", fe.Deta il.TraceTe xt); | |||||
| 464 | Consol e.WriteLin e("Inner F ault: {0}" , | |||||
| 465 | nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault"); | |||||
| 466 | } | |||||
| 467 | } | |||||
| 468 | } | |||||
| 469 | // Addit ional exce ptions to catch: Sec urityToken Validation Exception, ExpiredSe curityToke nException , | |||||
| 470 | // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion. | |||||
| 471 | ||||||
| 472 | finally | |||||
| 473 | { | |||||
| 474 | Cons ole.WriteL ine("Press <Enter> t o exit."); | |||||
| 475 | Cons ole.ReadLi ne(); | |||||
| 476 | } | |||||
| 477 | } | |||||
| 478 | #e ndregion M ain method | |||||
| 479 | } | |||||
| 480 | } | |||||
| 481 | //</snippe tWorkingWi thContract s> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.