381. Araxis Merge File Comparison Report

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

381.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\FieldSecurity RetrieveUserSharedAttributePermissions.cs Tue Dec 20 19:51:44 2016 UTC
2 Wed Feb 1 19:56:32 2017 UTC

381.2 Comparison summary

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

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

381.4 Active regular expressions

No regular expressions were active.

381.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 RetrieveUs erSharedAt tributePer missions>        
17   using Syst em;        
18   using Syst em.Service Model;        
19   using Syst em.Linq;        
20          
21   // This na mespace is  in the Mi crosoft.Cr m.Sdk.Prox y.dll asse mbly        
22   // located  in the SD K\bin fold er.        
23   using Micr osoft.Crm. Sdk.Messag es;        
24          
25   // These n amespaces  are in the  Microsoft .Xrm.Sdk.d ll assembl y        
26   // located  in the SD K\bin fold er of the  SDK downlo ad.        
27   using Micr osoft.Xrm. Sdk;        
28   using Micr osoft.Xrm. Sdk.Client ;        
29   using Micr osoft.Xrm. Sdk.Messag es;        
30   using Micr osoft.Xrm. Sdk.Query;        
31   using Micr osoft.Xrm. Sdk.Metada ta;        
32          
33   namespace  Microsoft. Crm.Sdk.Sa mples        
34   {        
35       /// <s ummary>        
36       /// Cu rrently, u sers must  have prvRe adPOAA per missions t o access a ny         
37       /// Pr incipleObj ectAttribu teAccess ( POAA) reco rds. Howev er, in an  upcoming        
38       /// re lease, use rs who do  not have p rvReadPOAA  permissio ns will be  able         
39       /// to  access PO AA records  by using  the Retrie veMultiple  method. U sers         
40       /// wi ll be able  to retrie ve attribu te permiss ions for a ttributes  shared         
41       /// di rectly or  indirectly  (through  teams) wit h themselv es.          
42       /// </ summary>        
43       /// <r emarks>        
44       /// At  run time,  you will  be given t he option  to delete  all the        
45       /// da tabase rec ords creat ed by this  program.        
46       /// </ remarks>        
47       public  class Ret rieveUserS haredAttri butePermis sions        
48       {        
49           #r egion Clas s Level Me mbers        
50          
51           pr ivate Guid  _accountR ecordId;        
52           pr ivate Guid  _secretPh oneId;         
53           pr ivate Guid  _secretHo meId;         
54           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
55          
56           #e ndregion C lass Level  Members        
57          
58           #r egion How  To Sample  Code        
59           // / <summary >        
60           // / This met hod first  checks if  the logged  on user h as prvRead POAA permi ssions.         
61           // / Afterwar ds,  the m ethod crea tes the se cure custo m fields r equired fo r this sam ple,        
62           // / an accou nt record  for testin g purposes , and POAA  records f or the use r        
63           // / and thos e custom f ields.        
64           // / Finally,  the metho d retrieve s the User  Shared At tribute pe rmissions  for that u ser.        
65           // / </summar y>        
66           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
67           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
68           // / created  entities.< /param>        
69           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
70           {        
71                try        
72                {        
73                    //<s nippetRetr ieveUserSh aredAttrib utePermiss ions1>        
74                    // C onnect to  the Organi zation ser vice.         
75                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
76                    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 ))        
77                    {        
78                         // This st atement is  required  to enable  early boun d type sup port.        
79                         _servicePr oxy.Enable ProxyTypes ();        
80          
81                         CreateRequ iredRecord s();        
82          
83                         //<snippet RetrieveUs erSharedAt tributePer missions2>        
84          
85                         #region Ch eck if thi s user has  prvReadPO AA        
86                         // Get the  GUID of t he current  user.        
87                         WhoAmIRequ est whoAmI  = new Who AmIRequest ();        
88                         Guid userL oggedId =         
89                             ((WhoA mIResponse )_serviceP roxy.Execu te(whoAmI) ).UserId;        
90                         Console.Wr iteLine("U ser logged : " + user LoggedId);        
91          
92                         // Check i f this use r has prvR eadPOAA.        
93                         RetrieveUs erPrivileg esRequest  userPrivil egesReques t =         
94                             new Re trieveUser Privileges Request();        
95                         userPrivil egesReques t.UserId =  userLogge dId;        
96                         RetrieveUs erPrivileg esResponse  userPrivi legesRespo nse =        
97                             (Retri eveUserPri vilegesRes ponse)_ser viceProxy. Execute(us erPrivileg esRequest) ;        
98          
99                         // Fixed t he GUID fo r prvReadP OAA.        
100                         Guid prvRe adPOAA = n ew Guid("{ 68564CD5-2 B2E-11DF-8 0A6-001372 99E1C2}");        
101          
102                         if (userPr ivilegesRe sponse.Rol ePrivilege s.Any(r =>  r.Privile geId.Equal s(prvReadP OAA)))        
103                         {        
104                             Consol e.WriteLin e("This us er DOES ha ve prvRead POAA");        
105                         }        
106                         else        
107                         {        
108                             Consol e.WriteLin e("This us er DOESN'T  have prvR eadPOAA");        
109                         }        
110                         Console.Wr iteLine();        
111                         #endregion  Check if  this user  has prvRea dPOAA        
112                         //</snippe tRetrieveU serSharedA ttributePe rmissions2 >        
113                         #region Cr eate an ac count reco rd        
114          
115                         // Create  an account  record        
116                         Account ac countRecor d = new Ac count();        
117                         accountRec ord.Name =  "Ane";        
118                         accountRec ord["secre t_phone"]  = "123456" ;        
119                         _accountRe cordId = _ servicePro xy.Create( accountRec ord);        
120                         Console.Wr iteLine("A ccount rec ord create d.");        
121          
122                         #endregion  Create an  account r ecord        
123          
124                         #region Cr eate POAA  entity for  field #1        
125          
126                         // Create  POAA entit y for fiel d #1        
127                         PrincipalO bjectAttri buteAccess  poaa = ne w Principa lObjectAtt ributeAcce ss        
128                         {        
129                             Attrib uteId = _s ecretHomeI d,        
130                             Object Id = new E ntityRefer ence        
131                                 (A ccount.Ent ityLogical Name, _acc ountRecord Id),        
132                             Princi palId = ne w EntityRe ference        
133                                 (S ystemUser. EntityLogi calName, u serLoggedI d),        
134                             ReadAc cess = tru e,        
135                             Update Access = t rue        
136                         };        
137          
138                         _servicePr oxy.Create (poaa);        
139                         Console.Wr iteLine("P OAA record  for custo m field Se cret_Home  created.") ;        
140          
141                         #endregion  Create PO AA entity  for field  #1        
142          
143                         #region Cr eate POAA  entity for  field #2        
144          
145                         // Create  POAA entit y for fiel d #2        
146                         poaa = new  Principal ObjectAttr ibuteAcces s        
147                         {        
148                             Attrib uteId = _s ecretPhone Id,        
149                             Object Id = new E ntityRefer ence        
150                                 (A ccount.Ent ityLogical Name, _acc ountRecord Id),         
151                             Princi palId = ne w EntityRe ference        
152                                 (S ystemUser. EntityLogi calName, u serLoggedI d),        
153                             ReadAc cess = tru e,        
154                             Update Access = t rue        
155                         };        
156          
157                         _servicePr oxy.Create (poaa);        
158                         Console.Wr iteLine("P OAA record  for custo m field Se cret_Phone  created." );        
159          
160                         #endregion  Create PO AA entity  for field  #2        
161          
162                         #region Re trieve Use r Shared A ttribute P ermissions        
163                         // Create  the query  for retrie ve User Sh ared Attri bute permi ssions.        
164                         QueryExpre ssion quer yPOAA =        
165                             new Qu eryExpress ion("princ ipalobject attributea ccess");        
166                         queryPOAA. ColumnSet  = new Colu mnSet        
167                             (new s tring[] {  "attribute id", "read access", " updateacce ss", "prin cipalid" } );        
168                         queryPOAA. Criteria.F ilterOpera tor = Logi calOperato r.And;        
169                         queryPOAA. Criteria.C onditions. Add        
170                             (new C onditionEx pression(" objectid",  Condition Operator.E qual, _acc ountRecord Id));        
171                         queryPOAA. Criteria.C onditions. Add        
172                             (new C onditionEx pression(" principali d", Condit ionOperato r.EqualUse rId));        
173          
174                         Console.Wr iteLine();        
175                         Console.Wr iteLine("P OAA for us er: " + us erLoggedId .ToString( ));        
176                         Console.Wr iteLine();        
177          
178                         try        
179                         {        
180                             // Exe cute the q uery.        
181                             Entity Collection  responseP OAA = _ser viceProxy. RetrieveMu ltiple(que ryPOAA);        
182          
183                             foreac h (var ent ity in res ponsePOAA. Entities)        
184                             {        
185                                 Co nsole.Writ eLine("  p rincipalid : " + ((En tityRefere nce)entity ["principa lid"]).Id) ;        
186                                 Co nsole.Writ eLine("  a ttributeid : " + enti ty["attrib uteid"].To String());        
187                                 Co nsole.Writ eLine("  r eadaccess:  " + entit y["readacc ess"].ToSt ring());        
188                                 Co nsole.Writ eLine("  u pdateacces s: " + ent ity["updat eaccess"]. ToString() );        
189                                 Co nsole.Writ eLine();        
190                             }        
191                         }        
192                         catch (Exc eption exc )        
193                         {        
194                             Consol e.WriteLin e("Error:  " + exc.Me ssage);        
195                         }        
196          
197                         #endregion  Retrieve  User Share d Attribut e Permissi ons        
198          
199                         DeleteRequ iredRecord s(promptfo rDelete);        
200                               
201                    }        
202                   //</s nippetRetr ieveUserSh aredAttrib utePermiss ions1>        
203          
204                }        
205          
206                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
207                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
208                {        
209                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
210                    thro w;        
211                }        
212           }        
213          
214           // / <summary >        
215           // / Creates  any entity  records t hat this s ample requ ires.        
216           // / </summar y>        
217           pu blic void  CreateRequ iredRecord s()        
218           {        
219                #region  Create cus tom fields  in accoun t entity        
220                        
221                // Creat e secure c ustom fiel d #1        
222                CreateAt tributeReq uest attrR eq = new C reateAttri buteReques t()        
223                {        
224                    Attr ibute = ne w StringAt tributeMet adata()        
225                    {        
226                         LogicalNam e = "secre t_home",        
227                         DisplayNam e = new La bel("Secre tHome", 10 33),        
228                         SchemaName  = "Secret _Home",        
229                         MaxLength  = 500,        
230                         RequiredLe vel = new  AttributeR equiredLev elManagedP roperty(        
231                             Attrib uteRequire dLevel.Rec ommended),        
232                         IsSecured  = true        
233                    },        
234                    Enti tyName = A ccount.Ent ityLogical Name        
235                };        
236                CreateAt tributeRes ponse attr ibuteRespo nse =        
237                    (Cre ateAttribu teResponse )_serviceP roxy.Execu te(attrReq );        
238                _secretH omeId = at tributeRes ponse.Attr ibuteId;        
239                Console. WriteLine( "Secret_Ho me custom  field crea ted.");        
240          
241                // Creat e secure c ustom fiel d #2        
242                attrReq  = new Crea teAttribut eRequest()        
243                {        
244                    Attr ibute = ne w StringAt tributeMet adata()        
245                    {        
246                         LogicalNam e = "secre t_phone",        
247                         DisplayNam e = new La bel("Secre tPhone", 1 033),        
248                         SchemaName  = "Secret _Phone",        
249                         MaxLength  = 500,        
250                         RequiredLe vel = new  AttributeR equiredLev elManagedP roperty(        
251                             Attrib uteRequire dLevel.Rec ommended),        
252                         IsSecured  = true        
253                    },        
254                    Enti tyName = A ccount.Ent ityLogical Name        
255                };        
256                attribut eResponse  = (CreateA ttributeRe sponse)_se rviceProxy .Execute(a ttrReq);        
257                _secretP honeId = a ttributeRe sponse.Att ributeId;        
258                Console. WriteLine( "Secret_Ph one custom  field cre ated.");        
259          
260                #endregi on Create  custom fie lds in acc ount entit y        
261                        
262                Console. WriteLine( );        
263           }        
264          
265           // / <summary >        
266           // / Deletes  any entity  records t hat were c reated for  this samp le.        
267           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
268           // / to delet e the reco rds create d in this  sample.</p aram>        
269           // / </summar y>        
270           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
271           {        
272                bool toB eDeleted =  true;        
273          
274                if (prom pt)        
275                {        
276                    // A sk the use r if the c reated ent ities shou ld be dele ted.        
277                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
278                    Stri ng answer  = Console. ReadLine() ;        
279                    if ( answer.Sta rtsWith("y ") ||        
280                         answer.Sta rtsWith("Y ") ||        
281                         answer ==  String.Emp ty)        
282                    {        
283                         toBeDelete d = true;        
284                    }        
285                    else        
286                    {        
287                         toBeDelete d = false;        
288                    }        
289                }        
290          
291                if (toBe Deleted)        
292                {        
293                    // D elete all  records cr eated in t his sample .        
294                    // D elete the  secured cu stom field  #1.        
295                    Dele teAttribut eRequest d eleteReque st = new D eleteAttri buteReques t()        
296                    {        
297                         EntityLogi calName =  Account.En tityLogica lName,        
298                         LogicalNam e = "secre t_phone",        
299                         RequestId  = _secretP honeId        
300                    };        
301                    _ser viceProxy. Execute(de leteReques t);        
302                    // D elete the  secured cu stom field  #2.        
303                    dele teRequest  = new Dele teAttribut eRequest()        
304                    {        
305                         EntityLogi calName =  Account.En tityLogica lName,        
306                         LogicalNam e = "secre t_home",        
307                         RequestId  = _secretH omeId        
308                    };        
309                    _ser viceProxy. Execute(de leteReques t);        
310          
311                    // D elete the  account re cord.        
312                    _ser viceProxy. Delete(Acc ount.Entit yLogicalNa me, _accou ntRecordId );        
313                            
314                    // W e don't ne ed to dele te POAA re cords, bec ause        
315                    // t hey were d eleted whe n we delet ed the acc ount recor d.        
316          
317                    Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. ");        
318                }        
319           }        
320          
321           #e ndregion H ow To Samp le Code        
322          
323           #r egion Main  method        
324          
325           // / <summary >        
326           // / Standard  Main() me thod used  by most SD K samples.        
327           // / </summar y>        
328           // / <param n ame="args" ></param>        
329           st atic publi c void Mai n(string[]  args)        
330           {        
331                try        
332                {        
333                    // O btain the  target org anization' s web addr ess and cl ient logon          
334                    // c redentials  from the  user.        
335                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
336                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
337          
338                    Retr ieveUserSh aredAttrib utePermiss ions app =  new Retri eveUserSha redAttribu tePermissi ons();        
339                    app. Run(config , true);        
340                }        
341                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
342                {        
343                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
344                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
345                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
346                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
347                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
348                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
349                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
350                }        
351                catch (S ystem.Time outExcepti on ex)        
352                {        
353                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
354                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
355                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
356                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
357                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
358                }        
359                catch (S ystem.Exce ption ex)        
360                {        
361                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
362                    Cons ole.WriteL ine(ex.Mes sage);        
363          
364                    // D isplay the  details o f the inne r exceptio n.        
365                    if ( ex.InnerEx ception !=  null)        
366                    {        
367                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
368          
369                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
370                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
371                         if (fe !=  null)        
372                         {        
373                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
374                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
375                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
376                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
377                             Consol e.WriteLin e("Inner F ault: {0}" ,        
378                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
379                         }        
380                    }        
381                }        
382                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
383                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
384          
385                finally        
386                {        
387                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
388                    Cons ole.ReadLi ne();        
389                }        
390           }        
391           #e ndregion M ain method        
392       }        
393   }        
394   //</snippe tRetrieveU serSharedA ttributePe rmissions>