661. Araxis Merge File Comparison Report

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

661.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\Solutions GetSolutionDependencies.cs Tue Dec 20 19:51:43 2016 UTC
2 Wed Feb 1 19:56:55 2017 UTC

661.2 Comparison summary

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

661.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

661.4 Active regular expressions

No regular expressions were active.

661.5 Comparison detail

1          
2   // ======= ========== ========== ========== ========== ========== ========== ==        
3   //        
4   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
5   //        
6   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
7   //        
8   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
9   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
10   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
11   //        
12   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
13   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
14   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
15   //  PARTIC ULAR PURPO SE.        
16   //        
17   // ======= ========== ========== ========== ========== ========== ========== ==        
18   //<snippet GetSolutio nDependenc ies>        
19   using Syst em;        
20   using Syst em.Collect ions.Gener ic;        
21   using Syst em.Linq;        
22   using Syst em.Service Model;        
23   using Syst em.Service Model.Desc ription;        
24          
25   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
26   // found i n the SDK\ bin folder .        
27   using Micr osoft.Xrm. Sdk;        
28   using Micr osoft.Xrm. Sdk.Client ;        
29   using Micr osoft.Xrm. Sdk.Metada ta;        
30   using Micr osoft.Xrm. Sdk.Query;        
31   using Micr osoft.Xrm. Sdk.Discov ery;        
32   using Micr osoft.Xrm. Sdk.Messag es;        
33          
34   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
35   // found i n the SDK\ bin folder .        
36   using Micr osoft.Crm. Sdk.Messag es;        
37          
38          
39   namespace  Microsoft. Crm.Sdk.Sa mples        
40   {        
41          
42       /// <s ummary>        
43       /// De monstrates  how to de tect any d ependencie s prior to  deleting         
44       /// so lution com ponent.        
45       /// </ summary>        
46       public  class Get SolutionDe pendencies        
47       {        
48           #r egion Clas s Level Me mbers        
49                   
50           // / <summary >        
51           // / Stores t he organiz ation serv ice proxy.        
52           // / </summar y>        
53           Or ganization ServicePro xy _servic eProxy;        
54          
55           pr ivate Guid  _publishe rId;        
56           pr ivate cons t string _ primarySol utionName  = "Primary Solution";        
57           pr ivate Guid  _primaryS olutionId;        
58           pr ivate Guid  _secondar ySolutionI d;        
59           pr ivate cons t String _ prefix = " sample";        
60           pr ivate cons t String _ globalOpti onSetName  = _prefix  + "_exampl eoptionset ";        
61           pr ivate Guid ? _globalO ptionSetId ;        
62           pr ivate cons t String _ picklistNa me = _pref ix + "_exa mplepickli st";        
63          
64          
65           //  Specify w hich langu age code t o use in t he sample.  If you ar e using a  language        
66           //  other tha n US Engli sh, you wi ll need to  modify th is value a ccordingly .        
67           //  See http: //msdn.mic rosoft.com /en-us/lib rary/0h88f ahh.aspx        
68           pr ivate cons t int _lan guageCode  = 1033;        
69          
70          
71           #e ndregion C lass Level  Members        
72          
73           #r egion How  To Sample  Code        
74           // / <summary >        
75           // / Shows ho w to detec t dependen cies that  may cause  a managed  solution t o become        
76           // / un-delet able.        
77           //        
78           // / Get all  solution c omponents  of a solut ion        
79           // / For each  solution  component,  list the  dependenci es upon th at compone nt.        
80           // / </summar y>        
81           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
82           // / <param n ame="promp tForDelete ">When Tru e, the use r will be  prompted t o delete a ll        
83           // / created  entities.< /param>        
84           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete)        
85           {        
86                try        
87                {        
88          
89                    // C onnect to  the Organi zation ser vice.         
90                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
91                    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 ))        
92                    {        
93                         // This st atement is  required  to enable  early-boun d type sup port.        
94                         _servicePr oxy.Enable ProxyTypes ();        
95          
96                         // Call th e method t o create a ny data th at this sa mple requi res.        
97                         CreateRequ iredRecord s();        
98                         //<snippet GetSolutio nDependenc ies1>        
99          
100                         // Grab al l Solution  Component s for a so lution.        
101                         QueryByAtt ribute com ponentQuer y = new Qu eryByAttri bute        
102                         {        
103                             Entity Name = Sol utionCompo nent.Entit yLogicalNa me,        
104                             Column Set = new  ColumnSet( "component type", "ob jectid", " solutionco mponentid" , "solutio nid"),        
105                             Attrib utes = { " solutionid " },        
106          
107                             // In  your code,  this valu e would pr obably com e from ano ther query .        
108                             Values  = { _prim arySolutio nId }        
109                         };        
110          
111                         IEnumerabl e<Solution Component>  allCompon ents =        
112                             _servi ceProxy.Re trieveMult iple(compo nentQuery) .Entities. Cast<Solut ionCompone nt>();        
113          
114                         foreach (S olutionCom ponent com ponent in  allCompone nts)        
115                         {        
116                             // For  each solu tion compo nent, retr ieve all d ependencie s for the  component.        
117                             Retrie veDependen tComponent sRequest d ependentCo mponentsRe quest =        
118                                 ne w Retrieve DependentC omponentsR equest        
119                                 {        
120                                      Componen tType = co mponent.Co mponentTyp e.Value,        
121                                      ObjectId  = compone nt.ObjectI d.Value        
122                                 };        
123                             Retrie veDependen tComponent sResponse  dependentC omponentsR esponse =        
124                                 (R etrieveDep endentComp onentsResp onse)_serv iceProxy.E xecute(dep endentComp onentsRequ est);        
125          
126                             // If  there are  no depende nt compone nts, we ca n ignore t his compon ent.        
127                             if (de pendentCom ponentsRes ponse.Enti tyCollecti on.Entitie s.Any() ==  false)        
128                                 co ntinue;        
129          
130                             // If  there are  dependenci es upon th is solutio n componen t, and the  solution        
131                             // its elf is man aged, then  you will  be unable  to delete  the soluti on.        
132                             Consol e.WriteLin e("Found { 0} depende ncies for  Component  {1} of typ e {2}",        
133                                 de pendentCom ponentsRes ponse.Enti tyCollecti on.Entitie s.Count,        
134                                 co mponent.Ob jectId.Val ue,        
135                                 co mponent.Co mponentTyp e.Value        
136                                 );        
137                             //A mo re complet e report r equires mo re code        
138                             foreac h (Depende ncy d in d ependentCo mponentsRe sponse.Ent ityCollect ion.Entiti es)        
139                             {        
140                                 De pendencyRe port(d);        
141                             }        
142                         }        
143                         //</snippe tGetSoluti onDependen cies1>        
144          
145                     //F ind out if  any depen dencies on  a  specif ic global  option set  would pre vent it fr om being d eleted        
146                         //<snippet GetSolutio nDependenc ies8>        
147                         // Use the  RetrieveO ptionSetRe quest mess age to ret rieve          
148                         // a globa l option s et by it's  name.        
149                         RetrieveOp tionSetReq uest retri eveOptionS etRequest  =        
150                             new Re trieveOpti onSetReque st        
151                             {        
152                              Name  = _globalO ptionSetNa me        
153                             };        
154          
155                         // Execute  the reque st.        
156                         RetrieveOp tionSetRes ponse retr ieveOption SetRespons e =        
157                             (Retri eveOptionS etResponse )_serviceP roxy.Execu te(        
158                             retrie veOptionSe tRequest);        
159                         _globalOpt ionSetId =  retrieveO ptionSetRe sponse.Opt ionSetMeta data.Metad ataId;        
160                         if (_globa lOptionSet Id != null )        
161                                
162                          //Use the  global Op tionSet Me tadataId w ith the ap propriate  componentt ype        
163                          // to cal l Retrieve Dependenci esForDelet eRequest        
164                          RetrieveD ependencie sForDelete Request re trieveDepe ndenciesFo rDeleteReq uest = new  RetrieveD ependencie sForDelete Request         
165                                
166                          Component Type = (in t)componen ttype.Opti onSet,        
167                          ObjectId  = (Guid)_g lobalOptio nSetId        
168                         };        
169          
170                          RetrieveD ependencie sForDelete Response r etrieveDep endenciesF orDeleteRe sponse =        
171                           (Retriev eDependenc iesForDele teResponse )_serviceP roxy.Execu te(retriev eDependenc iesForDele teRequest) ;        
172                          Console.W riteLine(" ");        
173                          foreach ( Dependency  d in retr ieveDepend enciesForD eleteRespo nse.Entity Collection .Entities)        
174                          {        
175          
176                           if (d.De pendentCom ponentType .Value ==  2)//Just t esting for  Attribute s        
177                           {        
178                            String  attributeL abel = "";        
179                            Retriev eAttribute Request re trieveAttr ibuteReque st = new R etrieveAtt ributeRequ est        
180                            {        
181                             Metada taId = (Gu id)d.Depen dentCompon entObjectI d        
182                            };        
183                            Retriev eAttribute Response r etrieveAtt ributeResp onse = (Re trieveAttr ibuteRespo nse)_servi ceProxy.Ex ecute(retr ieveAttrib uteRequest );        
184          
185                            Attribu teMetadata  attmet =  retrieveAt tributeRes ponse.Attr ibuteMetad ata;        
186          
187                            attribu teLabel =  attmet.Dis playName.U serLocaliz edLabel.La bel;        
188                                   
189                             Consol e.WriteLin e("An {0}  named {1}  will preve nt deletin g the {2}  global opt ion set.",          
190                            (compon enttype)d. DependentC omponentTy pe.Value,         
191                            attribu teLabel,         
192                            _global OptionSetN ame);        
193                           }        
194                          }                          
195                         }        
196          
197                         //</snippe tGetSoluti onDependen cies8>        
198          
199                         DeleteRequ iredRecord s(promptFo rDelete);        
200                    }        
201                }        
202          
203                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
204                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
205                {        
206                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
207                    thro w;        
208                }        
209           }        
210          
211           // <snippetGe tSolutionD ependencie s7>        
212           // / <summary >        
213           // / Shows ho w to get a  more frie ndly messa ge based o n informat ion within  the depen dency        
214           // / <param n ame="depen dency">A D ependency  returned f rom the Re trieveDepe ndentCompo nents mess age</param >        
215           // / </summar y>         
216        publi c void Dep endencyRep ort(Depend ency depen dency)        
217           {        
218         //Th ese string s represen t paramete rs for the  message.        
219            S tring depe ndentCompo nentName =  "";        
220            S tring depe ndentCompo nentTypeNa me = "";        
221            S tring depe ndentCompo nentSoluti onName = " ";        
222            S tring requ iredCompon entName =  "";        
223            S tring requ iredCompon entTypeNam e = "";        
224            S tring requ iredCompon entSolutio nName = "" ;        
225          
226         //Th e Componen tType glob al Option  Set contai ns options  for each  possible c omponent.        
227            R etrieveOpt ionSetRequ est compon entTypeReq uest = new  RetrieveO ptionSetRe quest        
228            {        
229              Name = "co mponenttyp e"        
230            } ;        
231          
232            R etrieveOpt ionSetResp onse compo nentTypeRe sponse = ( RetrieveOp tionSetRes ponse)_ser viceProxy. Execute(co mponentTyp eRequest);        
233            O ptionSetMe tadata com ponentType OptionSet  = (OptionS etMetadata )component TypeRespon se.OptionS etMetadata ;        
234         // M atch the C omponent t ype with t he option  value and  get the la bel value  of the opt ion.        
235            f oreach (Op tionMetada ta opt in  componentT ypeOptionS et.Options )        
236            {        
237              if (depend ency.Depen dentCompon entType.Va lue == opt .Value)        
238              {        
239               dependent ComponentT ypeName =  opt.Label. UserLocali zedLabel.L abel;        
240              }        
241              if (depend ency.Requi redCompone ntType.Val ue == opt. Value)        
242              {        
243               requiredC omponentTy peName = o pt.Label.U serLocaliz edLabel.La bel;        
244              }        
245            }        
246         //Th e name or  display na me of the  compoent i s retrieve d in diffe rent ways  depending  on the com ponent typ e        
247            d ependentCo mponentNam e = getCom ponentName (dependenc y.Dependen tComponent Type.Value , (Guid)de pendency.D ependentCo mponentObj ectId);        
248            r equiredCom ponentName  = getComp onentName( dependency .RequiredC omponentTy pe.Value,  (Guid)depe ndency.Req uiredCompo nentObject Id);        
249          
250         // R etrieve th e friendly  name for  the depend ent soluti on.        
251            S olution de pendentSol ution = (S olution)_s erviceProx y.Retrieve        
252              (        
253               Solution. EntityLogi calName,        
254               (Guid)dep endency.De pendentCom ponentBase SolutionId ,        
255               new Colum nSet("frie ndlyname")        
256              );        
257            d ependentCo mponentSol utionName  = dependen tSolution. FriendlyNa me;        
258                    
259         // R etrieve th e friendly  name for  the requir ed solutio n.        
260            S olution re quiredSolu tion = (So lution)_se rviceProxy .Retrieve        
261               (        
262                Solution .EntityLog icalName,        
263                (Guid)de pendency.R equiredCom ponentBase SolutionId ,        
264                new Colu mnSet("fri endlyname" )        
265               );        
266            r equiredCom ponentSolu tionName =  requiredS olution.Fr iendlyName ;        
267          
268         //Di splay the  message        
269              Console.Wr iteLine("T he {0} {1}  in the {2 } depends  on the {3}  {4} in th e {5} solu tion.",        
270              dependentC omponentNa me,        
271              dependentC omponentTy peName,        
272              dependentC omponentSo lutionName ,        
273              requiredCo mponentNam e,        
274              requiredCo mponentTyp eName,        
275              requiredCo mponentSol utionName) ;        
276           }        
277        //</s nippetGetS olutionDep endencies7 >        
278          
279        // Th e name or  display na me of the  component  depends on  the type  of compone nt.        
280           pu blic Strin g getCompo nentName(i nt Compone ntType, Gu id Compone ntId)        
281           {        
282            S tring name  = "";        
283          
284            s witch (Com ponentType )        
285            {        
286               // A sepa rate metho d is requi red for ea ch type of  component        
287              case (int) componentt ype.Attrib ute:        
288               name = ge tAttribute Informatio n(Componen tId);        
289               break;        
290              case (int) componentt ype.Option Set:        
291               name = ge tGlobalOpt ionSetName (Component Id);        
292               break;        
293              default:        
294               name = "n ot impleme nted";        
295               break;        
296            }        
297          
298            r eturn name ;        
299                   
300           }        
301          
302        // Re trieve the  display n ame and pa rent entit y informat ion about  an attribu te solutio n componen t.        
303           pu blic strin g getAttri buteInform ation(Guid  id)        
304           {        
305            S tring attr ibuteInfor mation = " ";        
306            R etrieveAtt ributeRequ est req =  new Retrie veAttribut eRequest        
307            {        
308              MetadataId  = id        
309            } ;        
310            R etrieveAtt ributeResp onse resp  = (Retriev eAttribute Response)_ servicePro xy.Execute (req);        
311          
312            A ttributeMe tadata att met = resp .Attribute Metadata;        
313          
314            a ttributeIn formation  = attmet.E ntityLogic alName + "  : " + att met.Displa yName.User LocalizedL abel.Label ;        
315          
316          
317            r eturn attr ibuteInfor mation;        
318           }        
319        //Ret rieve the  name of a  global Opt ion set        
320           pu blic Strin g getGloba lOptionSet Name(Guid  id)        
321           {        
322            S tring name  = "";        
323              RetrieveOp tionSetReq uest req =  new Retri eveOptionS etRequest        
324              {        
325               MetadataI d = id        
326              };        
327              RetrieveOp tionSetRes ponse resp  = (Retrie veOptionSe tResponse) _servicePr oxy.Execut e(req);        
328              OptionSetM etadataBas e os = (Op tionSetMet adataBase) resp.Optio nSetMetada ta;        
329              name = os. DisplayNam e.UserLoca lizedLabel .Label;               
330            r eturn name ;        
331           }        
332          
333           // / <summary >        
334           // / This met hod create s any enti ty records  that this  sample re quires.        
335           // / Create a  publisher        
336           // / Create a  new solut ion, "Prim ary"        
337           // / Create a  Global Op tion Set i n solution  "Primary"        
338           // / Export t he "Primar y" solutio n, setting  it to Pro tected        
339           // / Delete t he option  set and so lution        
340           // / Import t he "Primar y" solutio n, creatin g a manage d solution  in CRM.        
341           // / Create a  new solut ion, "Seco ndary"        
342           // / Create a n attribut e in "Seco ndary" tha t referenc es the Glo bal Option  Set        
343           // / </summar y>        
344           pu blic void  CreateRequ iredRecord s()        
345           {        
346                //Create  the publi sher that  will "own"  the two s olutions        
347            / /<snippetG etSolution Dependenci es6>        
348                Publishe r publishe r = new Pu blisher        
349                {        
350                    Uniq ueName = " examplepub lisher",        
351                    Frie ndlyName =  "An Examp le Publish er",        
352                    Desc ription =  "This is a n example  publisher" ,        
353                    Cust omizationP refix = _p refix        
354                };        
355                _publish erId = _se rviceProxy .Create(pu blisher);        
356            / /</snippet GetSolutio nDependenc ies6>        
357                //Create  the prima ry solutio n - note t hat we are  not creat ing it         
358                //as a m anaged sol ution as t hat can on ly be done  when expo rting the  solution.        
359              //<snippet GetSolutio nDependenc ies2>        
360                Solution  primarySo lution = n ew Solutio n        
361                {        
362                    Vers ion = "1.0 ",        
363                    Frie ndlyName =  "Primary  Solution",        
364                    Publ isherId =  new Entity Reference( Publisher. EntityLogi calName, _ publisherI d),        
365                    Uniq ueName = _ primarySol utionName        
366                };        
367                _primary SolutionId  = _servic eProxy.Cre ate(primar ySolution) ;        
368                //</snip petGetSolu tionDepend encies2>        
369                //Now, c reate the  Global Opt ion Set an d associat e it to th e solution .        
370                //<snipp etGetSolut ionDepende ncies3>        
371                OptionSe tMetadata  optionSetM etadata =  new Option SetMetadat a()        
372                {        
373                    Name  = _global OptionSetN ame,        
374                    Disp layName =  new Label( "Example O ption Set" , _languag eCode),        
375                    IsGl obal = tru e,        
376                    Opti onSetType  = OptionSe tType.Pick list,        
377                    Opti ons =        
378                {        
379                    new  OptionMeta data(new L abel("Opti on 1", _la nguageCode ), 1),        
380                    new  OptionMeta data(new L abel("Opti on 2", _la nguageCode ), 2)        
381                }        
382                };        
383                CreateOp tionSetReq uest creat eOptionSet Request =  new Create OptionSetR equest        
384                {        
385                    Opti onSet = op tionSetMet adata                          
386                };        
387          
388                createOp tionSetReq uest.Solut ionUniqueN ame = _pri marySoluti onName;        
389                _service Proxy.Exec ute(create OptionSetR equest);        
390                //</snip petGetSolu tionDepend encies3>        
391                //Export  the solut ion as man aged so th at we can  later impo rt it.        
392                //<snipp etGetSolut ionDepende ncies4>        
393                ExportSo lutionRequ est export Request =  new Export SolutionRe quest        
394                {        
395                    Mana ged = true ,        
396                    Solu tionName =  _primaryS olutionNam e        
397                };        
398                ExportSo lutionResp onse expor tResponse  =        
399                    (Exp ortSolutio nResponse) _servicePr oxy.Execut e(exportRe quest);        
400                //</snip petGetSolu tionDepend encies4>        
401                // Delet e the opti on set pre vious crea ted, so it  can be im ported und er the        
402                // manag ed solutio n.        
403                //<snipp etGetSolut ionDepende ncies5>        
404                DeleteOp tionSetReq uest delet eOptionSet Request =  new Delete OptionSetR equest        
405                {        
406                    Name  = _global OptionSetN ame        
407                };        
408                _service Proxy.Exec ute(delete OptionSetR equest);        
409                //</snip petGetSolu tionDepend encies5>        
410                // Delet e the prev ious prima ry solutio n, so it c an be impo rted as ma naged.        
411                _service Proxy.Dele te(Solutio n.EntityLo gicalName,  _primaryS olutionId) ;        
412                _primary SolutionId  = Guid.Em pty;        
413          
414                // Re-im port the s olution as  managed.        
415                ImportSo lutionRequ est import Request =  new Import SolutionRe quest        
416                {        
417                    Cust omizationF ile = expo rtResponse .ExportSol utionFile        
418                };        
419                _service Proxy.Exec ute(import Request);        
420          
421                // Retri eve the so lution fro m CRM in o rder to ge t the new  id.        
422                QueryByA ttribute p rimarySolu tionQuery  = new Quer yByAttribu te        
423                {        
424                    Enti tyName = S olution.En tityLogica lName,        
425                    Colu mnSet = ne w ColumnSe t("solutio nid"),        
426                    Attr ibutes = {  "uniquena me" },        
427                    Valu es = { _pr imarySolut ionName }        
428                };        
429                _primary SolutionId  = _servic eProxy.Ret rieveMulti ple(primar ySolutionQ uery).Enti ties        
430                    .Cas t<Solution >().FirstO rDefault() .SolutionI d.GetValue OrDefault( );        
431          
432          
433                // Creat e a second ary soluti on.        
434                Solution  secondary Solution =  new Solut ion        
435                {        
436                    Vers ion = "1.0 ",        
437                    Frie ndlyName =  "Secondar y Solution ",        
438                    Publ isherId =  new Entity Reference( Publisher. EntityLogi calName, _ publisherI d),        
439                    Uniq ueName = " SecondaryS olution"        
440                };        
441                _seconda rySolution Id = _serv iceProxy.C reate(seco ndarySolut ion);        
442          
443                // Creat e a Pickli st attribu te in the  secondary  solution l inked to t he option  set in the        
444                // prima ry - see W orkWithOpt ionSets.cs  for more  on option  sets.        
445                Picklist AttributeM etadata pi cklistMeta data = new  PicklistA ttributeMe tadata        
446                {        
447                    Sche maName = _ picklistNa me,        
448                    Logi calName =  _picklistN ame,        
449                    Disp layName =  new Label( "Example P icklist",  _languageC ode),        
450                                      Required Level = ne w Attribut eRequiredL evelManage dProperty( AttributeR equiredLev el.None),        
451                    Opti onSet = ne w OptionSe tMetadata        
452                    {        
453                         IsGlobal =  true,        
454                         Name = _gl obalOption SetName        
455                    }        
456          
457                };        
458          
459                CreateAt tributeReq uest creat eAttribute Request =  new Create AttributeR equest        
460                {        
461                    Enti tyName = C ontact.Ent ityLogical Name,        
462                    Attr ibute = pi cklistMeta data        
463                };        
464                createAt tributeReq uest["Solu tionUnique Name"] = s econdarySo lution.Uni queName;        
465                _service Proxy.Exec ute(create AttributeR equest);        
466           }        
467          
468           // / <summary >        
469           // / Deletes  any entity  records t hat were c reated for  this samp le.        
470           // / <param n ame="promp t">Indicat es whether  to prompt  the user  to delete  the record s created  in this sa mple.</par am>        
471           // / </summar y>        
472           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
473           {        
474                bool del eteRecords  = true;        
475          
476                if (prom pt)        
477                {        
478                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n)");        
479                    Stri ng answer  = Console. ReadLine() ;        
480          
481                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ));        
482                }        
483          
484                if (dele teRecords)        
485                {        
486          
487                    Dele teAttribut eRequest d eleteAttri buteReques t = new De leteAttrib uteRequest        
488                    {        
489                         EntityLogi calName =  Contact.En tityLogica lName,        
490                         LogicalNam e = _pickl istName        
491                    };        
492                    _ser viceProxy. Execute(de leteAttrib uteRequest );        
493                    _ser viceProxy. Delete(Sol ution.Enti tyLogicalN ame, _prim arySolutio nId);        
494                    _ser viceProxy. Delete(Sol ution.Enti tyLogicalN ame, _seco ndarySolut ionId);        
495                    _ser viceProxy. Delete(Pub lisher.Ent ityLogical Name, _pub lisherId);        
496          
497          
498                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
499                }        
500           }        
501          
502           #e ndregion H ow To Samp le Code        
503          
504           #r egion Main        
505           // / <summary >        
506           // / Standard  Main() me thod used  by most SD K samples.        
507           // / </summar y>        
508           // / <param n ame="args" ></param>        
509           st atic publi c void Mai n(string[]  args)        
510           {        
511                try        
512                {        
513                    // O btain the  target org anization' s Web addr ess and cl ient logon          
514                    // c redentials  from the  user.        
515                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
516                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
517          
518                    GetS olutionDep endencies  app = new  GetSolutio nDependenc ies();        
519                    app. Run(config , true);        
520                }        
521                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
522                {        
523                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
524                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
525                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
526                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
527                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
528                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
529                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
530                }        
531                catch (S ystem.Time outExcepti on ex)        
532                {        
533                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
534                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
535                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
536                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
537                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
538                }        
539                catch (S ystem.Exce ption ex)        
540                {        
541                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
542                    Cons ole.WriteL ine(ex.Mes sage);        
543          
544                    // D isplay the  details o f the inne r exceptio n.        
545                    if ( ex.InnerEx ception !=  null)        
546                    {        
547                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
548          
549                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
550                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
551                         if (fe !=  null)        
552                         {        
553                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
554                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
555                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
556                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
557                             Consol e.WriteLin e("Inner F ault: {0}" ,        
558                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
559                         }        
560                    }        
561                }        
562                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
563                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
564          
565                finally        
566                {        
567                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
568                    Cons ole.ReadLi ne();        
569                }        
570          
571           }        
572           #e ndregion M ain        
573          
574       }        
575   }        
576   //</snippe tGetSoluti onDependen cies>