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

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

380.2 Comparison summary

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

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

380.4 Active regular expressions

No regular expressions were active.

380.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 RetrieveSe curedField sForAUser>        
17   using Syst em;        
18   using Syst em.Collect ions.Gener ic;        
19   using Syst em.Service Model;        
20          
21   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
22   // found i n the SDK\ bin folder .        
23   using Micr osoft.Xrm. Sdk;        
24   using Micr osoft.Xrm. Sdk.Client ;        
25   using Micr osoft.Xrm. Sdk.Messag es;        
26   using Micr osoft.Xrm. Sdk.Metada ta;        
27   using Micr osoft.Xrm. Sdk.Query;        
28          
29   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
30   // found i n the SDK\ bin folder .        
31   using Micr osoft.Crm. Sdk.Messag es;        
32          
33   namespace  Microsoft. Crm.Sdk.Sa mples        
34   {        
35       /// <s ummary>        
36       /// De monstrates  how to re trieve sec ured field s for a us er.        
37       /// </ summary>        
38       /// <r emarks>        
39       /// At  run-time,  you will  be given t he option  to delete  all the        
40       /// da tabase rec ords creat ed by this  program.< /remarks>        
41       public  class Ret rieveSecur edFieldsFo rAUser        
42       {        
43          
44           #r egion Clas s Level Me mbers        
45          
46           pr ivate Guid  _roleId;        
47           pr ivate Guid  _teamId;        
48           pr ivate Guid  _userId;        
49           pr ivate Guid  _profileI d;        
50           pr ivate Guid  _identity Id;        
51           pr ivate Guid  _messageI d;        
52           pr ivate Guid  _identity Permission Id;        
53           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
54          
55           #e ndregion C lass Level  Members        
56          
57           #r egion How- To Sample  Code        
58           // / <summary >        
59           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,  an         
60           // / authoriz ation prof ile is cre ated, and  associated  to a team . Then an  entity        
61           // / is creat ed and per missions f or the ent ity are as signed to  the profil e. These        
62           // / permissi ons are th en retriev ed.        
63           // / </summar y>        
64           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
65           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
66           // / created  entities.< /param>        
67           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
68           {        
69                try        
70                {        
71                    //<s nippetRetr ieveSecure dFieldsFor AUser1>        
72                    // C onnect to  the Organi zation ser vice.         
73                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
74                    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 ))        
75                    {        
76                         // This st atement is  required  to enable  early-boun d type sup port.        
77                         _servicePr oxy.Enable ProxyTypes ();        
78          
79                         CreateRequ iredRecord s();        
80          
81                         // Create  Field Secu rity Profi le.        
82                         FieldSecur ityProfile  managersP rofile = n ew FieldSe curityProf ile();        
83                         managersPr ofile.Name  = "Manage rs";        
84                         _profileId  = _servic eProxy.Cre ate(manage rsProfile) ;        
85                         Console.Wr ite("Creat ed Profile , ");        
86          
87                         // Add tea m to profi le.        
88                         AssociateR equest tea mToProfile  = new Ass ociateRequ est()        
89                         {        
90                             Target  = new Ent ityReferen ce(FieldSe curityProf ile.Entity LogicalNam e,        
91                                 _p rofileId),        
92                             Relate dEntities  = new Enti tyReferenc eCollectio n()        
93                             {        
94                                 ne w EntityRe ference(Te am.EntityL ogicalName , _teamId)        
95                             },        
96                             Relati onship = n ew Relatio nship("tea mprofiles_ associatio n")        
97                         };        
98                         _servicePr oxy.Execut e(teamToPr ofile);        
99          
100                         // Add use r to the p rofile.        
101                         AssociateR equest use rToProfile  = new Ass ociateRequ est()        
102                         {        
103                             Target  = new Ent ityReferen ce(FieldSe curityProf ile.Entity LogicalNam e,        
104                                 _p rofileId),        
105                             Relate dEntities  = new Enti tyReferenc eCollectio n()        
106                             {        
107                                 ne w EntityRe ference(Sy stemUser.E ntityLogic alName, _u serId)        
108                             },        
109                             Relati onship = n ew Relatio nship("sys temuserpro files_asso ciation")        
110                         };        
111                         _servicePr oxy.Execut e(userToPr ofile);        
112          
113                         // Create  custom act ivity enti ty.        
114                         CreateEnti tyRequest  req = new  CreateEnti tyRequest( )        
115                         {        
116                             Entity  = new Ent ityMetadat a        
117                             {        
118                                 Lo gicalName  = "new_twe et",        
119                                 Di splayName  = new Labe l("Tweet",  1033),        
120                                 Di splayColle ctionName  = new Labe l("Tweet",  1033),        
121                                 Ow nershipTyp e = Owners hipTypes.U serOwned,        
122                                 Sc hemaName =  "New_Twee t",        
123                                 Is Activity =  true,        
124                                 Is AvailableO ffline = t rue,        
125                                 Is AuditEnabl ed = new B ooleanMana gedPropert y(true),        
126                                 Is MailMergeE nabled = n ew Boolean ManagedPro perty(fals e),        
127                             },        
128                             HasAct ivities =  false,        
129                             HasNot es = true,        
130                             Primar yAttribute  = new Str ingAttribu teMetadata ()        
131                             {        
132                                 Sc hemaName =  "Subject" ,        
133                                 Lo gicalName  = "subject ",        
134                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(        
135                                      Attribut eRequiredL evel.None) ,        
136                                 Ma xLength =  100,        
137                                 Di splayName  = new Labe l("Subject ", 1033)        
138                             }        
139                         };        
140                         _servicePr oxy.Execut e(req);        
141                         Console.Wr ite("Entit y Created,  ");        
142          
143                         // Add pri vileges fo r the Twee t entity t o the Mark eting Role .        
144                         RolePrivil ege[] priv ileges = n ew RolePri vilege[3];        
145          
146                         // SDK: pr vCreateAct ivity        
147                         privileges [0] = new  RolePrivil ege();        
148                         privileges [0].Privil egeId = ne w Guid("{0 91DF793-FE 5E-44D4-B4 CA-7E3F580 C4664}");        
149                         privileges [0].Depth  = Privileg eDepth.Glo bal;        
150          
151                         // SDK: pr vReadActiv ity        
152                         privileges [1] = new  RolePrivil ege();        
153                         privileges [1].Privil egeId = ne w Guid("{6 50C14FE-35 21-45FE-A0 00-8413868 8E45D}");        
154                         privileges [1].Depth  = Privileg eDepth.Glo bal;        
155          
156                         // SDK: pr vWriteActi vity        
157                         privileges [2] = new  RolePrivil ege();        
158                         privileges [2].Privil egeId = ne w Guid("{0 DC8F72C-57 D5-4B4D-88 92-FE6AAC0 E4B81}");        
159                         privileges [2].Depth  = Privileg eDepth.Glo bal;        
160          
161                         // Create  and execut e the requ est.        
162                         AddPrivile gesRoleReq uest reque st = new A ddPrivileg esRoleRequ est()        
163                         {        
164                             RoleId  = _roleId ,        
165                             Privil eges = pri vileges        
166                         };        
167                         AddPrivile gesRoleRes ponse resp onse =        
168                             (AddPr ivilegesRo leResponse )_serviceP roxy.Execu te(request );        
169          
170                         // Create  custom ide ntity attr ibute.        
171                         CreateAttr ibuteReque st attrReq  = new Cre ateAttribu teRequest( )        
172                         {        
173                             Attrib ute = new  StringAttr ibuteMetad ata()        
174                             {        
175                                 Lo gicalName  = "new_ide ntity",        
176                                 Di splayName  = new Labe l("Identit y", 1033),        
177                                 Sc hemaName =  "New_Iden tity",        
178                                 Ma xLength =  500,        
179                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(        
180                                      Attribut eRequiredL evel.Recom mended),        
181                                 Is Secured =  true        
182                             },        
183                             Entity Name = "ne w_tweet"        
184                         };        
185                         CreateAttr ibuteRespo nse identi tyAttribut eResponse  =        
186                             (Creat eAttribute Response)_ servicePro xy.Execute (attrReq);        
187                         _identityI d = identi tyAttribut eResponse. AttributeI d;        
188                         Console.Wr ite("Ident ity Create d, ");        
189          
190                         // Create  custom mes sage attri bute.        
191                         attrReq =  new Create AttributeR equest()        
192                         {        
193                             Attrib ute = new  StringAttr ibuteMetad ata()        
194                             {        
195                                 Lo gicalName  = "new_mes sage",        
196                                 Di splayName  = new Labe l("Message ", 1033),        
197                                 Sc hemaName =  "New_Mess age",        
198                                 Ma xLength =  140,        
199                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(        
200                                      Attribut eRequiredL evel.Recom mended),        
201                                 Is Secured =  true        
202                             },        
203                             Entity Name = "ne w_tweet"        
204                         };        
205                         CreateAttr ibuteRespo nse messag eAttribute Response =        
206                             (Creat eAttribute Response)_ servicePro xy.Execute (attrReq);        
207                         _messageId  = message AttributeR esponse.At tributeId;        
208                         Console.Wr ite("Messa ge Created , ");        
209          
210                         // Create  field perm ission obj ect for Id entity.        
211                         FieldPermi ssion iden tityPermis sion = new  FieldPerm ission();        
212                         identityPe rmission.A ttributeLo gicalName  = "new_ide ntity";        
213                         identityPe rmission.E ntityName  = "new_twe et";        
214                         identityPe rmission.C anRead = n ew OptionS etValue(Fi eldPermiss ionType.Al lowed);        
215                         identityPe rmission.F ieldSecuri tyProfileI d = new En tityRefere nce(        
216                             FieldS ecurityPro file.Entit yLogicalNa me, _profi leId);        
217                         _identityP ermissionI d = _servi ceProxy.Cr eate(ident ityPermiss ion);        
218                         Console.Wr ite("Permi ssion Crea ted, ");        
219          
220                         // Create  list for s toring ret rieved pro files.        
221                         List<Guid>  profileId s = new Li st<Guid>() ;        
222          
223                         // Build q uery to ob tain the f ield secur ity profil es.        
224                         QueryExpre ssion qe =  new Query Expression ()        
225                         {        
226                             Entity Name = Fie ldSecurity Profile.En tityLogica lName,        
227                             Column Set = new  ColumnSet( "fieldsecu rityprofil eid"),        
228                             LinkEn tities =        
229                             {        
230                                 ne w LinkEnti ty        
231                                 {        
232                                      LinkFrom EntityName  = FieldSe curityProf ile.Entity LogicalNam e,        
233                                      LinkToEn tityName =  SystemUse r.EntityLo gicalName,        
234                                      LinkCrit eria =         
235                                      {        
236                                          Cond itions =         
237                                          {        
238                                               new Condit ionExpress ion("syste muserid",  ConditionO perator.Eq ual, _user Id)        
239                                          }        
240                                      }        
241                                 }        
242                             }        
243                         };        
244          
245                         // Execute  the query  and obtai n the resu lts.        
246                         RetrieveMu ltipleRequ est rmRequ est = new  RetrieveMu ltipleRequ est()        
247                         {        
248                             Query  = qe        
249                         };        
250          
251                         EntityColl ection bec  = ((Retri eveMultipl eResponse) _servicePr oxy.Execut e(        
252                             rmRequ est)).Enti tyCollecti on;        
253          
254                         // Extract  profiles  from query  result.        
255                         foreach (F ieldSecuri tyProfile  profileEnt  in bec.En tities)        
256                         {        
257                             profil eIds.Add(p rofileEnt. FieldSecur ityProfile Id.Value);        
258                         }        
259                         Console.Wr ite("Profi les Retrie ved, ");        
260          
261                         // Retriev e attribut e permissi ons of a F ieldSecuri tyProfile.        
262                         DataCollec tion<Entit y> dc;        
263          
264                         // Retriev e the attr ibutes.        
265                         QueryByAtt ribute qba  = new Que ryByAttrib ute(FieldP ermission. EntityLogi calName);        
266                         qba.AddAtt ributeValu e("fieldse curityprof ileid", _p rofileId);        
267                         qba.Column Set = new  ColumnSet( "attribute logicalnam e");        
268          
269                         dc = _serv iceProxy.R etrieveMul tiple(qba) .Entities;        
270                         Console.Wr ite("Attri butes Retr ieved. ");        
271          
272                         DeleteRequ iredRecord s(promptfo rDelete);        
273                    }        
274                    //</ snippetRet rieveSecur edFieldsFo rAUser1>        
275                }        
276          
277                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
278                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
279                {        
280                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
281                    thro w;        
282                }        
283           }        
284          
285           // / <summary >        
286           // / Creates  any entity  records t hat this s ample requ ires.        
287           // / </summar y>        
288           pu blic void  CreateRequ iredRecord s()        
289           {        
290                // Get t he user fr om the Hel per.        
291                _userId  = SystemUs erProvider .RetrieveM arketingMa nager(_ser viceProxy) ;        
292                Console. Write("Use r retrieve d, ");        
293          
294                // Retri eve the se curity rol e needed t o assign t o the user .        
295                QueryExp ression ro leQuery =  new QueryE xpression        
296                {        
297                    Enti tyName = R ole.Entity LogicalNam e,        
298                    Colu mnSet = ne w ColumnSe t("roleid" ),        
299                    Crit eria =        
300                    {        
301                         Conditions  =        
302                         {        
303                             new Co nditionExp ression("n ame", Cond itionOpera tor.Equal,        
304                                 "M arketing M anager")        
305                         }        
306                    }        
307                };        
308          
309                Role rol e = (Role) _servicePr oxy.Retrie veMultiple (roleQuery ).Entities [0];        
310                _roleId  = role.Id;        
311          
312                // Retri eve the de fault busi ness unit  needed to  create the  team.        
313                QueryExp ression qu eryDefault BusinessUn it = new Q ueryExpres sion        
314                {        
315                    Enti tyName = B usinessUni t.EntityLo gicalName,        
316                    Colu mnSet = ne w ColumnSe t("busines sunitid"),        
317                    Crit eria =        
318                    {        
319                         Conditions  =        
320                         {        
321                             new Co nditionExp ression("p arentbusin essunitid" , Conditio nOperator. Null)        
322                         }        
323                    }        
324                };        
325          
326                // Execu te the que ry.        
327                Business Unit defau ltBusiness Unit = (Bu sinessUnit )_serviceP roxy.Retri eveMultipl e(        
328                    quer yDefaultBu sinessUnit ).Entities [0];        
329          
330                // Insta ntiate a t eam entity  record an d set its  property v alues.        
331                // See t he Entity  Metadata t opic in th e SDK docu mentation  to determi ne        
332                // which  attribute s must be  set for ea ch entity.        
333                Team set upTeam = n ew Team        
334                {        
335                    Name  = "ABC Ma nagement T eam",        
336                    Busi nessUnitId  = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame,        
337                         defaultBus inessUnit. Id)        
338                };        
339          
340                // Creat e a team r ecord.        
341                _teamId  = _service Proxy.Crea te(setupTe am);        
342                Console. Write("Cre ated Team,  ");                     
343           }        
344          
345           // / <summary >        
346           // / Deletes  any entity  records a nd files t hat were c reated for  this samp le.        
347           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
348           // / to delet e the reco rds create d in this  sample.</p aram>        
349           // / </summar y>        
350           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
351           {        
352                bool del eteRecords  = true;        
353          
354                if (prom pt)        
355                {        
356                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n) [y]:  ");        
357                    Stri ng answer  = Console. ReadLine() ;        
358          
359                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
360                }        
361          
362                if (dele teRecords)        
363                {        
364                    Dele teEntityRe quest del  = new Dele teEntityRe quest()        
365                    {        
366                         LogicalNam e = "new_t weet",        
367                    };        
368                    _ser viceProxy. Execute(de l);        
369                    _ser viceProxy. Delete(Fie ldSecurity Profile.En tityLogica lName, _pr ofileId);        
370                    _ser viceProxy. Delete(Tea m.EntityLo gicalName,  _teamId);        
371                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
372                }        
373           }        
374          
375           #e ndregion H ow-To Samp le Code        
376          
377           #r egion Main  method        
378          
379           // / <summary >        
380           // / Standard  Main() me thod used  by most SD K samples.        
381           // / </summar y>        
382           // / <param n ame="args" ></param>        
383           st atic publi c void Mai n(string[]  args)        
384           {        
385                try        
386                {        
387                    // O btain the  target org anization' s Web addr ess and cl ient logon          
388                    // c redentials  from the  user.        
389                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
390                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
391          
392                    Retr ieveSecure dFieldsFor AUser app  = new Retr ieveSecure dFieldsFor AUser();        
393                    app. Run(config , true);        
394                }        
395                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
396                {        
397                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
398                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
399                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
400                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
401                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
402                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
403                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
404                }        
405                catch (S ystem.Time outExcepti on ex)        
406                {        
407                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
408                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
409                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
410                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
411                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
412                }        
413                catch (S ystem.Exce ption ex)        
414                {        
415                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
416                    Cons ole.WriteL ine(ex.Mes sage);        
417          
418                    // D isplay the  details o f the inne r exceptio n.        
419                    if ( ex.InnerEx ception !=  null)        
420                    {        
421                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
422          
423                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
424                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
425                         if (fe !=  null)        
426                         {        
427                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
428                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
429                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
430                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
431                             Consol e.WriteLin e("Inner F ault: {0}" ,        
432                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
433                         }        
434                    }        
435                }        
436                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
437                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
438          
439                finally        
440                {        
441                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
442                    Cons ole.ReadLi ne();        
443                }        
444           }        
445           #e ndregion M ain method        
446       }        
447   }        
448   //</snippe tRetrieveS ecuredFiel dsForAUser >