376. Araxis Merge File Comparison Report

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

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

376.2 Comparison summary

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

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

376.4 Active regular expressions

No regular expressions were active.

376.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          
17   //<snippet EnableFiel dSecurityF orAnEntity >        
18   using Syst em;        
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          
34   namespace  Microsoft. Crm.Sdk.Sa mples        
35          
36   {        
37       /// <s ummary>        
38       /// De monstrates  how to cr eate enabl e field se curity for  an entity .</summary >        
39       /// <r emarks>        
40       /// At  run-time,  you will  be given t he option  to delete  all the        
41       /// da tabase rec ords creat ed by this  program.< /remarks>        
42       public  class Ena bleFieldSe curityForA nEntity        
43       {        
44          
45           #r egion Clas s Level Me mbers        
46          
47           pr ivate Guid  _teamId;        
48           pr ivate Guid  _profileI d;        
49           pr ivate Guid  _identity Id;        
50           pr ivate Guid  _messageI d;        
51           pr ivate Guid  _identity Permission Id;        
52           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
53          
54           #e ndregion C lass Level  Members        
55          
56           #r egion How- To Sample  Code        
57           // / <summary >        
58           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,        
59           // / a FieldS ecurityPro file objec t is creat ed and tie d to an ex isting tea m. Then a        
60           // / custom e ntity and  several at tributes a re created  and Field Permission  is         
61           // / assigned  to the Id entity att ribute of  the new en tity.        
62           // / </summar y>        
63           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
64           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
65           // / created  entities.< /param>        
66           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
67           {        
68                try        
69                {        
70                    //<s nippetEnab leFieldSec urityForAn Entity1>        
71                    // C onnect to  the Organi zation ser vice.         
72                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
73                    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 ))        
74                    {        
75                         // This st atement is  required  to enable  early-boun d type sup port.        
76                         _servicePr oxy.Enable ProxyTypes ();        
77                                
78                         CreateRequ iredRecord s();        
79          
80                         // Create  Field Secu rity Profi le.        
81                         FieldSecur ityProfile  managersP rofile = n ew FieldSe curityProf ile();        
82                         managersPr ofile.Name  = "Manage rs";        
83                         _profileId  = _servic eProxy.Cre ate(manage rsProfile) ;        
84                         Console.Wr ite("Creat ed Profile , ");        
85          
86                         //<snippet EnableFiel dSecurityF orAnEntity 2>        
87                         // Create  the reques t object a nd set the  monikers  with the        
88                         // teampro files_asso ciation re lationship .        
89                         AssociateR equest tea mToProfile  = new Ass ociateRequ est        
90                         {        
91                             Target  = new Ent ityReferen ce(FieldSe curityProf ile.Entity LogicalNam e, _profil eId),        
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          
99                         // Execute  the reque st.        
100                         _servicePr oxy.Execut e(teamToPr ofile);        
101                         //</snippe tEnableFie ldSecurity ForAnEntit y2>        
102          
103                         // Create  custom act ivity enti ty.        
104                         CreateEnti tyRequest  req = new  CreateEnti tyRequest( )        
105                         {        
106                             Entity  = new Ent ityMetadat a        
107                             {        
108                                 Lo gicalName  = "new_twe et",        
109                                 Di splayName  = new Labe l("Tweet",  1033),        
110                                 Di splayColle ctionName  = new Labe l("Tweet",  1033),        
111                                 Ow nershipTyp e = Owners hipTypes.U serOwned,        
112                                 Sc hemaName =  "New_Twee t",        
113                                 Is Activity =  true,        
114                                 Is AvailableO ffline = t rue,        
115                                 Is AuditEnabl ed = new B ooleanMana gedPropert y(true),        
116                                 Is MailMergeE nabled = n ew Boolean ManagedPro perty(fals e)        
117                             },        
118                             HasAct ivities =  false,        
119                             HasNot es = true,        
120                             Primar yAttribute  = new Str ingAttribu teMetadata ()        
121                             {        
122                                 Sc hemaName =  "Subject" ,        
123                                 Lo gicalName  = "subject ",        
124                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.N one),        
125                                 Ma xLength =  100,        
126                                 Di splayName  = new Labe l("Subject ", 1033)        
127                             }        
128                         };        
129          
130                         // Execute  the reque st.        
131                         _servicePr oxy.Execut e(req);        
132                         Console.Wr ite("Entit y Created,  ");        
133          
134                         // Create  custom att ributes.        
135                         CreateAttr ibuteReque st attrReq  = new Cre ateAttribu teRequest( )        
136                         {        
137                             Attrib ute = new  StringAttr ibuteMetad ata()        
138                             {        
139                                 Lo gicalName  = "new_ide ntity",        
140                                 Di splayName  = new Labe l("Identit y", 1033),        
141                                 Sc hemaName =  "New_Iden tity",        
142                                 Ma xLength =  500,        
143                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.R ecommended ),        
144                                 Is Secured =  true        
145                             },        
146                             Entity Name = "ne w_tweet"        
147                         };        
148          
149                         // Execute  the reque st.        
150                         CreateAttr ibuteRespo nse identi tyAttribut eResponse  = (CreateA ttributeRe sponse)_se rviceProxy .Execute(a ttrReq);        
151                         _identityI d = identi tyAttribut eResponse. AttributeI d;        
152                         Console.Wr ite("Ident ity Create d, ");        
153          
154                         attrReq =  new Create AttributeR equest()        
155                         {        
156                             Attrib ute = new  StringAttr ibuteMetad ata()        
157                             {        
158                                 Lo gicalName  = "new_mes sage",        
159                                 Di splayName  = new Labe l("Message ", 1033),        
160                                 Sc hemaName =  "New_Mess age",        
161                                 Ma xLength =  140,        
162                                 Re quiredLeve l = new At tributeReq uiredLevel ManagedPro perty(Attr ibuteRequi redLevel.R ecommended ),        
163                                 Is Secured =  true        
164                             },        
165                             Entity Name = "ne w_tweet"        
166                         };        
167          
168                         // Execute  the reque st.        
169                         CreateAttr ibuteRespo nse messag eAttribute Response =  (CreateAt tributeRes ponse)_ser viceProxy. Execute(at trReq);        
170                         _messageId  = message AttributeR esponse.At tributeId;        
171                         Console.Wr ite("Messa ge Created , ");        
172          
173                         // Create  the field  permission  for the I dentity at tribute.        
174                         FieldPermi ssion iden tityPermis sion = new  FieldPerm ission()        
175                         {        
176                             Attrib uteLogical Name = "ne w_identity ",        
177                             Entity Name = "ne w_tweet",        
178                             CanRea d = new Op tionSetVal ue(FieldPe rmissionTy pe.Allowed ),        
179                             FieldS ecurityPro fileId = n ew EntityR eference(F ieldSecuri tyProfile. EntityLogi calName, _ profileId)        
180                         };        
181          
182                         // Execute  the reque st        
183                         _identityP ermissionI d = _servi ceProxy.Cr eate(ident ityPermiss ion);        
184                         Console.Wr ite("Permi ssion Crea ted. ");        
185          
186                         DeleteRequ iredRecord s(promptfo rDelete);        
187                    }        
188                    //</ snippetEna bleFieldSe curityForA nEntity1>        
189                }        
190          
191                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
192                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
193                {        
194                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
195                    thro w;        
196                }        
197           }        
198          
199           // / <summary >        
200           // / Creates  any entity  records t hat this s ample requ ires.        
201           // / </summar y>        
202           pu blic void  CreateRequ iredRecord s()        
203           {        
204                // Retri eve the de fault busi ness unit  needed to  create the  team.        
205                QueryExp ression qu eryDefault BusinessUn it = new Q ueryExpres sion        
206                {        
207                    Enti tyName = B usinessUni t.EntityLo gicalName,        
208                    Colu mnSet = ne w ColumnSe t("busines sunitid"),        
209                    Crit eria =        
210                    {        
211                         Conditions  =        
212                         {        
213                             new Co nditionExp ression("p arentbusin essunitid"        
214                                 Co nditionOpe rator.Null )        
215                         }        
216                    }        
217                };        
218          
219                Business Unit defau ltBusiness Unit = (Bu sinessUnit )_serviceP roxy.Retri eveMultipl e(        
220                    quer yDefaultBu sinessUnit ).Entities [0];        
221          
222                // Insta ntiate a t eam entity  record an d set its  property v alues.        
223                // See t he Entity  Metadata t opic in th e SDK docu mentation  to determi ne        
224                // which  attribute s must be  set for ea ch entity.        
225                Team set upTeam = n ew Team        
226                {        
227                    Name  = "ABC Ma nagement T eam",        
228                    Busi nessUnitId  = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame,        
229                         defaultBus inessUnit. Id)        
230                };        
231                        
232                //Create  a team re cord.        
233                _teamId  = _service Proxy.Crea te(setupTe am);        
234                Console. Write("Cre ated Team,  ");        
235           }        
236          
237           // / <summary >        
238           // / Deletes  any entity  records a nd files t hat were c reated for  this samp le.        
239           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
240           // / to delet e the reco rds create d in this  sample.</p aram>        
241           // / </summar y>        
242           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
243           {        
244                bool del eteRecords  = true;        
245          
246                if (prom pt)        
247                {        
248                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n) [y]:  ");        
249                    Stri ng answer  = Console. ReadLine() ;        
250          
251                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
252                }        
253          
254                if (dele teRecords)        
255                {        
256                    _ser viceProxy. Delete(Fie ldSecurity Profile.En tityLogica lName, _pr ofileId);        
257                    _ser viceProxy. Delete(Tea m.EntityLo gicalName,  _teamId);        
258                    Dele teEntityRe quest del  = new Dele teEntityRe quest()        
259                    {        
260                         LogicalNam e = "new_t weet",        
261                    };        
262                    _ser viceProxy. Execute(de l);        
263                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
264                }        
265           }        
266          
267           #e ndregion H ow-To Samp le Code        
268          
269           #r egion Main  method        
270          
271           // / <summary >        
272           // / Standard  Main() me thod used  by most SD K samples.        
273           // / </summar y>        
274           // / <param n ame="args" ></param>        
275           st atic publi c void Mai n(string[]  args)        
276           {        
277                try        
278                {        
279                    // O btain the  target org anization' s Web addr ess and cl ient logon          
280                    // c redentials  from the  user.        
281                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
282                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
283          
284                    Enab leFieldSec urityForAn Entity app  = new Ena bleFieldSe curityForA nEntity();        
285                    app. Run(config , true);        
286                }        
287                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
288                {        
289                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
290                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
291                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
292                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
293                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
294                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
295                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
296                }        
297                catch (S ystem.Time outExcepti on ex)        
298                {        
299                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
300                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
301                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
302                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
303                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
304                }        
305                catch (S ystem.Exce ption ex)        
306                {        
307                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
308                    Cons ole.WriteL ine(ex.Mes sage);        
309          
310                    // D isplay the  details o f the inne r exceptio n.        
311                    if ( ex.InnerEx ception !=  null)        
312                    {        
313                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
314          
315                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
316                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
317                         if (fe !=  null)        
318                         {        
319                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
320                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
321                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
322                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
323                             Consol e.WriteLin e("Inner F ault: {0}" ,        
324                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
325                         }        
326                    }        
327                }        
328                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
329                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
330          
331                finally        
332                {        
333                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
334                    Cons ole.ReadLi ne();        
335                }        
336           }        
337           #e ndregion M ain method        
338       }        
339   }        
340   //</snippe tEnableFie ldSecurity ForAnEntit y>