443. Araxis Merge File Comparison Report

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

443.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\Queries RetrieveRecordsFromAnIntersectTable.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:35 2017 UTC

443.2 Comparison summary

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

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

443.4 Active regular expressions

No regular expressions were active.

443.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 RetrieveRe cordsFromA nIntersect Table>        
18   using Syst em;        
19   using Syst em.Text;        
20   using Syst em.Linq;        
21   using Syst em.Xml.Lin q;        
22   using Syst em.Service Model;        
23          
24   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
25   // found i n the SDK\ bin folder .        
26   using Micr osoft.Xrm. Sdk;        
27   using Micr osoft.Xrm. Sdk.Client ;        
28   using Micr osoft.Xrm. Sdk.Query;        
29   using Micr osoft.Xrm. Sdk.Messag es;        
30          
31   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
32   // found i n the SDK\ bin folder .        
33   using Micr osoft.Crm. Sdk.Messag es;        
34          
35   namespace  Microsoft. Crm.Sdk.Sa mples        
36   {        
37       /// <s ummary>        
38       /// De monstrates  how to re trieve rec ords from  an interse ct table.        
39       /// </ summary>        
40       public  class Ret rieveRecor dsFromAnIn tersectTab le        
41       {        
42          
43           #r egion Clas s Level Me mbers        
44          
45           pr ivate Guid  _userId;        
46           pr ivate Guid  _roleId;        
47           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
48          
49           #e ndregion C lass Level  Members        
50          
51           #r egion How- To Sample  Code        
52           // / <summary >        
53           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,        
54           // / records  are retrie ved from t he systemu serroles i ntersect t able via t hree        
55           // / methods:  Query Exp ression, F etch, and  LINQ.        
56           // / </summar y>        
57           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
58           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
59           // / created  entities.< /param>        
60           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
61           {        
62                try        
63                {        
64                    // C onnect to  the Organi zation ser vice.         
65                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
66                    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 ))        
67                    {        
68                         // This st atement is  required  to enable  early-boun d type sup port.        
69                         _servicePr oxy.Enable ProxyTypes ();        
70          
71                         CreateRequ iredRecord s();        
72                         //<snippet RetrieveRe cordsFromA nIntersect Table1>        
73                         #region Re trieve rec ords from  an interse ct table v ia QueryEx pression        
74          
75                         //Create Q uery Expre ssion.        
76                         QueryExpre ssion quer y = new Qu eryExpress ion()        
77                         {        
78                             Entity Name = "ro le",        
79                             Column Set = new  ColumnSet( "name"),        
80                             LinkEn tities =         
81                             {        
82                                 ne w LinkEnti ty        
83                                 {        
84                                      LinkFrom EntityName  = Role.En tityLogica lName,        
85                                      LinkFrom AttributeN ame = "rol eid",        
86                                      LinkToEn tityName =  SystemUse rRoles.Ent ityLogical Name,        
87                                      LinkToAt tributeNam e = "rolei d",        
88                                      LinkCrit eria = new  FilterExp ression        
89                                      {        
90                                          Filt erOperator  = Logical Operator.A nd,        
91                                          Cond itions =         
92                                          {        
93                                               new Condit ionExpress ion        
94                                               {        
95                                                   Attrib uteName =  "systemuse rid",        
96                                                   Operat or = Condi tionOperat or.Equal,        
97                                                   Values  = { _user Id }        
98                                               }        
99                                          }        
100                                      }        
101                                 }        
102                             }        
103                         };        
104          
105                         // Obtain  results fr om the que ry express ion.        
106                         EntityColl ection ec  = _service Proxy.Retr ieveMultip le(query);        
107          
108                         // Display  results.        
109                         for (int i  = 0; i <  ec.Entitie s.Count; i ++)        
110                         {        
111                             Consol e.WriteLin e("Query E xpression  Retrieved:  {0}", ((R ole)ec.Ent ities[i]). Name);        
112                         }        
113          
114                         #endregion        
115                         //</snippe tRetrieveR ecordsFrom AnIntersec tTable1>        
116                         //<snippet RetrieveRe cordsFromA nIntersect Table2>        
117                         #region Re trieve rec ords from  an interse ct table v ia Fetch        
118          
119                         // Setup F etch XML.        
120                         StringBuil der linkFe tch = new  StringBuil der();        
121                         linkFetch. Append("<f etch versi on=\"1.0\"  output-fo rmat=\"xml -platform\ " mapping= \"logical\ " distinct =\"true\"> ");        
122                         linkFetch. Append("<e ntity name =\"role\"> ");        
123                         linkFetch. Append("<a ttribute n ame=\"name \"/>");        
124                         linkFetch. Append("<l ink-entity  name=\"sy stemuserro les\" from =\"roleid\ " to=\"rol eid\" visi ble=\"fals e\" inters ect=\"true \">");        
125                         linkFetch. Append("<f ilter type =\"and\">" );        
126                         linkFetch. Append("<c ondition a ttribute=\ "systemuse rid\" oper ator=\"eq\ " value=\" " + _userI d + "\"/>" );        
127                         linkFetch. Append("</ filter>");        
128                         linkFetch. Append("</ link-entit y>");        
129                         linkFetch. Append("</ entity>");        
130                         linkFetch. Append("</ fetch>");        
131          
132                         // Build f etch reque st and obt ain result s.        
133                         RetrieveMu ltipleRequ est efr =  new Retrie veMultiple Request()        
134                         {        
135                             Query  = new Fetc hExpressio n(linkFetc h.ToString ())        
136                         };        
137                         EntityColl ection ent ityResults  = ((Retri eveMultipl eResponse) _servicePr oxy.Execut e(efr)).En tityCollec tion;        
138          
139                         // Display  results.        
140                         foreach (v ar e in en tityResult s.Entities        
141                         {        
142                             Consol e.WriteLin e("Fetch R etrieved:  {0}", e.At tributes[" name"]);        
143                         }        
144          
145                         #endregion        
146                         //</snippe tRetrieveR ecordsFrom AnIntersec tTable2>        
147                         //<snippet RetrieveRe cordsFromA nIntersect Table3>        
148                         #region Re trieve rec ords from  an interse ct table v ia LINQ        
149          
150                         // Obtain  the Organi zation Con text.        
151                         Organizati onServiceC ontext con text = new  Organizat ionService Context(_s erviceProx y);        
152          
153                         // Create  Linq Query .        
154                         var roles  = (from r  in context .CreateQue ry<Role>()        
155                                       join s  in context .CreateQue ry<SystemU serRoles>( ) on r.Rol eId equals  s.RoleId        
156                                       where s .SystemUse rId == _us erId        
157                                       orderby  r.RoleId        
158                                       select  r.Name);        
159          
160                         // Display  results.        
161                         foreach (v ar role in  roles)        
162                         {        
163                             Consol e.WriteLin e("Linq Re trieved: { 0}", role) ;        
164                         }        
165          
166                         #endregion        
167                         //</snippe tRetrieveR ecordsFrom AnIntersec tTable3>        
168                         DeleteRequ iredRecord s(promptfo rDelete);        
169                    }        
170                }        
171          
172                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
173                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
174                {        
175                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
176                    thro w;        
177                }        
178           }        
179          
180           // / <summary >        
181           // / Creates  any entity  records t hat this s ample requ ires.        
182           // / </summar y>        
183           pu blic void  CreateRequ iredRecord s()        
184           {        
185                // Retri eve the de fault busi ness unit  needed to  create the  team.        
186                QueryExp ression qu eryDefault BusinessUn it = new Q ueryExpres sion        
187                {        
188                    Enti tyName = B usinessUni t.EntityLo gicalName,        
189                    Colu mnSet = ne w ColumnSe t("busines sunitid"),        
190                    Crit eria = new  FilterExp ression()        
191                };        
192          
193                // Execu te the req uest.        
194                queryDef aultBusine ssUnit.Cri teria.AddC ondition(" parentbusi nessunitid ",        
195                    Cond itionOpera tor.Null);        
196          
197                Business Unit defau ltBusiness Unit = (Bu sinessUnit )_serviceP roxy.Retri eveMultipl e(        
198                    quer yDefaultBu sinessUnit ).Entities [0];        
199          
200                // Get t he GUID of  the curre nt user.        
201                WhoAmIRe quest who  = new WhoA mIRequest( );        
202                WhoAmIRe sponse who Resp = (Wh oAmIRespon se)_servic eProxy.Exe cute(who);        
203                _userId  = whoResp. UserId;        
204          
205                // Insta ntiate a r ole entity  record an d set its  property v alues.        
206                // See t he Entity  Metadata t opic in th e SDK docu mentation  to determi ne        
207                // which  attribute s must be  set for ea ch entity.        
208                Role set upRole = n ew Role        
209                {        
210                    Name  = "ABC Ma nagement R ole",        
211                    Busi nessUnitId  = new Ent ityReferen ce(Busines sUnit.Enti tyLogicalN ame,        
212                         defaultBus inessUnit. Id)        
213                };        
214          
215                //Create  a role re cord.        
216                _roleId  = _service Proxy.Crea te(setupRo le);        
217                Console. WriteLine( "Created R ole.");        
218          
219                // Assig n User to  Managers r ole.        
220                Associat eRequest a ssociate =  new Assoc iateReques t()        
221                {        
222                    Targ et = new E ntityRefer ence(Syste mUser.Enti tyLogicalN ame, _user Id),        
223                    Rela tedEntitie s = new En tityRefere nceCollect ion()        
224                    {        
225                         new Entity Reference( Role.Entit yLogicalNa me, _roleI d),        
226                    },        
227                    Rela tionship =  new Relat ionship("s ystemuserr oles_assoc iation")        
228                };        
229          
230                // Execu te the req uest.        
231                _service Proxy.Exec ute(associ ate);        
232           }        
233          
234           // / <summary >        
235           // / Deletes  any entity  records a nd files t hat were c reated for  this samp le.        
236           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
237           // / to delet e the reco rds create d in this  sample.</p aram>        
238           // / </summar y>        
239           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
240           {        
241                bool del eteRecords  = true;        
242          
243                if (prom pt)        
244                {        
245                    Cons ole.WriteL ine("\nDo  you want t hese entit y records  deleted? ( y/n) [y]:  ");        
246                    Stri ng answer  = Console. ReadLine() ;        
247          
248                    dele teRecords  = (answer. StartsWith ("y") || a nswer.Star tsWith("Y" ) || answe r == Strin g.Empty);        
249                }        
250          
251                if (dele teRecords)        
252                {        
253                    _ser viceProxy. Delete(Rol e.EntityLo gicalName,  _roleId);        
254                    Cons ole.WriteL ine("Entit y records  have been  deleted.") ;        
255                }        
256           }        
257          
258           #e ndregion H ow-To Samp le Code        
259          
260           #r egion Main  method        
261          
262           // / <summary >        
263           // / Standard  Main() me thod used  by most SD K samples.        
264           // / </summar y>        
265           // / <param n ame="args" ></param>        
266           st atic publi c void Mai n(string[]  args)        
267           {        
268                try        
269                {        
270                    // O btain the  target org anization' s Web addr ess and cl ient logon          
271                    // c redentials  from the  user.        
272                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
273                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
274          
275                    Retr ieveRecord sFromAnInt ersectTabl e app = ne w Retrieve RecordsFro mAnInterse ctTable();        
276                    app. Run(config , true);        
277                }        
278                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
279                {        
280                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
281                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
282                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
283                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
284                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
285                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
286                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
287                }        
288                catch (S ystem.Time outExcepti on ex)        
289                {        
290                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
291                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
292                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
293                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
294                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
295                }        
296                catch (S ystem.Exce ption ex)        
297                {        
298                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
299                    Cons ole.WriteL ine(ex.Mes sage);        
300          
301                    // D isplay the  details o f the inne r exceptio n.        
302                    if ( ex.InnerEx ception !=  null)        
303                    {        
304                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
305          
306                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
307                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
308                         if (fe !=  null)        
309                         {        
310                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
311                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
312                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
313                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
314                             Consol e.WriteLin e("Inner F ault: {0}" ,        
315                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
316                         }        
317                    }        
318                }        
319                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
320                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
321          
322                finally        
323                {        
324                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
325                    Cons ole.ReadLi ne();        
326                }        
327           }        
328           #e ndregion M ain method        
329       }        
330   }        
331   //</snippe tRetrieveR ecordsFrom AnIntersec tTable>