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

413.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 UserAccess.cs Tue Dec 20 19:51:45 2016 UTC
2 Wed Feb 1 19:56:33 2017 UTC

413.2 Comparison summary

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

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

413.4 Active regular expressions

No regular expressions were active.

413.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
3   //        
4   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
5   //        
6   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
7   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
8   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
9   //        
10   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
11   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
12   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
13   //  PARTIC ULAR PURPO SE.        
14   // ======= ========== ========== ========== ========== ========== ========== ==        
15          
16   //<snippet UserAccess >        
17   using Syst em;        
18   using Syst em.Collect ions.Gener ic;        
19   using Syst em.Service Model;        
20   using Micr osoft.Crm. Sdk.Messag es;        
21   using Micr osoft.Xrm. Sdk;        
22   using Micr osoft.Xrm. Sdk.Client ;        
23   using Micr osoft.Xrm. Sdk.Query;        
24          
25   namespace  Microsoft. Crm.Sdk.Sa mples        
26   {        
27       public  class Use rAccess        
28       {        
29           #r egion Clas s Level Me mbers        
30           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
31           pr ivate Guid  _currentU serId;        
32           pr ivate List <Guid> _sy stemUserId s;        
33           pr ivate Guid  _teamId;        
34           pr ivate Guid  _leadId;        
35           pr ivate Guid  _taskId;        
36           #e ndregion        
37          
38           #r egion How  To Sample  Code        
39           pu blic void  Run(Server Connection .Configura tion serve rConfig,        
40                bool pro mptforDele te)        
41           {        
42                using (_ servicePro xy = new O rganizatio nServicePr oxy(server Config.Org anizationU ri, server Config.Hom eRealmUri, serverConf ig.Credent ials, serv erConfig.D eviceCrede ntials))        
43                {        
44                    // T his statem ent is req uired to e nable earl y bound ty pe support .        
45                    _ser viceProxy. EnableProx yTypes();        
46                    Crea teRequired Records();        
47          
48                    // R etrieve an d display  the access  that the  calling us er has to  the        
49                    // c reated lea d.        
50                    var  leadRefere nce = new  EntityRefe rence(Lead .EntityLog icalName,  _leadId);        
51                    var  currentUse rReference  = new Ent ityReferen ce(        
52                         SystemUser .EntityLog icalName,  _currentUs erId);        
53                    Retr ieveAndDis playPrinci palAccess( leadRefere nce, curre ntUserRefe rence,        
54                         "Current U ser");        
55          
56                    // R etrieve an d display  the access  that the  first user  has to th e        
57                    // c reated lea d.        
58                    var  systemUser 1Ref = new  EntityRef erence(Sys temUser.En tityLogica lName,        
59                         _systemUse rIds[0]);        
60                    Retr ieveAndDis playPrinci palAccess( leadRefere nce, syste mUser1Ref,        
61                         "System Us er 1");        
62          
63                    // G rant the f irst user  read acces s to the c reated lea d.        
64                    var  grantAcces sRequest1  = new Gran tAccessReq uest        
65                    {        
66                         PrincipalA ccess = ne w Principa lAccess        
67                         {        
68                             Access Mask = Acc essRights. ReadAccess ,        
69                             Princi pal = syst emUser1Ref        
70                         },        
71                         Target = l eadReferen ce        
72                    };        
73          
74                    Cons ole.WriteL ine("Grant ing {0} to  {1} ({2})  on the le ad...\r\n" ,        
75                         AccessRigh ts.ReadAcc ess, GetEn tityRefere nceString( systemUser 1Ref), "Sy stem User  1");        
76                    _ser viceProxy. Execute(gr antAccessR equest1);        
77          
78          
79                    // R etrieve an d display  access inf ormation f or the lea d.        
80                    Retr ieveAndDis playPrinci palAccess( leadRefere nce, syste mUser1Ref,        
81                         "System Us er 1");        
82                    Retr ieveAndDis playLeadAc cess(leadR eference);        
83          
84                    //<s nippetUser Access1>        
85                    // G rant the t eam read/w rite acces s to the l ead.        
86                    var  teamRefere nce = new  EntityRefe rence(Team .EntityLog icalName,  _teamId);        
87                    var  grantAcces sRequest =  new Grant AccessRequ est        
88                    {        
89                         PrincipalA ccess = ne w Principa lAccess        
90                         {        
91                             Access Mask = Acc essRights. ReadAccess  | AccessR ights.Writ eAccess,        
92                             Princi pal = team Reference        
93                         },        
94                         Target = l eadReferen ce        
95                    };        
96          
97                    Cons ole.WriteL ine("Grant ing {0} to  {1} ({2})  on the le ad...\r\n" ,        
98                         AccessRigh ts.ReadAcc ess | Acce ssRights.W riteAccess , GetEntit yReference String(tea mReference ), "Team") ;        
99                    _ser viceProxy. Execute(gr antAccessR equest);        
100          
101                    var  systemUser 2Ref = new  EntityRef erence(Sys temUser.En tityLogica lName,        
102                         _systemUse rIds[1]);        
103          
104                    //</ snippetUse rAccess1>        
105                           
106                    // R etrieve an d display  access inf ormation f or the lea d and syst em user 2.        
107                    Retr ieveAndDis playPrinci palAccess( leadRefere nce, syste mUser2Ref,        
108                         "System Us er 2");        
109                    Retr ieveAndDis playLeadAc cess(leadR eference);        
110          
111                    //<s nippetUser Access2>        
112          
113                    // G rant the f irst user  delete acc ess to the  lead.        
114                    var  modifyUser 1AccessReq  = new Mod ifyAccessR equest        
115                    {        
116                         PrincipalA ccess = ne w Principa lAccess        
117                         {        
118                             Access Mask = Acc essRights. DeleteAcce ss,        
119                             Princi pal = syst emUser1Ref        
120                         },        
121                         Target = l eadReferen ce        
122                    };        
123          
124                    Cons ole.WriteL ine("Grant ing delete  access to  {0} on th e lead...\ r\n",        
125                         GetEntityR eferenceSt ring(syste mUser1Ref) );        
126                    _ser viceProxy. Execute(mo difyUser1A ccessReq);        
127                    //</ snippetUse rAccess2>        
128          
129                    // R etrieve an d display  access inf ormation f or the lea d.        
130                    Retr ieveAndDis playLeadAc cess(leadR eference);        
131          
132                    //<s nippetUser Access3>        
133          
134                    // R evoke acce ss to the  lead for t he second  user.        
135                    var  revokeUser 2AccessReq  = new Rev okeAccessR equest        
136                    {        
137                         Revokee =  systemUser 2Ref,        
138                         Target = l eadReferen ce        
139                    };        
140          
141                    Cons ole.WriteL ine("Revok ing access  to the le ad for {0} ...\r\n",        
142                         GetEntityR eferenceSt ring(syste mUser2Ref) );        
143                    _ser viceProxy. Execute(re vokeUser2A ccessReq);        
144                    //</ snippetUse rAccess3>        
145          
146                    // R etrieve an d display  access inf ormation f or the lea d.        
147                    Retr ieveAndDis playPrinci palAccess( leadRefere nce, syste mUser2Ref,        
148                         "System Us er 2");        
149          
150                    Retr ieveAndDis playLeadAc cess(leadR eference);        
151          
152                    Dele teRequired Records(pr omptforDel ete);        
153                }        
154           }        
155          
156           pr ivate void  RetrieveA ndDisplayP rincipalAc cess(Entit yReference  leadRefer ence,        
157                EntityRe ference pr incipal, S tring addi tionalIden tifier)        
158           {        
159                //<snipp etUserAcce ss4>        
160                var prin cipalAcces sReq = new  RetrieveP rincipalAc cessReques t        
161                {        
162                    Prin cipal = pr incipal,        
163                    Targ et = leadR eference        
164                };        
165                var prin cipalAcces sRes = (Re trievePrin cipalAcces sResponse)        
166                    _ser viceProxy. Execute(pr incipalAcc essReq);        
167                Console. WriteLine( "Access ri ghts of {0 } ({1}) on  the lead:  {2}\r\n",        
168                    GetE ntityRefer enceString (principal ),        
169                    addi tionalIden tifier,        
170                    prin cipalAcces sRes.Acces sRights);        
171                //</snip petUserAcc ess4>        
172           }        
173          
174           pr ivate void  RetrieveA ndDisplayL eadAccess( EntityRefe rence lead Reference)        
175           {        
176                //<snipp etUserAcce ss5>        
177                var acce ssRequest  = new Retr ieveShared Principals AndAccessR equest        
178                {        
179                    Targ et = leadR eference        
180                };        
181                        
182                // The R etrieveSha redPrincip alsAndAcce ssResponse  returns a n entity r eference        
183                // that  has a Logi calName of  "user" wh en returni ng access  informatio n for a        
184                // "team ."        
185                var acce ssResponse  = (Retrie veSharedPr incipalsAn dAccessRes ponse)        
186                    _ser viceProxy. Execute(ac cessReques t);        
187                Console. WriteLine( "The follo wing have  the specif ied grante d access t o the lead .");        
188                foreach  (var princ ipalAccess  in access Response.P rincipalAc cesses)        
189                {        
190                    Cons ole.WriteL ine("\t{0} :\r\n\t\t{ 1}",        
191                         GetEntityR eferenceSt ring(princ ipalAccess .Principal ),        
192                         principalA ccess.Acce ssMask);        
193                }        
194                Console. WriteLine( );        
195                //</snip petUserAcc ess5>        
196          
197           }        
198          
199           pr ivate Stri ng GetEnti tyReferenc eString(En tityRefere nce entity Reference)        
200           {        
201                return S tring.Form at("{0} wi th GUID {1 }", entity Reference. LogicalNam e,        
202                    enti tyReferenc e.Id);        
203           }        
204          
205           // / <summary >        
206           // / Creates  any entity  records t hat this s ample requ ires.        
207           // / </summar y>        
208           pu blic void  CreateRequ iredRecord s()        
209           {        
210                // Creat e a unique  identifie r for this  sample fo r preventi ng name co nflicts.        
211                var samp leIdentifi er = Guid. NewGuid();        
212          
213                // Retri eve/create  the syste m users to  use for t he sample.        
214                var ldap Path = Str ing.Empty;        
215                _systemU serIds = S ystemUserP rovider.Re trieveDele gates(        
216                    _ser viceProxy,  ref ldapP ath);        
217          
218                // Retri eve the ro ot busines s unit to  use for cr eating the  team for  the        
219                // sampl e.        
220                var busi nessUnitQu ery = new  QueryExpre ssion        
221                {        
222                    Enti tyName = B usinessUni t.EntityLo gicalName,        
223                    Colu mnSet = ne w ColumnSe t("busines sunitid"),        
224                    Crit eria = new  FilterExp ression()        
225                };        
226          
227                business UnitQuery. Criteria.A ddConditio n("parentb usinessuni tid",        
228                    Cond itionOpera tor.Null);        
229                var busi nessUnitRe sult = _se rviceProxy .RetrieveM ultiple(bu sinessUnit Query);        
230                var busi nessUnit =  businessU nitResult. Entities[0 ].ToEntity <BusinessU nit>();        
231          
232                // Get t he GUID of  the curre nt user.        
233                var who  = new WhoA mIRequest( );        
234                var whoR esponse =  (WhoAmIRes ponse)_ser viceProxy. Execute(wh o);        
235                _current UserId = w hoResponse .UserId;        
236          
237                // Creat e a team f or use in  the sample .        
238                var team  = new Tea m        
239                {        
240                    Admi nistratorI d = new En tityRefere nce(        
241                         "systemuse r", _curre ntUserId),        
242                    Name  = String. Format("Us er Access  Sample Tea m {0}", sa mpleIdenti fier),        
243                    Busi nessUnitId  = busines sUnit.ToEn tityRefere nce()        
244                };        
245                _teamId  = _service Proxy.Crea te(team);        
246          
247                // Add t he second  user to th e newly cr eated team .        
248                var addT oTeamReque st = new A ddMembersT eamRequest        
249                {        
250                    Team Id = _team Id,        
251                    Memb erIds = ne w[] { _sys temUserIds [1] }        
252                };        
253                _service Proxy.Exec ute(addToT eamRequest );        
254          
255                // Creat e a lead f or use in  the sample .        
256                var lead  = new Lea d        
257                {        
258                    Comp anyName =  "User Acce ss Sample  Company",        
259                    Firs tName = "S ample",        
260                    Last Name = "Le ad",        
261                    Subj ect = "Use r Access S ample Lead ",        
262                };        
263                _leadId  = _service Proxy.Crea te(lead);        
264          
265                // Creat e a task t o associat e to the l ead.        
266                var lead Reference  = new Enti tyReferenc e(Lead.Ent ityLogical Name, _lea dId);        
267                var task  = new Tas k        
268                {        
269                    Subj ect = "Use r Access S ample Task ",        
270                    Rega rdingObjec tId = lead Reference        
271                };        
272                _taskId  = _service Proxy.Crea te(task);        
273          
274                // Creat e a letter  to associ ate to the  lead.        
275                var lett er = new L etter        
276                {        
277                    Subj ect = "Use r Access S ample Lett er",        
278                    Rega rdingObjec tId = lead Reference        
279                };        
280                _service Proxy.Crea te(letter) ;        
281           }        
282          
283           pr ivate void  DeleteReq uiredRecor ds(bool pr ompt)        
284           {        
285                bool toB eDeleted =  true;        
286          
287                if (prom pt)        
288                {        
289                    // A sk the use r if the c reated ent ities shou ld be dele ted.        
290                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
291                    Stri ng answer  = Console. ReadLine() ;        
292                    if ( answer.Sta rtsWith("y ") ||        
293                         answer.Sta rtsWith("Y ") ||        
294                         answer ==  String.Emp ty)        
295                    {        
296                         toBeDelete d = true;        
297                    }        
298                    else        
299                    {        
300                         toBeDelete d = false;        
301                    }        
302                }        
303          
304                if (toBe Deleted)        
305                {        
306                    // D elete reco rds create d in this  sample.        
307                    _ser viceProxy. Delete(Tea m.EntityLo gicalName,  _teamId);        
308                    // D eleting th e lead wil l delete i ts associa ted activi ties.        
309                    _ser viceProxy. Delete(Lea d.EntityLo gicalName,  _leadId);        
310          
311                    Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. ");        
312                }        
313           }        
314           #e ndregion H ow To Samp le Code        
315          
316           #r egion Main  method        
317          
318           // / <summary >        
319           // / Standard  Main() me thod used  by most SD K samples.        
320           // / </summar y>        
321           // / <param n ame="args" ></param>        
322           st atic publi c void Mai n(string[]  args)        
323           {        
324                try        
325                {        
326                    // O btain the  target org anization' s web addr ess and cl ient logon          
327                    // c redentials  from the  user.        
328                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
329                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
330          
331                    var  app = new  UserAccess ();        
332                    app. Run(config , true);        
333                }        
334                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
335                {        
336                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
337                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
338                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
339                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
340                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
341                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
342                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
343                }        
344                catch (S ystem.Time outExcepti on ex)        
345                {        
346                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
347                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
348                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
349                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
350                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
351                }        
352                catch (S ystem.Exce ption ex)        
353                {        
354                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
355                    Cons ole.WriteL ine(ex.Mes sage);        
356          
357                    // D isplay the  details o f the inne r exceptio n.        
358                    if ( ex.InnerEx ception !=  null)        
359                    {        
360                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
361          
362                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
363                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
364                         if (fe !=  null)        
365                         {        
366                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
367                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
368                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
369                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
370                             Consol e.WriteLin e("Inner F ault: {0}" ,        
371                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
372                         }        
373                    }        
374                }        
375                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
376                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
377          
378                finally        
379                {        
380                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
381                    Cons ole.ReadLi ne();        
382                }        
383           }        
384           #e ndregion M ain method        
385       }        
386   }        
387   //</snippe tUserAcces s>