492. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:56:48 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.

492.1 Files compared

# 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\Metadata\OptionSets WorkWithOptionSets.cs Tue Dec 20 19:51:47 2016 UTC
2 Wed Feb 1 19:56:48 2017 UTC

492.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 502

492.3 Comparison options

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

492.4 Active regular expressions

No regular expressions were active.

492.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //        
3   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
4   //        
5   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
6   //        
7   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
8   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
9   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
10   //        
11   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
12   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
13   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
14   //  PARTIC ULAR PURPO SE.        
15   //        
16   // ======= ========== ========== ========== ========== ========== ========== ==        
17   //<snippet WorkwithGl obalOption Sets>        
18   using Syst em;        
19   using Syst em.Linq;        
20   using Syst em.Xml.Lin q;        
21   using Syst em.Service Model;        
22   using Syst em.Service Model.Desc ription;        
23          
24   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
25   // found i n the SDK\ bin folder .        
26   using Micr osoft.Xrm. Sdk;        
27   using Micr osoft.Xrm. Sdk.Client ;        
28   using Micr osoft.Xrm. Sdk.Query;        
29   using Micr osoft.Xrm. Sdk.Metada ta;        
30   using Micr osoft.Xrm. Sdk.Discov ery;        
31   using Micr osoft.Xrm. Sdk.Messag es;        
32          
33   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
34   // found i n the SDK\ bin folder .        
35   using Micr osoft.Crm. Sdk.Messag es;        
36          
37          
38   namespace  Microsoft. Crm.Sdk.Sa mples        
39   {        
40          
41       /// <s ummary>        
42       /// Cr eate a glo bal option  set.        
43       /// Se t the opti ons for th at option  set.        
44       /// Cr eate a new  reference  to that o ption set  on an enti ty.        
45       /// Up date the o ption set' s properti es.        
46       /// Ch eck the gl obal optio n set for  dependenci es.        
47       /// De lete the o ption set.        
48       /// </ summary>        
49       public  class Wor kwithGloba lOptionSet s        
50       {        
51           #r egion Clas s Level Me mbers        
52          
53           // / <summary >        
54           // / Stores t he organiz ation serv ice proxy.        
55           // / </summar y>        
56           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
57                   
58           //  Specify w hich langu age code t o use in t he sample.  If you ar e using a  language        
59           //  other tha n US Engli sh, you wi ll need to  modify th is value a ccordingly .        
60           //  See http: //msdn.mic rosoft.com /en-us/lib rary/0h88f ahh.aspx        
61           pr ivate cons t int _lan guageCode  = 1033;        
62          
63           //  Specify t he option  set's sche ma name is  used in m any operat ions relat ed to        
64           //  global op tion sets.        
65           pr ivate cons t string _ globalOpti onSetName  = "sample_ exampleopt ionset";        
66          
67           //  Define th e IDs need ed for thi s sample.        
68           pr ivate Guid  _optionSe tId;        
69           pr ivate int  _insertedO ptionValue ;        
70          
71           #e ndregion C lass Level  Members        
72          
73           #r egion How  To Sample  Code        
74           // / <summary >        
75           // / Create a  global op tion set.        
76           // / Set the  options fo r that opt ion set.        
77           // / Create a  new refer ence to th at option  set on an  entity.        
78           // / Update t he option  set's prop erties.        
79           // / Check th e global o ption set  for depend encies.        
80           // / Delete t he option  set.        
81           // / </summar y>        
82           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
83           // / <param n ame="promp tForDelete ">When Tru e, the use r will be  prompted t o delete a ll        
84           // / created  entities.< /param>        
85           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete)        
86           {        
87                try        
88                {        
89          
90                    // C onnect to  the Organi zation ser vice.         
91                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
92                    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 ))        
93                    {        
94                         // This st atement is  required  to enable  early-boun d type sup port.        
95                         _servicePr oxy.Enable ProxyTypes ();        
96          
97                         //<snippet WorkwithGl obalOption Sets1>        
98                         //<snippet WorkwithGl obalOption Sets2>        
99                         #region Ho w to creat e global o ption set        
100                         // Define  the reques t object a nd pass to  the servi ce.        
101                         CreateOpti onSetReque st createO ptionSetRe quest = ne w CreateOp tionSetReq uest        
102                         {        
103                             // Cre ate a glob al option  set (Optio nSetMetada ta).        
104                             Option Set = new  OptionSetM etadata        
105                             {        
106                                 Na me = _glob alOptionSe tName,        
107                                 Di splayName  = new Labe l("Example  Option Se t", _langu ageCode),        
108                                 Is Global = t rue,        
109                                 Op tionSetTyp e = Option SetType.Pi cklist,        
110                                 Op tions =         
111                             {        
112                                 ne w OptionMe tadata(new  Label("Op en", _lang uageCode),  null),        
113                                 ne w OptionMe tadata(new  Label("Su spended",  _languageC ode), null ),        
114                                 ne w OptionMe tadata(new  Label("Ca ncelled",  _languageC ode), null ),        
115                                 ne w OptionMe tadata(new  Label("Cl osed", _la nguageCode ), null)        
116                             }        
117                             }        
118                         };        
119          
120                         // Execute  the reque st.        
121                         CreateOpti onSetRespo nse option sResp =        
122                             (Creat eOptionSet Response)_ servicePro xy.Execute (createOpt ionSetRequ est);        
123          
124                         //</snippe tWorkwithG lobalOptio nSets2>        
125                         #endregion  How to cr eate globa l option s et        
126          
127                         // Store t he option  set's id a s it will  be needed  to find al l the        
128                         // depende nt compone nts.        
129                         _optionSet Id = optio nsResp.Opt ionSetId;        
130                         Console.Wr iteLine("T he global  option set  has been  created.") ;        
131          
132                         #region Ho w to creat e a pickli st linked  to the glo bal option  set        
133                         //<snippet WorkwithGl obalOption Sets3>        
134                         // Create  a Picklist  linked to  the optio n set.        
135                         // Specify  which ent ity will o wn the pic klist, and  create it .        
136                         CreateAttr ibuteReque st createR equest = n ew CreateA ttributeRe quest        
137                         {        
138                             Entity Name = Con tact.Entit yLogicalNa me,        
139                             Attrib ute = new  PicklistAt tributeMet adata        
140                             {        
141                                 Sc hemaName =  "sample_e xamplepick list",        
142                                 Lo gicalName  = "sample_ examplepic klist",        
143                                 Di splayName  = new Labe l("Example  Picklist" , _languag eCode),        
144                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one),        
145          
146                                 //  In order  to relate  the pickli st to the  global opt ion set, b e sure        
147                                 //  to specif y the two  attributes  below app ropriately .        
148                                 //  Failing t o do so wi ll lead to  errors.        
149                                 Op tionSet =  new Option SetMetadat a        
150                                 {        
151                                      IsGlobal  = true,        
152                                      Name = _ globalOpti onSetName        
153                                 }        
154                             }        
155                         };        
156          
157                         _servicePr oxy.Execut e(createRe quest);        
158                         //</snippe tWorkwithG lobalOptio nSets3>        
159                         Console.Wr iteLine("R eferring p icklist at tribute cr eated.");        
160                         #endregion  How to cr eate a pic klist link ed to the  global opt ion set        
161          
162                         #region Ho w to updat e a global  option se t        
163                         //<snippet WorkwithGl obalOption Sets4>        
164                         // Use Upd ateOptionS etRequest  to update  the basic  informatio n of an op tion        
165                         // set. Up dating opt ion set va lues requi res differ ent messag es (see be low).        
166                         UpdateOpti onSetReque st updateO ptionSetRe quest = ne w UpdateOp tionSetReq uest        
167                         {        
168                             Option Set = new  OptionSetM etadata        
169                             {        
170                                 Di splayName  = new Labe l("Updated  Option Se t", _langu ageCode),        
171                                 Na me = _glob alOptionSe tName,        
172                                 Is Global = t rue        
173                             }        
174                         };        
175          
176                         _servicePr oxy.Execut e(updateOp tionSetReq uest);        
177          
178                         //Publish  the Option Set        
179                         PublishXml Request px Req1 = new  PublishXm lRequest {  Parameter Xml = Stri ng.Format( "<importex portxml><o ptionsets> <optionset >{0}</opti onset></op tionsets>< /importexp ortxml>",  _globalOpt ionSetName ) };        
180                         _servicePr oxy.Execut e(pxReq1);        
181                         //</snippe tWorkwithG lobalOptio nSets4>        
182                         Console.Wr iteLine("O ption Set  display na me changed .");        
183                         #endregion  How to up date a glo bal option  set prope rties        
184          
185                         #region Ho w to inser t a new op tion item  in a globa l option s et        
186                         //<snippet WorkwithGl obalOption Sets5>        
187                         // Use Ins ertOptionV alueReques t to inser t a new op tion into         
188                         // global  option set .        
189                         InsertOpti onValueReq uest inser tOptionVal ueRequest  =        
190                             new In sertOption ValueReque st        
191                             {        
192                                 Op tionSetNam e = _globa lOptionSet Name,        
193                                 La bel = new  Label("New  Picklist  Label", _l anguageCod e)        
194                             };        
195          
196                         // Execute  the reque st and sto re the new ly inserte d option v alue         
197                         // for cle anup, used  in the la ter part o f this sam ple.        
198                         _insertedO ptionValue  = ((Inser tOptionVal ueResponse )_serviceP roxy.Execu te(        
199                             insert OptionValu eRequest)) .NewOption Value;        
200          
201                         //Publish  the Option Set        
202                         PublishXml Request px Req2 = new  PublishXm lRequest {  Parameter Xml = Stri ng.Format( "<importex portxml><o ptionsets> <optionset >{0}</opti onset></op tionsets>< /importexp ortxml>",  _globalOpt ionSetName ) };        
203                         _servicePr oxy.Execut e(pxReq2);        
204                         //</snippe tWorkwithG lobalOptio nSets5>        
205                         Console.Wr iteLine("C reated {0}  with the  value of { 1}.",        
206                             insert OptionValu eRequest.L abel.Local izedLabels [0].Label,        
207                             _inser tedOptionV alue);        
208                         #endregion  How to in sert a new  option it em in a gl obal optio n set        
209          
210                         #region Ho w to retri eve a glob al option  set by it' s name        
211                         //<snippet WorkwithGl obalOption Sets6>        
212                         // Use the  RetrieveO ptionSetRe quest mess age to ret rieve          
213                         // a globa l option s et by it's  name.        
214                         RetrieveOp tionSetReq uest retri eveOptionS etRequest  =        
215                             new Re trieveOpti onSetReque st        
216                             {        
217                                 Na me = _glob alOptionSe tName        
218                             };        
219          
220                         // Execute  the reque st.        
221                         RetrieveOp tionSetRes ponse retr ieveOption SetRespons e =        
222                             (Retri eveOptionS etResponse )_serviceP roxy.Execu te(        
223                             retrie veOptionSe tRequest);        
224          
225                         Console.Wr iteLine("R etrieved { 0}.",        
226                             retrie veOptionSe tRequest.N ame);        
227          
228                         // Access  the retrie ved Option SetMetadat a.        
229                         OptionSetM etadata re trievedOpt ionSetMeta data =        
230                             (Optio nSetMetada ta)retriev eOptionSet Response.O ptionSetMe tadata;        
231          
232                         // Get the  current o ptions lis t for the  retrieved  attribute.        
233                         OptionMeta data[] opt ionList =        
234                             retrie vedOptionS etMetadata .Options.T oArray();        
235                         //</snippe tWorkwithG lobalOptio nSets6>        
236                         #endregion  How to re trieve a g lobal opti on set by  it's name        
237          
238                         #region Ho w to updat e an optio n item in  a picklist        
239                         //<snippet WorkwithGl obalOption Sets7>        
240                         // In orde r to chang e labels o n option s et values  (or delete ) option s et        
241                         // values,  you must  use Update OptionValu eRequest         
242                         // (or Del eteOptionV alueReques t).        
243                         UpdateOpti onValueReq uest updat eOptionVal ueRequest  =        
244                             new Up dateOption ValueReque st        
245                             {        
246                                 Op tionSetNam e = _globa lOptionSet Name,        
247                                 //  Update th e second o ption valu e.        
248                                 Va lue = opti onList[1]. Value.Valu e,        
249                                 La bel = new  Label("Upd ated Optio n 1", _lan guageCode)        
250                             };        
251          
252                         _servicePr oxy.Execut e(updateOp tionValueR equest);        
253          
254                         //Publish  the Option Set        
255                         PublishXml Request px Req3 = new  PublishXm lRequest {  Parameter Xml = Stri ng.Format( "<importex portxml><o ptionsets> <optionset >{0}</opti onset></op tionsets>< /importexp ortxml>",  _globalOpt ionSetName ) };        
256                         _servicePr oxy.Execut e(pxReq3);        
257          
258                                
259          
260                         //</snippe tWorkwithG lobalOptio nSets7>        
261                         Console.Wr iteLine("O ption Set  option lab el changed .");        
262                         #endregion  How to up date an op tion item  in a pickl ist        
263          
264                         #region Ho w to chang e the orde r of optio ns of a gl obal optio n set        
265                         //<snippet WorkwithGl obalOption Sets8>        
266                         // Change  the order  of the ori ginal opti on's list.        
267                         // Use the  OrderBy ( OrderByDes cending) l inq functi on to sort  options i n          
268                         // ascendi ng (descen ding) orde r accordin g to label  text.        
269                         // For asc ending ord er use thi s:        
270                         var update OptionList  =        
271                             option List.Order By(x => x. Label.Loca lizedLabel s[0].Label ).ToList() ;        
272          
273                         // For des cending or der use th is:        
274                         // var upd ateOptionL ist =        
275                         //      op tionList.O rderByDesc ending(        
276                         //      x  => x.Label .Localized Labels[0]. Label).ToL ist();        
277          
278                         // Create  the reques t.        
279                         OrderOptio nRequest o rderOption Request =  new OrderO ptionReque st        
280                         {        
281                             // Set  the prope rties for  the reques t.        
282                             Option SetName =  _globalOpt ionSetName ,        
283                             // Set  the chang ed order u sing Selec t linq fun ction         
284                             // to  get only v alues in a n array fr om the cha nged optio n list.        
285                             Values  = updateO ptionList. Select(x = > x.Value. Value).ToA rray()        
286                         };        
287          
288                         // Execute  the reque st        
289                         _servicePr oxy.Execut e(orderOpt ionRequest );        
290          
291                         //Publish  the Option Set        
292                         PublishXml Request px Req4 = new  PublishXm lRequest {  Parameter Xml = Stri ng.Format( "<importex portxml><o ptionsets> <optionset >{0}</opti onset></op tionsets>< /importexp ortxml>",  _globalOpt ionSetName ) };        
293                         _servicePr oxy.Execut e(pxReq4);        
294                         //</snippe tWorkwithG lobalOptio nSets8>        
295                         Console.Wr iteLine("O ption Set  option ord er changed ");        
296                         #endregion  How to ch ange the o rder of op tions of a  global op tion set        
297          
298                         #region Ho w to retri eve all gl obal optio n sets        
299                         //<snippet WorkwithGl obalOption Sets9>        
300                         // Use Ret rieveAllOp tionSetsRe quest to r etrieve al l global o ption sets .        
301                         // Create  the reques t.        
302                         RetrieveAl lOptionSet sRequest r etrieveAll OptionSets Request =        
303                             new Re trieveAllO ptionSetsR equest();        
304          
305                         // Execute  the reque st        
306                         RetrieveAl lOptionSet sResponse  retrieveAl lOptionSet sResponse  =        
307                             (Retri eveAllOpti onSetsResp onse)_serv iceProxy.E xecute(        
308                             retrie veAllOptio nSetsReque st);        
309          
310                         // Now you  can use R etrieveAll OptionSets Response.O ptionSetMe tadata pro perty to         
311                         // work wi th all ret rieved opt ion sets.        
312                         if (retrie veAllOptio nSetsRespo nse.Option SetMetadat a.Count()  > 0)        
313                         {        
314                             Consol e.WriteLin e("All the  global op tion sets  retrieved  as below:" );        
315                             int co unt = 1;        
316                             foreac h (OptionS etMetadata Base optio nSetMetada ta in        
317                                 re trieveAllO ptionSetsR esponse.Op tionSetMet adata)        
318                             {        
319                                 Co nsole.Writ eLine("{0}  {1}", cou nt++,        
320                                      (optionS etMetadata .DisplayNa me.Localiz edLabels.C ount >0)?  optionSetM etadata.Di splayName. LocalizedL abels[0].L abel : Str ing.Empty) ;        
321                             }        
322                         }        
323                         //</snippe tWorkwithG lobalOptio nSets9>        
324                         #endregion  How to re trieve all  global op tion sets        
325          
326          
327                         //</snippe tWorkwithG lobalOptio nSets1>        
328          
329                         DeleteRequ iredRecord s(promptFo rDelete);        
330                    }        
331                }        
332                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
333                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
334                {        
335                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
336                    thro w;        
337                }        
338           }        
339          
340           // / <summary >        
341           // / Deletes  any entity  records t hat were c reated for  this samp le.        
342           // / <param n ame="promp t">Indicat es whether  to prompt  the user  to         
343           // / delete t he records  created i n this sam ple.</para m>        
344           // / </summar y>        
345           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
346           {        
347                bool del eteRecords  = true;        
348          
349                if (prom pt)        
350                {        
351                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n)");        
352                    Stri ng answer  = Console. ReadLine() ;        
353          
354                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ));        
355                }        
356          
357                if (dele teRecords)        
358                {        
359                    #reg ion How to  delete a  option fro m a option  set        
360                    //<s nippetWork withGlobal OptionSets 11>        
361                    // U se the Del eteOptionV alueReques t message         
362                    // t o remove t he newly i nserted la bel.        
363                    Dele teOptionVa lueRequest  deleteOpt ionValueRe quest =        
364                         new Delete OptionValu eRequest        
365                    {        
366                         OptionSetN ame = _glo balOptionS etName,        
367                         Value = _i nsertedOpt ionValue        
368                    };        
369          
370                    // E xecute the  request.        
371                    _ser viceProxy. Execute(de leteOption ValueReque st);        
372                    //</ snippetWor kwithGloba lOptionSet s11>        
373          
374                    Cons ole.WriteL ine("Optio n Set opti on removed .");        
375                    #end region How  to delete  a option  from a opt ion set        
376          
377                    #reg ion How to  delete at tribute        
378                    //<s nippetWork withGlobal OptionSets 12>        
379                    // C reate the  request to  see which  component s have a d ependency  on the        
380                    // g lobal opti on set.        
381                    Retr ieveDepend entCompone ntsRequest  dependenc yRequest =        
382                         new Retrie veDependen tComponent sRequest        
383                         {        
384                             Object Id = _opti onSetId,        
385                             Compon entType =  (int)compo nenttype.O ptionSet        
386                         };        
387          
388                    Retr ieveDepend entCompone ntsRespons e dependen cyResponse  =        
389                         (RetrieveD ependentCo mponentsRe sponse)_se rviceProxy .Execute(        
390                         dependency Request);        
391          
392                    // H ere you wo uld check  the depend encyRespon se.EntityC ollection  property        
393                    // a nd act as  appropriat e. However , we know  there is e xactly one          
394                    // d ependency  so this ex ample deal s with it  directly a nd deletes          
395                    // t he previou sly create d attribut e.        
396                    Dele teAttribut eRequest d eleteAttri buteReques t =        
397                         new Delete AttributeR equest        
398                    {        
399                         EntityLogi calName =  Contact.En tityLogica lName,        
400                         LogicalNam e = "sampl e_examplep icklist"        
401                    };        
402          
403                    _ser viceProxy. Execute(de leteAttrib uteRequest );        
404                          
405                    Cons ole.WriteL ine("Refer ring attri bute delet ed.");        
406                    #end region How  to delete  attribute        
407          
408                    #reg ion How to  delete gl obal optio n set        
409                            
410                    // F inally, de lete the g lobal opti on set. At tempting t his before  deleting        
411                    // t he picklis t above wi ll result  in an exce ption bein g thrown.        
412                    //<s nippetWork withGlobal OptionSets .DeleteOpt ionSetRequ est>        
413                    Dele teOptionSe tRequest d eleteReque st = new D eleteOptio nSetReques t        
414                    {        
415                         Name = _gl obalOption SetName        
416                    };        
417          
418                    _ser viceProxy. Execute(de leteReques t);        
419                    //</ snippetWor kwithGloba lOptionSet s.DeleteOp tionSetReq uest>        
420                    //</ snippetWor kwithGloba lOptionSet s12>        
421                    Cons ole.WriteL ine("Globa l Option S et deleted ");        
422                    #end region How  to delete  global op tion set        
423                }        
424           }        
425          
426           #e ndregion H ow To Samp le Code        
427          
428           #r egion Main        
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                    Work withGlobal OptionSets  app = new  WorkwithG lobalOptio nSets();        
443                    app. Run(config , true);        
444                }        
445                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
446                {        
447                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
448                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
449                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
450                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
451                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
452                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
453                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
454                }        
455                catch (S ystem.Time outExcepti on ex)        
456                {        
457                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
458                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
459                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
460                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
461                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
462                }        
463                catch (S ystem.Exce ption ex)        
464                {        
465                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
466                    Cons ole.WriteL ine(ex.Mes sage);        
467          
468                    // D isplay the  details o f the inne r exceptio n.        
469                    if ( ex.InnerEx ception !=  null)        
470                    {        
471                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
472          
473                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e =         
474                             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("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
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          
490                finally        
491                {        
492                             
493                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
494                    Cons ole.ReadLi ne();        
495                }        
496          
497           }        
498           #e ndregion M ain        
499          
500       }        
501   }        
502   //</snippe tWorkwithG lobalOptio nSets>