399. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:56:33 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

399.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\GeneralProgramming\EarlyBound AssignSecurityRoleToTeam.cs Tue Dec 20 19:51:45 2016 UTC
2 Wed Feb 1 19:56:33 2017 UTC

399.2 Comparison summary

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

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

399.4 Active regular expressions

No regular expressions were active.

399.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 AssignSecu rityRoleTo Team>        
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.Query;        
29   using Micr osoft.Xrm. Sdk.Discov ery;        
30   using Micr osoft.Xrm. Sdk.Client ;        
31          
32   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
33   // found i n the SDK\ bin folder .        
34   using Micr osoft.Crm. Sdk.Messag es;        
35          
36          
37          
38   namespace  Microsoft. Crm.Sdk.Sa mples        
39   {        
40          
41       /// <s ummary>        
42       /// De monstrates  how to as sign a sec urity role  to a team .        
43       /// </ summary>        
44       public  class Ass ignSecurit yRoleToTea m        
45       {        
46           #r egion Clas s Level Me mbers        
47          
48          
49           // / <summary >        
50           // / Stores t he organiz ation serv ice proxy.        
51           // / </summar y>        
52           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
53           pr ivate IOrg anizationS ervice _se rvice;        
54          
55           //  Define th e IDs need ed for thi s sample.        
56           pr ivate Guid  _teamId;        
57           pr ivate Guid  _roleId;        
58           pu blic const  String _r oleName =  "An Exampl e Role";        
59          
60           #e ndregion C lass Level  Members        
61          
62           #r egion How  To Sample  Code        
63           // / <summary >        
64           // / Retrieve  a role fr om CRM.        
65           // / Assign t hat role t o a team.        
66           // / <param n ame="organ izationFri endlyName" >The frien dly name o        
67           // / the targ et organiz ation.</pa ram>        
68           // / <param n ame="disco veryServer ">The name  of the di scovery se rver.</par am>        
69           // / <param n ame="promp tForDelete ">Indicate s whether  to prompt  the user         
70           // / to delet e the reco rds create d in this  sample.</p aram>        
71           // / </summar y>        
72           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt ForDelete)        
73           {        
74                try        
75                {        
76                    // C onnect to  the Organi zation ser vice.         
77                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
78                    usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,        
79                                                                              s erverConfi g.Credenti als, serve rConfig.De viceCreden tials))        
80                    {        
81                         // This st atement is  required  to enable  early-boun d type sup port.        
82                         _servicePr oxy.Enable ProxyTypes ();        
83          
84                         _service =  (IOrganiz ationServi ce)_servic eProxy;        
85          
86                         // Call th e method t o create a ny data th at this sa mple requi res.        
87                         CreateRequ iredRecord s();        
88          
89                         //<snippet AssignSecu rityRoleTo Team1>        
90          
91                         // Retriev e a role f rom CRM.        
92                         QueryExpre ssion quer y = new Qu eryExpress ion        
93                         {        
94                             Entity Name = Rol e.EntityLo gicalName,        
95                             Column Set = new  ColumnSet( "roleid"),        
96                             Criter ia = new F ilterExpre ssion        
97                             {        
98                                 Co nditions =        
99                             {        
100                                 //  You would  replace t he conditi on below w ith an act ual role        
101                                 //  name, or  skip this  query if y ou had a r ole id.        
102                                 ne w Conditio nExpressio n        
103                                 {        
104                                      Attribut eName = "n ame",        
105                                      Operator  = Conditi onOperator .Equal,        
106                                      Values =  {_roleNam e}        
107                                 }        
108                             }        
109                             }        
110                         };        
111          
112                         Role role  = _service .RetrieveM ultiple(qu ery).Entit ies.        
113                             Cast<R ole>().Fir st();        
114          
115          
116                         // Add the  role to t he team.        
117                         _service.A ssociate(        
118                                Tea m.EntityLo gicalName,        
119                                _te amId,        
120                                new  Relations hip("teamr oles_assoc iation"),        
121                                new  EntityRef erenceColl ection() {  new Entit yReference (Role.Enti tyLogicalN ame, _role Id) });        
122          
123                         Console.Wr iteLine("A ssigned ro le to team ");        
124                         //</snippe tAssignSec urityRoleT oTeam1>        
125          
126                         DeleteRequ iredRecord s(promptFo rDelete);        
127                    }        
128                }        
129          
130                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
131                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
132                {        
133                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
134                    thro w;        
135                }        
136           }        
137          
138           // / <summary >        
139           // / This met hod create s any enti ty records  that this  sample re quires.        
140           // / Creates  a team and  a role.        
141           // / </summar y>        
142           pu blic void  CreateRequ iredRecord s()        
143           {        
144          
145                // Retri eve the de fault busi ness unit  needed to  create the  team and  role.        
146                QueryExp ression qu ery = new  QueryExpre ssion        
147                {        
148                    Enti tyName = B usinessUni t.EntityLo gicalName,        
149                    Colu mnSet = ne w ColumnSe t("busines sunitid"),        
150                    Crit eria =        
151                    {        
152                         Conditions  =        
153                         {        
154                             new Co nditionExp ression("p arentbusin essunitid"        
155                                 Co nditionOpe rator.Null )        
156                         }        
157                    }        
158                };        
159          
160                Business Unit defau ltBusiness Unit = _se rvice.Retr ieveMultip le(query)        
161                    .Ent ities.Cast <BusinessU nit>().Fir stOrDefaul t();        
162          
163                // Insta ntiate a t eam entity  record an d set its  property v alues.        
164                // See t he Entity  Metadata t opic in th e SDK docu mentation           
165                // to de termine wh ich attrib utes must  be set for  each enti ty.        
166                Team set upTeam = n ew Team        
167                {        
168                    Name  = "An Exa mple Team" ,        
169                    Busi nessUnitId  = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame,        
170                         defaultBus inessUnit. Id)        
171                };        
172          
173                // Creat e a team r ecord.        
174                _teamId  = _service .Create(se tupTeam);        
175                Console. WriteLine( "Created t eam '{0}'" , setupTea m.Name);        
176          
177                // Insta ntiate a r ole entity  record an d set its  property v alues.        
178                // See t he Entity  Metadata t opic in th e SDK docu mentation           
179                // to de termine wh ich attrib utes must  be set for  each enti ty.        
180                Role set upRole = n ew Role        
181                {        
182                    Name  = _roleNa me,        
183                    Busi nessUnitId  = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame,        
184                         defaultBus inessUnit. Id)        
185                };        
186          
187                // Creat e the role  record.         
188                _roleId  = _service .Create(se tupRole);        
189                Console. WriteLine( "Created r ole '{0}'" , setupRol e.Name);        
190          
191                // Defin e an array  listing t he privile ges that w e want to  add to the  role        
192                String[]  privilege sToAdd = n ew string[ ] { "prvRe adContact"        
193                    "prv CreateCont act", "prv ReadAccoun t", "prvCr eateAccoun t" };        
194          
195                // Query  for the p rivileges  we want to  add to th e role        
196                QueryExp ression qu eryPrivile ges = new  QueryExpre ssion        
197                {        
198                    Enti tyName = P rivilege.E ntityLogic alName,        
199                    Colu mnSet = ne w ColumnSe t("privile geid", "na me"),        
200                    Crit eria = new  FilterExp ression()        
201                };        
202                queryPri vileges.Cr iteria.Add Condition( "name", Co nditionOpe rator.In,        
203                    priv ilegesToAd d);        
204          
205                DataColl ection<Ent ity> retur nedPrivile ges = _ser vice.Retri eveMultipl e(        
206                    quer yPrivilege s).Entitie s;        
207                Console. WriteLine( "Retrieved  privilege s to add t o role");        
208          
209                // Defin e a list t o hold the  RolePrivi leges we'l l need to  add        
210                List<Rol ePrivilege > rolePriv ileges = n ew List<Ro lePrivileg e>();        
211          
212                foreach  (Privilege  privilege  in return edPrivileg es)        
213                {        
214                    Role Privilege  rolePrivil ege = new  RolePrivil ege(        
215                         (int)Privi legeDepth. Local, pri vilege.Pri vilegeId.V alue);        
216                    role Privileges .Add(roleP rivilege);        
217                }        
218          
219                // Add t he retriev ed privile ges to the  example r ole.        
220                AddPrivi legesRoleR equest add Privileges Request =  new AddPri vilegesRol eRequest        
221                {        
222                    Role Id = _role Id,        
223                    Priv ileges = r olePrivile ges.ToArra y()        
224                };        
225                _service .Execute(a ddPrivileg esRequest) ;        
226                Console. WriteLine( "Added pri vileges to  role");        
227           }        
228          
229           // / <summary >        
230           // / Deletes  any entity  records t hat were c reated for  this samp le.        
231           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
232           // / to delet e the reco rds create d in this  sample.</p aram>        
233           // / </summar y>        
234           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
235           {        
236                bool del eteRecords  = true;        
237          
238                if (prom pt)        
239                {        
240                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n)");        
241                    Stri ng answer  = Console. ReadLine() ;        
242          
243                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ));        
244                }        
245          
246                if (dele teRecords)        
247                {        
248                    _ser vice.Delet e(Team.Ent ityLogical Name, _tea mId);        
249                    _ser vice.Delet e(Role.Ent ityLogical Name, _rol eId);        
250          
251                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
252                }        
253           }        
254          
255           #e ndregion H ow To Samp le Code        
256          
257           #r egion Main        
258           // / <summary >        
259           // / Main. Ru ns the sam ple and pr ovides err or output.        
260           // / <param n ame="args" >Array of  arguments  to Main me thod.</par am>        
261           // / </summar y>        
262           st atic publi c void Mai n(string[]  args)        
263           {        
264          
265                try        
266                {        
267                    // O btain the  target org anization' s Web addr ess and cl ient logon          
268                    // c redentials  from the  user.        
269                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
270                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
271          
272                    Assi gnSecurity RoleToTeam  app = new  AssignSec urityRoleT oTeam();        
273                    app. Run(config , true);        
274          
275                }        
276                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
277                {        
278                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
279                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
280                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
281                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
282                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
283                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
284                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
285                }        
286                catch (S ystem.Time outExcepti on ex)        
287                {        
288                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
289                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
290                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
291                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
292                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
293                }        
294                catch (S ystem.Exce ption ex)        
295                {        
296                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
297                    Cons ole.WriteL ine(ex.Mes sage);        
298          
299                    // D isplay the  details o f the inne r exceptio n.        
300                    if ( ex.InnerEx ception !=  null)        
301                    {        
302                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
303          
304                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e =        
305                             ex.Inn erExceptio n        
306                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
307                         if (fe !=  null)        
308                         {        
309                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
310                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
311                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
312                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
313                             Consol e.WriteLin e("Inner F ault: {0}" ,        
314                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
315                         }        
316                    }        
317                }        
318                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
319                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
320          
321                finally        
322                {        
323          
324                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
325                    Cons ole.ReadLi ne();        
326                }        
327          
328           }        
329           #e ndregion M ain        
330          
331       }        
332   }        
333   //</snippe tAssignSec urityRoleT oTeam>