430. Araxis Merge File Comparison Report

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

430.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 CreateALinqQuery.cs Tue Dec 20 19:51:46 2016 UTC
2 Wed Feb 1 19:56:34 2017 UTC

430.2 Comparison summary

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

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

430.4 Active regular expressions

No regular expressions were active.

430.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 CreateALin qQuery>        
17   using Syst em;        
18   using Syst em.Service Model;        
19   using Syst em.Linq;        
20   using Syst em.Collect ions.Gener ic;        
21          
22   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
23   // located  in the SD K\bin fold er of the  SDK downlo ad.        
24   using Micr osoft.Xrm. Sdk;        
25   using Micr osoft.Xrm. Sdk.Client ;        
26          
27   namespace  Microsoft. Crm.Sdk.Sa mples        
28   {        
29    /// <summ ary>        
30    /// Demon strates ho w to do cr eate basic  LINQ quer ies agains t Microsof t Dynamics  CRM        
31    /// recor ds.</summa ry>        
32    /// <rema rks>        
33    /// At ru n-time, yo u will be  given the  option to  delete all  the        
34    /// datab ase record s created  by this pr ogram.</re marks>        
35    public cl ass Create ALinqQuery        
36    {        
37     #region  Class Leve l Members        
38          
39     private  Dictionary <Guid, Str ing> _reco rdIds = ne w Dictiona ry<Guid, S tring>();        
40     private  Organizati onServiceP roxy _serv iceProxy;        
41     private  IOrganizat ionService  _service;        
42          
43     #endregi on Class L evel Membe rs        
44          
45     #region  How To Sam ple Code        
46     /// <sum mary>        
47     /// This  method fi rst connec ts to the  Organizati on service . Afterwar ds,        
48     /// basi c LINQ que ries are p erformed.        
49     /// </su mmary>        
50     /// <par am name="s erverConfi g">Contain s server c onnection  informatio n.</param>        
51     /// <par am name="p romptforDe lete">When  True, the  user will  be prompt ed to dele te all        
52     /// crea ted entiti es.</param >        
53     public v oid Run(Se rverConnec tion.Confi guration s erverConfi g, bool pr omptforDel ete)        
54     {        
55      try        
56      {        
57          
58       // Con nect to th e Organiza tion servi ce.         
59       // The  using sta tement ass ures that  the servic e proxy wi ll be prop erly dispo sed.        
60          usi ng (_servi ceProxy =  new Organi zationServ iceProxy(s erverConfi g.Organiza tionUri, s erverConfi g.HomeReal mUri,        
61                                                                                  serverCo nfig.Crede ntials, se rverConfig .DeviceCre dentials))        
62       {        
63        // Th is stateme nt is requ ired to en able early -bound typ e support.        
64        _serv iceProxy.E nableProxy Types();        
65        _serv ice = (IOr ganization Service)_s erviceProx y;        
66          
67        Creat eRequiredR ecords();        
68          
69        // Cr eate the S erviceCont ext object  that will  generate        
70        // th e IQueryab le collect ions for L INQ calls.        
71          
72        Servi ceContext  svcContext  = new Ser viceContex t(_service );        
73        // Lo op through  all CRM a ccount usi ng the IQu eryable in terface        
74        // on  the Servi ceContext  object        
75        //<sn ippetCreat eALinqQuer y1>        
76        var a ccounts =  from a in  svcContext .AccountSe t        
77                         select new  Account        
78                         {        
79                          Name = a. Name,        
80                          Address1_ County = a .Address1_ County        
81                         };        
82        Syste m.Console. WriteLine( "List all  accounts i n CRM");        
83        Syste m.Console. WriteLine( "========= ========== =====");        
84        forea ch (var a  in account s)        
85        {        
86         Syst em.Console .WriteLine (a.Name +  " " + a.Ad dress1_Cou nty);        
87        }        
88        //</s nippetCrea teALinqQue ry1>        
89        Syste m.Console. WriteLine( );        
90        Syste m.Console. WriteLine( "<End of L isting>");        
91        Syste m.Console. WriteLine( );        
92        //OUT PUT:        
93        //Lis t all acco unts in CR M        
94        //=== ========== ========== =        
95        //Fou rth Coffee        
96        //Sch ool of Fin e Art Lake  County        
97        //Tai lspin Toys  King Coun ty        
98        //Woo dgrove Ban k        
99        //Con toso, Ltd.  Saint Lou is County        
100          
101        //<En d of Listi ng>        
102        Syste m.Console. WriteLine( );        
103          
104          
105          
106        // Re trieve all  accounts  owned by t he user wh o has read  access ri ghts        
107        // to  the accou nts and wh ere the la st name of  the user  is not Can non.        
108        //<sn ippetCreat eALinqQuer y2>        
109        var q ueryAccoun ts = from  a in svcCo ntext.Acco untSet        
110                              join  owner in s vcContext. SystemUser Set        
111                                on  a.OwnerId. Id equals  owner.Syst emUserId        
112                              where  owner.Las tName != " Cannon"        
113                              selec t new Acco unt        
114                              {        
115                               Name  = a.Name,        
116                               Addr ess1_City  = a.Addres s1_City        
117                              };        
118        Syste m.Console. WriteLine( "Accounts  not owned  by user w/  last name  'Cannon'" );        
119        Syste m.Console. WriteLine( "========= ========== ========== ========== =========" );        
120        forea ch (var a  in queryAc counts)        
121        {        
122         Syst em.Console .WriteLine (a.Name +  " " + a.Ad dress1_Cou nty);        
123        }        
124        //</s nippetCrea teALinqQue ry2>        
125        Syste m.Console. WriteLine( );        
126        Syste m.Console. WriteLine( "<End of L isting>");        
127        Syste m.Console. WriteLine( );        
128        //OUT PUT:        
129        //Acc ounts not  owned by u ser w/ las t name 'Ca nnon'        
130        //=== ========== ========== ========== ========== =====        
131        //Fou rth Coffee        
132        //Sch ool of Fin e Art        
133        //Tai lspin Toys        
134        //Woo dgrove Ban k        
135        //Con toso, Ltd.        
136          
137        //<En d of Listi ng>        
138        Syste m.Console. WriteLine( );        
139          
140          
141          
142        // Re turn a cou nt of all  accounts w hich have  a county s pecified        
143        // in  their add ress.        
144        //<sn ippetCreat eALinqQuer y3>        
145        int a ccountsWit hCounty =  (from a in  svcContex t.AccountS et        
146                                     where (a. Address1_C ounty != n ull)        
147                                     select ne w Account        
148                                     {        
149                                      Name = a .Name,        
150                                      Address1 _City = a. Address1_C ity        
151                                     }).ToArra y().Count( );        
152        Syste m.Console. Write("Num ber of acc ounts with  a county  specified:  ");        
153        Syste m.Console. WriteLine( accountsWi thCounty);        
154        //</s nippetCrea teALinqQue ry3>        
155        Syste m.Console. WriteLine( );        
156        //OUT PUT:        
157        //Num ber of acc ounts with  a county  specified:  3        
158        Syste m.Console. WriteLine( );        
159          
160          
161          
162        // Re turn a cou nt of stat es in whic h we have  an account . This        
163        // us es the 'di stinct' ke yword whic h counts a  state onl y one time .        
164        //<sn ippetCreat eALinqQuer y4>        
165        int s tatesWithA ccounts =  (from a in  svcContex t.AccountS et        
166                                     where (a. Address1_S tateOrProv ince != nu ll)        
167                                     select a. Address1_S tateOrProv ince)        
168                                     .Distinct ().ToArray ().Count() ;        
169        Syste m.Console. Write("Num ber of uni que states  that cont ain accoun ts: ");        
170        Syste m.Console. WriteLine( statesWith Accounts);        
171        //</s nippetCrea teALinqQue ry4>        
172        Syste m.Console. WriteLine( );        
173        //OUT PUT:        
174        //Num ber of uni que states  that cont ain accoun ts: 3        
175        Syste m.Console. WriteLine( );        
176          
177          
178          
179        // Re turn conta cts where  the city e quals Redm ond AND th e first        
180        // na me is Joe  OR John.        
181        //<sn ippetCreat eALinqQuer y5>        
182        var q ueryContac ts = from  c in svcCo ntext.Cont actSet        
183                              where  (c.Addres s1_City ==  "Redmond" ) &&        
184                                     (c.FirstN ame.Equals ("Joe") ||        
185                                      c.FirstN ame.Equals ("John"))        
186                              selec t new Cont act        
187                              {        
188                               Firs tName = c. FirstName,        
189                               Last Name = c.L astName,        
190                               Addr ess1_City  = c.Addres s1_City        
191                              };        
192        Syste m.Console. WriteLine( "Contacts  in Redmond  named Joe  OR John") ;        
193        Syste m.Console. WriteLine( "========= ========== ========== ========") ;        
194        forea ch (var c  in queryCo ntacts)        
195        {        
196         Syst em.Console .WriteLine (c.FirstNa me + " " +        
197              c.LastName  + " " + c .Address1_ City);        
198        }        
199        //</s nippetCrea teALinqQue ry5>        
200        Syste m.Console. WriteLine( );        
201        Syste m.Console. WriteLine( "<End of L isting>");        
202        Syste m.Console. WriteLine( );        
203        //OUT PUT:        
204        //Con tacts in R edmond nam ed Joe OR  John        
205        //=== ========== ========== ========== ====        
206        //Joe   Redmond        
207        //Joh n  Redmond        
208        //Joe   Redmond        
209          
210        //<En d of Listi ng>        
211          
212        Syste m.Console. WriteLine( );        
213          
214          
215        Delet eRequiredR ecords(pro mptforDele te);        
216       }        
217          
218      }        
219          
220      // Catc h any serv ice fault  exceptions  that Micr osoft Dyna mics CRM t hrows.        
221      catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault>)        
222      {        
223       // You  can handl e an excep tion here  or pass it  back to t he calling  method.        
224       throw;        
225      }        
226     }        
227          
228     /// <sum mary>        
229     /// Crea tes any en tity recor ds that th is sample  requires.        
230     /// </su mmary>        
231     public v oid Create RequiredRe cords()        
232     {        
233      // Crea te 5 Accou nts and 5  Contacts f or the LIN Q samples.        
234      Account  account =  new Accou nt        
235      {        
236       Name =  "Fourth C offee",        
237       Addres s1_StateOr Province =  "Colorado ",        
238      };        
239      _record Ids.Add(_s ervice.Cre ate(accoun t), Accoun t.EntityLo gicalName) ;        
240      account  = new Acc ount        
241      {        
242       Name =  "School o f Fine Art ",        
243       Addres s1_StateOr Province =  "Illinois ",        
244       Addres s1_County  = "Lake Co unty"        
245      };        
246      _record Ids.Add(_s ervice.Cre ate(accoun t), Accoun t.EntityLo gicalName) ;        
247      account  = new Acc ount        
248      {        
249       Name =  "Tailspin  Toys",        
250       Addres s1_StateOr Province =  "Washingt on",        
251       Addres s1_County  = "King Co unty",        
252      };        
253      _record Ids.Add(_s ervice.Cre ate(accoun t), Accoun t.EntityLo gicalName) ;        
254      account  = new Acc ount        
255      {        
256       Name =  "Woodgrov e Bank",        
257       Addres s1_StateOr Province =  "Washingt on"        
258      };        
259      _record Ids.Add(_s ervice.Cre ate(accoun t), Accoun t.EntityLo gicalName) ;        
260      account  = new Acc ount        
261      {        
262       Name =  "Contoso,  Ltd.",        
263       Addres s1_County  = "Saint L ouis Count y"        
264      };        
265      _record Ids.Add(_s ervice.Cre ate(accoun t), Accoun t.EntityLo gicalName) ;        
266          
267      Contact  contact =  new Conta ct        
268      {        
269       FirstN ame = "Joe ",        
270       Addres s1_City =  "Redmond",        
271      };        
272      _record Ids.Add(_s ervice.Cre ate(contac t), Contac t.EntityLo gicalName) ;        
273      contact  = new Con tact        
274      {        
275       FirstN ame = "Joh n",        
276       Addres s1_City =  "Redmond",        
277      };        
278      _record Ids.Add(_s ervice.Cre ate(contac t), Contac t.EntityLo gicalName) ;        
279      contact  = new Con tact        
280      {        
281       FirstN ame = "Joh n",        
282       Addres s1_City =  "Cleveland ",        
283      };        
284      _record Ids.Add(_s ervice.Cre ate(contac t), Contac t.EntityLo gicalName) ;        
285      contact  = new Con tact        
286      {        
287       FirstN ame = "Joe ",        
288       Addres s1_City =  "Redmond",        
289      };        
290      _record Ids.Add(_s ervice.Cre ate(contac t), Contac t.EntityLo gicalName) ;        
291      contact  = new Con tact        
292      {        
293       FirstN ame = "Jim ",        
294       Addres s1_City =  "Redmond",        
295      };        
296      _record Ids.Add(_s ervice.Cre ate(contac t), Contac t.EntityLo gicalName) ;        
297     }        
298          
299     /// <sum mary>        
300     /// Dele tes any en tity recor ds that we re created  for this  sample.        
301     /// <par am name="p rompt">Ind icates whe ther to pr ompt the u ser         
302     /// to d elete the  records cr eated in t his sample .</param>        
303     /// </su mmary>        
304     public v oid Delete RequiredRe cords(bool  prompt)        
305     {        
306      bool to BeDeleted  = true;        
307          
308      if (pro mpt)        
309      {        
310       // Ask  the user  if the cre ated entit ies should  be delete d.        
311       Consol e.Write("\ nDo you wa nt these e ntity reco rds delete d? (y/n) [ y]: ");        
312       String  answer =  Console.Re adLine();        
313       if (an swer.Start sWith("y")  ||        
314           an swer.Start sWith("Y")  ||        
315           an swer == St ring.Empty )        
316       {        
317        toBeD eleted = t rue;        
318       }        
319       else        
320       {        
321        toBeD eleted = f alse;        
322       }        
323      }        
324          
325      if (toB eDeleted)        
326      {        
327       // Del ete all re cords crea ted in thi s sample.        
328       foreac h (var rec ord in _re cordIds)        
329       {        
330        _serv ice.Delete (record.Va lue, recor d.Key);        
331       }        
332       Consol e.WriteLin e("Entity  record(s)  have been  deleted.") ;        
333      }        
334     }        
335          
336     #endregi on How To  Sample Cod e        
337          
338     #region  Main metho d        
339          
340     /// <sum mary>        
341     /// Stan dard Main( ) method u sed by mos t SDK samp les.        
342     /// </su mmary>        
343     /// <par am name="a rgs"></par am>        
344     static p ublic void  Main(stri ng[] args)        
345     {        
346      try        
347      {        
348       // Obt ain the ta rget organ ization's  Web addres s and clie nt logon         
349       // cre dentials f rom the us er.        
350       Server Connection  serverCon nect = new  ServerCon nection();        
351       Server Connection .Configura tion confi g = server Connect.Ge tServerCon figuration ();        
352          
353       Create ALinqQuery  app = new  CreateALi nqQuery();        
354       app.Ru n(config,  true);        
355      }        
356      catch ( FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> e x)        
357      {        
358       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
359       Consol e.WriteLin e("Timesta mp: {0}",  ex.Detail. Timestamp) ;        
360       Consol e.WriteLin e("Code: { 0}", ex.De tail.Error Code);        
361       Consol e.WriteLin e("Message : {0}", ex .Detail.Me ssage);        
362       Consol e.WriteLin e("Plugin  Trace: {0} ", ex.Deta il.TraceTe xt);        
363       Consol e.WriteLin e("Inner F ault: {0}" ,        
364           nu ll == ex.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
365      }        
366      catch ( System.Tim eoutExcept ion ex)        
367      {        
368       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
369       Consol e.WriteLin e("Message : {0}", ex .Message);        
370       Consol e.WriteLin e("Stack T race: {0}" , ex.Stack Trace);        
371       Consol e.WriteLin e("Inner F ault: {0}" ,        
372           nu ll == ex.I nnerExcept ion.Messag e ? "No In ner Fault"  : ex.Inne rException .Message);        
373      }        
374      catch ( System.Exc eption ex)        
375      {        
376       Consol e.WriteLin e("The app lication t erminated  with an er ror.");        
377       Consol e.WriteLin e(ex.Messa ge);        
378          
379       // Dis play the d etails of  the inner  exception.        
380       if (ex .InnerExce ption != n ull)        
381       {        
382        Conso le.WriteLi ne(ex.Inne rException .Message);        
383          
384        Fault Exception< Microsoft. Xrm.Sdk.Or ganization ServiceFau lt> fe = e x.InnerExc eption        
385            a s FaultExc eption<Mic rosoft.Xrm .Sdk.Organ izationSer viceFault> ;        
386        if (f e != null)        
387        {        
388         Cons ole.WriteL ine("Times tamp: {0}" , fe.Detai l.Timestam p);        
389         Cons ole.WriteL ine("Code:  {0}", fe. Detail.Err orCode);        
390         Cons ole.WriteL ine("Messa ge: {0}",  fe.Detail. Message);        
391         Cons ole.WriteL ine("Plugi n Trace: { 0}", fe.De tail.Trace Text);        
392         Cons ole.WriteL ine("Inner  Fault: {0 }",        
393              null == fe .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
394        }        
395       }        
396      }        
397      // Addi tional exc eptions to  catch: Se curityToke nValidatio nException , ExpiredS ecurityTok enExceptio n,        
398      // Secu rityAccess DeniedExce ption, Mes sageSecuri tyExceptio n, and Sec urityNegot iationExce ption.        
399          
400      finally        
401      {        
402       Consol e.WriteLin e("Press < Enter> to  exit.");        
403       Consol e.ReadLine ();        
404      }        
405     }        
406     #endregi on Main me thod        
407    }        
408   }        
409   //</snippe tCreateALi nqQuery>